redis_cluster 0.2.7 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/README.md +13 -1
- data/lib/redis_cluster/client.rb +3 -2
- data/lib/redis_cluster/pool.rb +4 -3
- data/lib/redis_cluster/version.rb +1 -1
- data/lib/redis_cluster.rb +2 -2
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41b457f6ceafa44ab6ace3d09ad557fda6fec135
|
4
|
+
data.tar.gz: d92d1ad1c22b95dfa7f15c282bec660dd9f93072
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df2c72b585d8f4c065abed593b3362c4f5bd0276f0e488151a9698fe5db8fe47e5db5b3ba688ff11e3f5f2c64792809be43b6f13511d75a9ab278188334de2a1
|
7
|
+
data.tar.gz: 5a4b84c9e6a6db6b4a685c9d329de132593d67744feccc315f27f9a10b8d8da23efd7f205bab22f5b6aa1fe2514a3ce4d461b7db83f686bb69fbac3d70d6852a
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -28,7 +28,8 @@ Or install it yourself as:
|
|
28
28
|
First you need to configure redis cluster with some nodes! Please see: [https://redis.io/topics/cluster-tutorial](https://redis.io/topics/cluster-tutorial)
|
29
29
|
|
30
30
|
```ruby
|
31
|
-
|
31
|
+
# don't need all, gem can auto detect all nodes, and process failover if some master nodes down
|
32
|
+
hosts = [{host: '127.0.0.1', port: 7000}, {host: '127.0.0.1', port: 7001}]
|
32
33
|
rs = RedisCluster.new hosts
|
33
34
|
rs.set "test", 1
|
34
35
|
rs.get "test"
|
@@ -39,6 +40,17 @@ now support keys command with scanning all nodes:
|
|
39
40
|
rs.keys 'test*'
|
40
41
|
```
|
41
42
|
|
43
|
+
limited support commands: pipelined, multi
|
44
|
+
```ruby
|
45
|
+
# Only support pipeline commands to one redis node once
|
46
|
+
# You must ensure keys at one slot: use same key or hash tags
|
47
|
+
# If you don't, not raise any errors now
|
48
|
+
rs.pipelined do
|
49
|
+
rs.set "{foo}one", 1
|
50
|
+
rs.set "{foo}two", 2
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
42
54
|
## Benchmark test
|
43
55
|
|
44
56
|
A simple benchmark at my macbook, start 4 master nodes (and 4 cold slave nodes), running with one ruby process.
|
data/lib/redis_cluster/client.rb
CHANGED
@@ -6,7 +6,7 @@ module RedisCluster
|
|
6
6
|
|
7
7
|
def initialize(startup_hosts, global_configs = {})
|
8
8
|
@startup_hosts = startup_hosts
|
9
|
-
@pool = Pool.new
|
9
|
+
@pool = Pool.new(global_configs)
|
10
10
|
@mutex = Mutex.new
|
11
11
|
reload_pool_nodes(true)
|
12
12
|
end
|
@@ -55,7 +55,7 @@ module RedisCluster
|
|
55
55
|
@mutex.synchronize do
|
56
56
|
@startup_hosts.each do |options|
|
57
57
|
begin
|
58
|
-
redis = Node.redis(options)
|
58
|
+
redis = Node.redis(@pool.global_configs.merge(options))
|
59
59
|
slots_mapping = redis.cluster("slots").group_by{|x| x[2]}
|
60
60
|
@pool.delete_except!(slots_mapping.keys)
|
61
61
|
slots_mapping.each do |host, infos|
|
@@ -64,6 +64,7 @@ module RedisCluster
|
|
64
64
|
end
|
65
65
|
rescue Redis::CommandError => e
|
66
66
|
raise e if raise_error && e.message =~ /cluster\ support\ disabled$/
|
67
|
+
raise e if e.message =~ /NOAUTH\ Authentication\ required/
|
67
68
|
next
|
68
69
|
rescue
|
69
70
|
next
|
data/lib/redis_cluster/pool.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
module RedisCluster
|
2
2
|
|
3
3
|
class Pool
|
4
|
-
attr_reader :nodes
|
4
|
+
attr_reader :nodes, :global_configs
|
5
5
|
|
6
|
-
def initialize
|
6
|
+
def initialize(global_configs = {})
|
7
7
|
@nodes = []
|
8
|
+
@global_configs = global_configs
|
8
9
|
end
|
9
10
|
|
10
11
|
# TODO: type check
|
11
12
|
def add_node!(node_options, slots)
|
12
|
-
new_node = Node.new(node_options)
|
13
|
+
new_node = Node.new(global_configs.merge(node_options))
|
13
14
|
node = @nodes.find {|n| n.name == new_node.name } || new_node
|
14
15
|
node.slots = slots
|
15
16
|
@nodes.push(node).uniq!
|
data/lib/redis_cluster.rb
CHANGED
@@ -8,8 +8,8 @@ module RedisCluster
|
|
8
8
|
# startup_hosts examples:
|
9
9
|
# [{host: 'xxx', port: 'xxx'}, {host: 'xxx', port: 'xxx'}, ...]
|
10
10
|
# global_configs:
|
11
|
-
#
|
12
|
-
def new(startup_hosts,
|
11
|
+
# options for redis: password, ...
|
12
|
+
def new(startup_hosts, global_configs = {})
|
13
13
|
@client = Client.new(startup_hosts, global_configs)
|
14
14
|
end
|
15
15
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis_cluster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- wangzc
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -142,9 +142,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
142
|
version: '0'
|
143
143
|
requirements: []
|
144
144
|
rubyforge_project:
|
145
|
-
rubygems_version: 2.
|
145
|
+
rubygems_version: 2.6.10
|
146
146
|
signing_key:
|
147
147
|
specification_version: 4
|
148
148
|
summary: redis cluster client
|
149
149
|
test_files: []
|
150
|
-
has_rdoc:
|