Skip to content

Commit 6d4dbe7

Browse files
committed
Some final README tweaks before 5.0.0.beta1
1 parent f9f5444 commit 6d4dbe7

File tree

6 files changed

+53
-38
lines changed

6 files changed

+53
-38
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Unreleased
22

3-
# Unreleased 5.0.0
3+
# Unreleased 5.0.0.beta1
44

55
- Use `MD5` for hashing server nodes in `Redis::Distributed`. This should improve keys distribution among servers. See #1089.
66
- Changed `sadd` and `srem` to now always return an Integer.

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ gem 'rake'
99
gem 'rubocop', '~> 1.25.1'
1010
gem 'mocha'
1111

12-
gem 'redis-client', github: 'redis-rb/redis-client'
1312
gem 'hiredis-client'

README.md

Lines changed: 50 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# redis-rb [![Build Status][gh-actions-image]][gh-actions-link] [![Inline docs][inchpages-image]][inchpages-link]
22

3-
A Ruby client that tries to match [Redis][redis-home]' API one-to-one, while still
4-
providing an idiomatic interface.
3+
A Ruby client that tries to match [Redis][redis-home]' API one-to-one, while still providing an idiomatic interface.
54

65
See [RubyDoc.info][rubydoc] for the API docs of the latest published gem.
76

@@ -38,10 +37,6 @@ redis = Redis.new(url: "redis://:[email protected]:6380/15")
3837
The client expects passwords with special chracters to be URL-encoded (i.e.
3938
`CGI.escape(password)`).
4039

41-
By default, the client will try to read the `REDIS_URL` environment variable
42-
and use that as URL to connect to. The above statement is therefore equivalent
43-
to setting this environment variable and calling `Redis.new` without arguments.
44-
4540
To connect to Redis listening on a Unix socket, try:
4641

4742
```ruby
@@ -76,6 +71,28 @@ redis.get("mykey")
7671
All commands, their arguments, and return values are documented and
7772
available on [RubyDoc.info][rubydoc].
7873

74+
## Connection Pooling and Thread safety
75+
76+
The client does not provide connection pooling. Each `Redis` instance
77+
has one and only one connection to the server, and use of this connection
78+
is protected by a mutex.
79+
80+
As such it is heavilly recommended to use the [`connection_pool` gem], e.g.:
81+
82+
```ruby
83+
module MyApp
84+
def self.redis
85+
@redis ||= ConnectionPool.new do
86+
Redis.new(url: ENV["REDIS_URL"])
87+
end
88+
end
89+
end
90+
91+
MyApp.redis.incr("some-counter")
92+
```
93+
94+
[`connection_pool` gem](https://github.com/mperham/connection_pool)
95+
7996
## Sentinel support
8097

8198
The client is able to perform automatic failover by using [Redis
@@ -118,21 +135,6 @@ redis = Redis.new(name: 'mymaster', sentinels: SENTINELS, role: :master)
118135

119136
[Clustering](https://redis.io/topics/cluster-spec). is supported via the [`redis_cluster` gem](redis_cluster/).
120137

121-
## Storing objects
122-
123-
Redis "string" types can be used to store serialized Ruby objects, for
124-
example with JSON:
125-
126-
```ruby
127-
require "json"
128-
129-
redis.set "foo", [1, 2, 3].to_json
130-
# => OK
131-
132-
JSON.parse(redis.get("foo"))
133-
# => [1, 2, 3]
134-
```
135-
136138
## Pipelining
137139

138140
When multiple commands are executed sequentially, but are not dependent,
@@ -190,15 +192,16 @@ pipeline has successfully executed, all futures are assigned their
190192
respective replies and can be used.
191193

192194
```ruby
195+
set = incr = nil
193196
redis.pipelined do |pipeline|
194-
@set = pipeline.set "foo", "bar"
195-
@incr = pipeline.incr "baz"
197+
set = pipeline.set "foo", "bar"
198+
incr = pipeline.incr "baz"
196199
end
197200

198-
@set.value
201+
set.value
199202
# => "OK"
200203

201-
@incr.value
204+
incr.value
202205
# => 1
203206
```
204207

@@ -277,6 +280,16 @@ Redis.new(reconnect_attempts: [
277280
])
278281
```
279282

283+
If you wish to disable reconnection only for some commands, you can use
284+
`disable_reconnection`:
285+
286+
```ruby
287+
redis.get("some-key") # this may be retried
288+
redis.disable_reconnection do
289+
redis.incr("some-counter") # this won't be retried.
290+
end
291+
```
292+
280293
## SSL/TLS Support
281294

282295
To enable SSL support, pass the `:ssl => true` option when configuring the
@@ -312,13 +325,7 @@ redis = Redis.new(
312325
)
313326
```
314327

315-
[stunnel]: https://www.stunnel.org/
316-
[hitch]: https://hitch-tls.org/
317-
[ghostunnel]: https://github.com/square/ghostunnel
318-
[OpenSSL::SSL::SSLContext documentation]: http://ruby-doc.org/stdlib-2.3.0/libdoc/openssl/rdoc/OpenSSL/SSL/SSLContext.html
319-
320-
*NOTE:* SSL is only supported by the default "Ruby" driver
321-
328+
[OpenSSL::SSL::SSLContext documentation]: http://ruby-doc.org/stdlib-2.5.0/libdoc/openssl/rdoc/OpenSSL/SSL/SSLContext.html
322329

323330
## Expert-Mode Options
324331

@@ -351,7 +358,17 @@ gem "redis"
351358
gem "hiredis-client"
352359
```
353360

354-
When instantiating the client object, specify hiredis:
361+
If your application doesn't call `Bundler.require`, you may have
362+
to require it explictly:
363+
364+
```ruby
365+
require "hiredis-client"
366+
````
367+
368+
This makes the hiredis driver the default.
369+
370+
If you want to be certain hiredis is being used, when instantiating
371+
the client object, specify hiredis:
355372

356373
```ruby
357374
redis = Redis.new(driver: :hiredis)

redis.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ Gem::Specification.new do |s|
4545

4646
s.required_ruby_version = '>= 2.5.0'
4747

48-
s.add_runtime_dependency('redis-client', '~> 0.6')
48+
s.add_runtime_dependency('redis-client', '~> 0.7')
4949
end

redis_cluster/Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ gem 'minitest'
88
gem 'rake'
99
gem 'rubocop', '~> 1.25.1'
1010
gem 'mocha'
11-
gem 'redis-cluster-client', github: 'redis-rb/redis-cluster-client'

redis_cluster/redis_cluster.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@ Gem::Specification.new do |s|
4646

4747
s.required_ruby_version = '>= 2.7.0'
4848

49-
s.add_runtime_dependency('redis-cluster-client', '~> 0.1')
49+
s.add_runtime_dependency('redis-cluster-client', '~> 0.2')
5050
end

0 commit comments

Comments
 (0)