redis_cluster 0.3.1 → 0.3.2
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/lib/redis_cluster/client.rb +5 -0
- data/lib/redis_cluster/configuration.rb +1 -1
- data/lib/redis_cluster/node.rb +2 -2
- data/lib/redis_cluster/pool.rb +26 -0
- data/lib/redis_cluster/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8264917dc18e8ffb741b2038f6dcc5b607caab2a
|
4
|
+
data.tar.gz: a3e799c1a0887c327f7277ed210ea961b674e414
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a894308b600b079667cb0dcd9ef2a9e4ca4ea7dc9d19d679a3af483122ae30fd11d981a7ed0e8a6f6483ff2438834e7ce538296a670d819add2c8cd65edaafa1
|
7
|
+
data.tar.gz: cd3eff23e5c40d3e3a901e8af38f78991e2973de198770df3e66c5f5a924ba171f0322653e94aba55d14cbd7fc7b03e6071ba1bd472979ec596df877dcf2cdb4
|
data/lib/redis_cluster/client.rb
CHANGED
@@ -118,6 +118,11 @@ module RedisCluster
|
|
118
118
|
execute(method, args, &block)
|
119
119
|
end
|
120
120
|
|
121
|
+
# Add default argument to keys to match redis client interface
|
122
|
+
def keys(glob = "*", &block)
|
123
|
+
execute("keys", [glob], &block)
|
124
|
+
end
|
125
|
+
|
121
126
|
# Closes all open connections and reloads the client pool.
|
122
127
|
#
|
123
128
|
# Normally host information from the last time the node pool was reloaded
|
@@ -16,7 +16,7 @@ module RedisCluster
|
|
16
16
|
hincrby hincrbyfloat hkeys hvals hgetall publish pfadd
|
17
17
|
).freeze
|
18
18
|
|
19
|
-
SUPPORT_MULTI_NODE_METHODS = %w(keys script multi pipelined).freeze
|
19
|
+
SUPPORT_MULTI_NODE_METHODS = %w(keys script multi pipelined scan).freeze
|
20
20
|
|
21
21
|
def self.method_names
|
22
22
|
SUPPORT_SINGLE_NODE_METHODS + SUPPORT_MULTI_NODE_METHODS
|
data/lib/redis_cluster/node.rb
CHANGED
@@ -41,8 +41,8 @@ module RedisCluster
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def self.redis(options)
|
44
|
-
|
45
|
-
::Redis.new(
|
44
|
+
default_options = {timeout: Configuration::DEFAULT_TIMEOUT, driver: 'hiredis'.freeze}
|
45
|
+
::Redis.new(default_options.merge(options))
|
46
46
|
end
|
47
47
|
|
48
48
|
end # end Node
|
data/lib/redis_cluster/pool.rb
CHANGED
@@ -54,8 +54,34 @@ module RedisCluster
|
|
54
54
|
random_node.execute :pipelined, args, &block
|
55
55
|
end
|
56
56
|
|
57
|
+
# Implements scan across all nodes in the pool.
|
58
|
+
# Cursors will behave strangely if the node list changes during iteration.
|
59
|
+
def scan(args)
|
60
|
+
scan_cursor = args.first
|
61
|
+
options = args[1] || {}
|
62
|
+
node_cursor, node_index = decode_scan_cursor(scan_cursor)
|
63
|
+
next_node_cursor, result = @nodes[node_index].execute("scan", [node_cursor, options])
|
64
|
+
[encode_next_scan_cursor(next_node_cursor, node_index), result]
|
65
|
+
end
|
66
|
+
|
57
67
|
private
|
58
68
|
|
69
|
+
def encode_next_scan_cursor(next_node_cursor, node_index)
|
70
|
+
if next_node_cursor == '0'
|
71
|
+
# '0' indicates the end of iteration. Advance the node index and
|
72
|
+
# start at the '0' position on the next node. If this was the last node,
|
73
|
+
# loop around and return '0' to indicate iteration is done.
|
74
|
+
((node_index + 1) % @nodes.size)
|
75
|
+
else
|
76
|
+
((next_node_cursor.to_i * @nodes.size) + node_index)
|
77
|
+
end.to_s # Cursors are strings
|
78
|
+
end
|
79
|
+
|
80
|
+
def decode_scan_cursor(cursor)
|
81
|
+
node_cursor, node_index = cursor.to_i.divmod(@nodes.size)
|
82
|
+
[node_cursor.to_s, node_index] # Cursors are strings.
|
83
|
+
end
|
84
|
+
|
59
85
|
def node_by(key)
|
60
86
|
slot = Slot.slot_by(key)
|
61
87
|
@nodes.find { |node| node.has_slot?(slot) }
|
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.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- wangzc
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|