redis_cluster 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e10ed9adf21d43959b884dd43b59474b469c84cf
4
- data.tar.gz: dfab801d69bf40c1d92fdb3f123ba980cc7aeade
3
+ metadata.gz: 8264917dc18e8ffb741b2038f6dcc5b607caab2a
4
+ data.tar.gz: a3e799c1a0887c327f7277ed210ea961b674e414
5
5
  SHA512:
6
- metadata.gz: e0e96edb02ff52f9a4eda36d1e922288a4459669d645ac736a8856a35a4cdbc2ca10b0cc37ab6560b4302eabb2270fe1ead8d9fa4cfb4bea53360ffaab8cae8e
7
- data.tar.gz: 80706f7728f362931760c1473bf7f01b68ee7e95953d85da47126170c43d30af0e138e5116179f8e11fd54544e451f8714351a5148b6c17cc071e4a70a42b741
6
+ metadata.gz: a894308b600b079667cb0dcd9ef2a9e4ca4ea7dc9d19d679a3af483122ae30fd11d981a7ed0e8a6f6483ff2438834e7ce538296a670d819add2c8cd65edaafa1
7
+ data.tar.gz: cd3eff23e5c40d3e3a901e8af38f78991e2973de198770df3e66c5f5a924ba171f0322653e94aba55d14cbd7fc7b03e6071ba1bd472979ec596df877dcf2cdb4
@@ -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
@@ -41,8 +41,8 @@ module RedisCluster
41
41
  end
42
42
 
43
43
  def self.redis(options)
44
- extra_options = {timeout: Configuration::DEFAULT_TIMEOUT, driver: 'hiredis'.freeze}
45
- ::Redis.new(options.merge(extra_options))
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
@@ -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) }
@@ -1,3 +1,3 @@
1
1
  module RedisCluster
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
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.1
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-03-24 00:00:00.000000000 Z
11
+ date: 2018-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis