Skip to content

Commit 376e063

Browse files
authored
Fix README (#24)
1 parent ad5c2c6 commit 376e063

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

README.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
Redis Cluster Client
55
===============================================================================
6-
This library is a client for Redis cluster.
6+
This library is a client for [Redis cluster](https://redis.io/docs/reference/cluster-spec/).
77
It depends on [redis-client](https://github.com/redis-rb/redis-client).
88
So it would be better to read `redis-client` documents first.
99

@@ -14,10 +14,10 @@ gem 'redis-cluster-client'
1414

1515
## Initialization
1616
| key | type | default | description |
17-
| --- | --- |
18-
| `nodes` | `String` or `Array<String, Hash>` | `['redis://127.0.0.1:6379]` | node addresses for startup connection |
19-
| `replica` | Boolean | `false` | `true` if client use scale read feature |
20-
| `fixed_hostname` | `String` | `nil` | specify if client connects to cluster with SSL and single endpoint |
17+
| --- | --- | --- | --- |
18+
| `:nodes` | String or Array<String, Hash> | `['redis://127.0.0.1:6379']` | node addresses for startup connection |
19+
| `:replica` | Boolean | `false` | `true` if client should use scale read feature |
20+
| `:fixed_hostname` | String | `nil` | required if client should connect to single endpoint with SSL |
2121

2222
Also, [the other generic options](https://github.com/redis-rb/redis-client#configuration) can be passed.
2323

@@ -29,7 +29,7 @@ Also, [the other generic options](https://github.com/redis-rb/redis-client#confi
2929
RedisClient.cluster.new_client
3030
#=> #<RedisClient::Cluster 172.20.0.2:6379, 172.20.0.6:6379, 172.20.0.7:6379>
3131

32-
# To connect to all nodes and to use scale reading feature
32+
# To connect to all nodes to use scale reading feature
3333
RedisClient.cluster(replica: true).new_client
3434
#=> #<RedisClient::Cluster 172.20.0.2:6379, 172.20.0.3:6379, 172.20.0.4:6379, 172.20.0.5:6379, 172.20.0.6:6379, 172.20.0.7:6379>
3535

@@ -73,8 +73,19 @@ A part of commands can be passed multiple keys. But it has a constraint the keys
7373
The following error occurs because keys must be in the same hash slot and not just the same node.
7474

7575
```ruby
76-
RedisClient.cluster.new_client.call('MGET', 'key1', 'key2', 'key3')
76+
cli = RedisClient.cluster.new_client
77+
78+
cli.call('MGET', 'key1', 'key2', 'key3')
7779
#=> CROSSSLOT Keys in request don't hash to the same slot (RedisClient::CommandError)
80+
81+
cli.call('CLUSTER', 'KEYSLOT', 'key1')
82+
#=> 9189
83+
84+
cli.call('CLUSTER', 'KEYSLOT', 'key2')
85+
#=> 4998
86+
87+
cli.call('CLUSTER', 'KEYSLOT', 'key3')
88+
#=> 935
7889
```
7990

8091
## Connection pooling

lib/redis_client/cluster/node.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class Node
1212
SLOT_SIZE = 16_384
1313
MIN_SLOT = 0
1414
MAX_SLOT = SLOT_SIZE - 1
15+
IGNORE_GENERIC_CONFIG_KEYS = %i[url host port path].freeze
16+
1517
ReloadNeeded = Class.new(::RedisClient::Error)
1618

1719
class Config < ::RedisClient::Config
@@ -207,7 +209,10 @@ def build_clients(options, pool: nil, **kwargs)
207209
options.filter_map do |node_key, option|
208210
next if replica_disabled? && replica?(node_key)
209211

210-
config = ::RedisClient::Cluster::Node::Config.new(scale_read: replica?(node_key), **option.merge(kwargs))
212+
config = ::RedisClient::Cluster::Node::Config.new(
213+
scale_read: replica?(node_key),
214+
**option.merge(kwargs.reject { |k, _| IGNORE_GENERIC_CONFIG_KEYS.include?(k) })
215+
)
211216
client = pool.nil? ? config.new_client : config.new_pool(**pool)
212217

213218
[node_key, client]

0 commit comments

Comments
 (0)