redis_cluster 0.2.1 → 0.2.3
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/README.md +29 -2
- data/lib/redis_cluster.rb +1 -0
- data/lib/redis_cluster/client.rb +17 -16
- data/lib/redis_cluster/configuration.rb +1 -1
- data/lib/redis_cluster/errors.rb +5 -0
- data/lib/redis_cluster/pool.rb +13 -1
- data/lib/redis_cluster/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f73539f72f1afc171f22acfd295dbf491f745ec2
|
4
|
+
data.tar.gz: 25c3ede9fa06f5402d21d3aa5b3aff8df64f77a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10437f66a1ca4fe5190d388fddc2e1619ca0fdb1db0c12506ce7cdeb43cd7fe37dba92b70b0a5e98ae323bb96143ec10162c9ef4d13bddd094af56387f250df5
|
7
|
+
data.tar.gz: 66e1268bfbd524926b61474c13d98bfb249eb7a2bfd71b4c1e6bac0c1ce59bd8b84721ce5a3e520f55779cbcd216e200f37b0418d4eecd9458cccd048dcd690a
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
RedisCluster for ruby is rewrited from [https://github.com/antirez/redis-rb-cluster](https://github.com/antirez/redis-rb-cluster)
|
4
4
|
|
5
|
-
Now is developing, and not use in any production environments.
|
5
|
+
Now is developing, only support single node methods, and not use in any production environments.
|
6
6
|
|
7
7
|
|
8
8
|
## Installation
|
@@ -26,12 +26,39 @@ Or install it yourself as:
|
|
26
26
|
Doing!
|
27
27
|
|
28
28
|
```ruby
|
29
|
-
hosts = [{host: 127.0.0.1, port: 7000}, {host: 127.0.0.1, port: 7001}]
|
29
|
+
hosts = [{host: '127.0.0.1', port: 7000}, {host: '127.0.0.1', port: 7001}] # don't need all, gem can auto detect all nodes, and process failover if some master nodes down
|
30
30
|
rs = RedisCluster.new hosts
|
31
31
|
rs.set "test", 1
|
32
32
|
rs.get "test"
|
33
33
|
```
|
34
34
|
|
35
|
+
## Benchmark test
|
36
|
+
|
37
|
+
A simple benchmark at my macbook, start 4 master nodes (and 4 cold slave nodes), running with one ruby process.
|
38
|
+
This only testing redis_cluster can work, not for redis Performance. When I fork 8 ruby process same time and run get command,redis can run 80,000 - 110,000 times per second at my macbook.
|
39
|
+
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
Benchmark.bm do |x|
|
43
|
+
x.report do
|
44
|
+
1.upto(100_000).each do |i|
|
45
|
+
redis.get "test#{i}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
x.report do
|
49
|
+
1.upto(100_000).each do |i|
|
50
|
+
redis.set "test#{i}", i
|
51
|
+
end
|
52
|
+
end
|
53
|
+
x.report do
|
54
|
+
1.upto(100_000).each do |i|
|
55
|
+
redis.del "test#{i}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
|
35
62
|
## Development
|
36
63
|
|
37
64
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/redis_cluster.rb
CHANGED
data/lib/redis_cluster/client.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "thread"
|
2
|
+
|
1
3
|
module RedisCluster
|
2
4
|
|
3
5
|
class Client
|
@@ -5,7 +7,7 @@ module RedisCluster
|
|
5
7
|
def initialize(startup_hosts, global_configs = {})
|
6
8
|
@startup_hosts = startup_hosts
|
7
9
|
@pool = Pool.new
|
8
|
-
@
|
10
|
+
@mutex = Mutex.new
|
9
11
|
reload_pool_nodes
|
10
12
|
end
|
11
13
|
|
@@ -48,24 +50,23 @@ module RedisCluster
|
|
48
50
|
private
|
49
51
|
|
50
52
|
def reload_pool_nodes
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
53
|
+
@mutex.synchronize do
|
54
|
+
@startup_hosts.each do |options|
|
55
|
+
begin
|
56
|
+
redis = Node.redis(options)
|
57
|
+
slots_mapping = redis.cluster("slots").group_by{|x| x[2]}
|
58
|
+
@pool.delete_except!(slots_mapping.keys)
|
59
|
+
slots_mapping.each do |host, infos|
|
60
|
+
slots_ranges = infos.map {|x| x[0]..x[1] }
|
61
|
+
@pool.add_node!({host: host[0], port: host[1]}, slots_ranges)
|
62
|
+
end
|
63
|
+
rescue
|
64
|
+
next
|
61
65
|
end
|
62
|
-
|
63
|
-
next
|
66
|
+
break
|
64
67
|
end
|
65
|
-
|
68
|
+
fresh_startup_nodes
|
66
69
|
end
|
67
|
-
@locking = false
|
68
|
-
fresh_startup_nodes
|
69
70
|
end
|
70
71
|
|
71
72
|
def fresh_startup_nodes
|
data/lib/redis_cluster/pool.rb
CHANGED
@@ -24,14 +24,20 @@ module RedisCluster
|
|
24
24
|
# asking
|
25
25
|
# random_node
|
26
26
|
def execute(method, args, other_options)
|
27
|
+
return keys(args.first) if Configuration::SUPPORT_MULTI_NODE_METHODS.include?(method.to_s)
|
28
|
+
|
27
29
|
key = key_by_command(method, args)
|
28
|
-
raise
|
30
|
+
raise NotSupportError if key.nil?
|
29
31
|
|
30
32
|
node = other_options[:random_node] ? random_node : node_by(key)
|
31
33
|
node.asking if other_options[:asking]
|
32
34
|
node.execute(method, args)
|
33
35
|
end
|
34
36
|
|
37
|
+
def keys(glob = "*")
|
38
|
+
on_each_node(:keys, glob).flatten
|
39
|
+
end
|
40
|
+
|
35
41
|
private
|
36
42
|
|
37
43
|
def node_by(key)
|
@@ -52,6 +58,12 @@ module RedisCluster
|
|
52
58
|
end
|
53
59
|
end
|
54
60
|
|
61
|
+
def on_each_node(method, *args)
|
62
|
+
@nodes.map do |node|
|
63
|
+
node.execute(method, args)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
55
67
|
end # end pool
|
56
68
|
|
57
69
|
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.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- wangzc
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -99,6 +99,7 @@ files:
|
|
99
99
|
- lib/redis_cluster/client.rb
|
100
100
|
- lib/redis_cluster/configuration.rb
|
101
101
|
- lib/redis_cluster/crc16.rb
|
102
|
+
- lib/redis_cluster/errors.rb
|
102
103
|
- lib/redis_cluster/node.rb
|
103
104
|
- lib/redis_cluster/pool.rb
|
104
105
|
- lib/redis_cluster/slot.rb
|