redis 4.1.0.beta1 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -2
- data/README.md +45 -0
- data/lib/redis.rb +497 -20
- data/lib/redis/client.rb +14 -6
- data/lib/redis/cluster.rb +1 -0
- data/lib/redis/cluster/command_loader.rb +2 -0
- data/lib/redis/cluster/node_loader.rb +2 -0
- data/lib/redis/cluster/option.rb +1 -0
- data/lib/redis/cluster/slot_loader.rb +2 -0
- data/lib/redis/distributed.rb +3 -4
- data/lib/redis/version.rb +1 -1
- metadata +20 -243
- data/.gitignore +0 -19
- data/.travis.yml +0 -61
- data/.travis/Gemfile +0 -18
- data/.yardopts +0 -3
- data/Gemfile +0 -8
- data/benchmarking/logging.rb +0 -71
- data/benchmarking/pipeline.rb +0 -51
- data/benchmarking/speed.rb +0 -21
- data/benchmarking/suite.rb +0 -24
- data/benchmarking/worker.rb +0 -71
- data/bin/build +0 -71
- data/bors.toml +0 -14
- data/examples/basic.rb +0 -15
- data/examples/consistency.rb +0 -114
- data/examples/dist_redis.rb +0 -43
- data/examples/incr-decr.rb +0 -17
- data/examples/list.rb +0 -26
- data/examples/pubsub.rb +0 -37
- data/examples/sentinel.rb +0 -41
- data/examples/sentinel/start +0 -49
- data/examples/sets.rb +0 -36
- data/examples/unicorn/config.ru +0 -3
- data/examples/unicorn/unicorn.rb +0 -20
- data/makefile +0 -74
- data/redis.gemspec +0 -42
- data/test/bitpos_test.rb +0 -63
- data/test/blocking_commands_test.rb +0 -40
- data/test/client_test.rb +0 -76
- data/test/cluster_abnormal_state_test.rb +0 -38
- data/test/cluster_blocking_commands_test.rb +0 -15
- data/test/cluster_client_internals_test.rb +0 -77
- data/test/cluster_client_key_hash_tags_test.rb +0 -88
- data/test/cluster_client_options_test.rb +0 -147
- data/test/cluster_client_pipelining_test.rb +0 -59
- data/test/cluster_client_replicas_test.rb +0 -36
- data/test/cluster_client_slots_test.rb +0 -94
- data/test/cluster_client_transactions_test.rb +0 -71
- data/test/cluster_commands_on_cluster_test.rb +0 -165
- data/test/cluster_commands_on_connection_test.rb +0 -40
- data/test/cluster_commands_on_geo_test.rb +0 -74
- data/test/cluster_commands_on_hashes_test.rb +0 -11
- data/test/cluster_commands_on_hyper_log_log_test.rb +0 -17
- data/test/cluster_commands_on_keys_test.rb +0 -134
- data/test/cluster_commands_on_lists_test.rb +0 -15
- data/test/cluster_commands_on_pub_sub_test.rb +0 -101
- data/test/cluster_commands_on_scripting_test.rb +0 -56
- data/test/cluster_commands_on_server_test.rb +0 -221
- data/test/cluster_commands_on_sets_test.rb +0 -39
- data/test/cluster_commands_on_sorted_sets_test.rb +0 -35
- data/test/cluster_commands_on_streams_test.rb +0 -196
- data/test/cluster_commands_on_strings_test.rb +0 -15
- data/test/cluster_commands_on_transactions_test.rb +0 -41
- data/test/cluster_commands_on_value_types_test.rb +0 -14
- data/test/command_map_test.rb +0 -28
- data/test/commands_on_geo_test.rb +0 -116
- data/test/commands_on_hashes_test.rb +0 -7
- data/test/commands_on_hyper_log_log_test.rb +0 -7
- data/test/commands_on_lists_test.rb +0 -7
- data/test/commands_on_sets_test.rb +0 -7
- data/test/commands_on_sorted_sets_test.rb +0 -7
- data/test/commands_on_strings_test.rb +0 -7
- data/test/commands_on_value_types_test.rb +0 -207
- data/test/connection_handling_test.rb +0 -275
- data/test/connection_test.rb +0 -57
- data/test/distributed_blocking_commands_test.rb +0 -52
- data/test/distributed_commands_on_hashes_test.rb +0 -21
- data/test/distributed_commands_on_hyper_log_log_test.rb +0 -26
- data/test/distributed_commands_on_lists_test.rb +0 -19
- data/test/distributed_commands_on_sets_test.rb +0 -105
- data/test/distributed_commands_on_sorted_sets_test.rb +0 -59
- data/test/distributed_commands_on_strings_test.rb +0 -79
- data/test/distributed_commands_on_value_types_test.rb +0 -129
- data/test/distributed_commands_requiring_clustering_test.rb +0 -162
- data/test/distributed_connection_handling_test.rb +0 -21
- data/test/distributed_internals_test.rb +0 -68
- data/test/distributed_key_tags_test.rb +0 -50
- data/test/distributed_persistence_control_commands_test.rb +0 -24
- data/test/distributed_publish_subscribe_test.rb +0 -90
- data/test/distributed_remote_server_control_commands_test.rb +0 -64
- data/test/distributed_scripting_test.rb +0 -100
- data/test/distributed_sorting_test.rb +0 -18
- data/test/distributed_test.rb +0 -56
- data/test/distributed_transactions_test.rb +0 -30
- data/test/encoding_test.rb +0 -14
- data/test/error_replies_test.rb +0 -57
- data/test/fork_safety_test.rb +0 -60
- data/test/helper.rb +0 -344
- data/test/helper_test.rb +0 -22
- data/test/internals_test.rb +0 -395
- data/test/lint/blocking_commands.rb +0 -174
- data/test/lint/hashes.rb +0 -203
- data/test/lint/hyper_log_log.rb +0 -74
- data/test/lint/lists.rb +0 -159
- data/test/lint/sets.rb +0 -282
- data/test/lint/sorted_sets.rb +0 -497
- data/test/lint/strings.rb +0 -348
- data/test/lint/value_types.rb +0 -130
- data/test/persistence_control_commands_test.rb +0 -24
- data/test/pipelining_commands_test.rb +0 -246
- data/test/publish_subscribe_test.rb +0 -280
- data/test/remote_server_control_commands_test.rb +0 -175
- data/test/scanning_test.rb +0 -407
- data/test/scripting_test.rb +0 -76
- data/test/sentinel_command_test.rb +0 -78
- data/test/sentinel_test.rb +0 -253
- data/test/sorting_test.rb +0 -57
- data/test/ssl_test.rb +0 -69
- data/test/support/cluster/orchestrator.rb +0 -199
- data/test/support/connection/hiredis.rb +0 -1
- data/test/support/connection/ruby.rb +0 -1
- data/test/support/connection/synchrony.rb +0 -17
- data/test/support/redis_mock.rb +0 -130
- data/test/support/ssl/gen_certs.sh +0 -31
- data/test/support/ssl/trusted-ca.crt +0 -25
- data/test/support/ssl/trusted-ca.key +0 -27
- data/test/support/ssl/trusted-cert.crt +0 -81
- data/test/support/ssl/trusted-cert.key +0 -28
- data/test/support/ssl/untrusted-ca.crt +0 -26
- data/test/support/ssl/untrusted-ca.key +0 -27
- data/test/support/ssl/untrusted-cert.crt +0 -82
- data/test/support/ssl/untrusted-cert.key +0 -28
- data/test/support/wire/synchrony.rb +0 -24
- data/test/support/wire/thread.rb +0 -5
- data/test/synchrony_driver.rb +0 -85
- data/test/test.conf.erb +0 -9
- data/test/thread_safety_test.rb +0 -60
- data/test/transactions_test.rb +0 -272
- data/test/unknown_commands_test.rb +0 -12
- data/test/url_param_test.rb +0 -136
@@ -1,175 +0,0 @@
|
|
1
|
-
require_relative "helper"
|
2
|
-
|
3
|
-
class TestRemoteServerControlCommands < Test::Unit::TestCase
|
4
|
-
|
5
|
-
include Helper::Client
|
6
|
-
|
7
|
-
def test_info
|
8
|
-
keys = [
|
9
|
-
"redis_version",
|
10
|
-
"uptime_in_seconds",
|
11
|
-
"uptime_in_days",
|
12
|
-
"connected_clients",
|
13
|
-
"used_memory",
|
14
|
-
"total_connections_received",
|
15
|
-
"total_commands_processed",
|
16
|
-
]
|
17
|
-
|
18
|
-
info = r.info
|
19
|
-
|
20
|
-
keys.each do |k|
|
21
|
-
msg = "expected #info to include #{k}"
|
22
|
-
assert info.keys.include?(k), msg
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_info_commandstats
|
27
|
-
target_version "2.5.7" do
|
28
|
-
r.config(:resetstat)
|
29
|
-
r.ping
|
30
|
-
|
31
|
-
result = r.info(:commandstats)
|
32
|
-
assert_equal "1", result["ping"]["calls"]
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_monitor_redis_lt_2_5_0
|
37
|
-
return unless version < "2.5.0"
|
38
|
-
|
39
|
-
log = []
|
40
|
-
|
41
|
-
wire = Wire.new do
|
42
|
-
Redis.new(OPTIONS).monitor do |line|
|
43
|
-
log << line
|
44
|
-
break if log.size == 3
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
Wire.pass while log.empty? # Faster than sleep
|
49
|
-
|
50
|
-
r.set "foo", "s1"
|
51
|
-
|
52
|
-
wire.join
|
53
|
-
|
54
|
-
assert log[-1][%q{(db 15) "set" "foo" "s1"}]
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_monitor_redis_gte_2_5_0
|
58
|
-
return unless version >= "2.5.0"
|
59
|
-
|
60
|
-
log = []
|
61
|
-
|
62
|
-
wire = Wire.new do
|
63
|
-
Redis.new(OPTIONS).monitor do |line|
|
64
|
-
log << line
|
65
|
-
break if line =~ /set/
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
Wire.pass while log.empty? # Faster than sleep
|
70
|
-
|
71
|
-
r.set "foo", "s1"
|
72
|
-
|
73
|
-
wire.join
|
74
|
-
|
75
|
-
assert log[-1] =~ /\b15\b.* "set" "foo" "s1"/
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_monitor_returns_value_for_break
|
79
|
-
result = r.monitor do |line|
|
80
|
-
break line
|
81
|
-
end
|
82
|
-
|
83
|
-
assert_equal "OK", result
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_echo
|
87
|
-
assert_equal "foo bar baz\n", r.echo("foo bar baz\n")
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_debug
|
91
|
-
r.set "foo", "s1"
|
92
|
-
|
93
|
-
assert r.debug(:object, "foo").kind_of?(String)
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_object
|
97
|
-
r.lpush "list", "value"
|
98
|
-
|
99
|
-
assert_equal 1, r.object(:refcount, "list")
|
100
|
-
encoding = r.object(:encoding, "list")
|
101
|
-
assert "ziplist" == encoding || "quicklist" == encoding, "Wrong encoding for list"
|
102
|
-
assert r.object(:idletime, "list").kind_of?(Integer)
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_sync
|
106
|
-
redis_mock(:sync => lambda { "+OK" }) do |redis|
|
107
|
-
assert_equal "OK", redis.sync
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
def test_slowlog
|
112
|
-
r.slowlog(:reset)
|
113
|
-
result = r.slowlog(:len)
|
114
|
-
assert_equal 0, result
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_client
|
118
|
-
assert_equal r.instance_variable_get(:@client), r._client
|
119
|
-
end
|
120
|
-
|
121
|
-
def test_client_list
|
122
|
-
return if version < "2.4.0"
|
123
|
-
|
124
|
-
keys = [
|
125
|
-
"addr",
|
126
|
-
"fd",
|
127
|
-
"name",
|
128
|
-
"age",
|
129
|
-
"idle",
|
130
|
-
"flags",
|
131
|
-
"db",
|
132
|
-
"sub",
|
133
|
-
"psub",
|
134
|
-
"multi",
|
135
|
-
"qbuf",
|
136
|
-
"qbuf-free",
|
137
|
-
"obl",
|
138
|
-
"oll",
|
139
|
-
"omem",
|
140
|
-
"events",
|
141
|
-
"cmd"
|
142
|
-
]
|
143
|
-
|
144
|
-
clients = r.client(:list)
|
145
|
-
clients.each do |client|
|
146
|
-
keys.each do |k|
|
147
|
-
msg = "expected #client(:list) to include #{k}"
|
148
|
-
assert client.keys.include?(k), msg
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
def test_client_kill
|
154
|
-
return if version < "2.6.9"
|
155
|
-
|
156
|
-
r.client(:setname, 'redis-rb')
|
157
|
-
clients = r.client(:list)
|
158
|
-
i = clients.index {|client| client['name'] == 'redis-rb'}
|
159
|
-
assert_equal "OK", r.client(:kill, clients[i]["addr"])
|
160
|
-
|
161
|
-
clients = r.client(:list)
|
162
|
-
i = clients.index {|client| client['name'] == 'redis-rb'}
|
163
|
-
assert_equal nil, i
|
164
|
-
end
|
165
|
-
|
166
|
-
def test_client_getname_and_setname
|
167
|
-
return if version < "2.6.9"
|
168
|
-
|
169
|
-
assert_equal nil, r.client(:getname)
|
170
|
-
|
171
|
-
r.client(:setname, 'redis-rb')
|
172
|
-
name = r.client(:getname)
|
173
|
-
assert_equal 'redis-rb', name
|
174
|
-
end
|
175
|
-
end
|
data/test/scanning_test.rb
DELETED
@@ -1,407 +0,0 @@
|
|
1
|
-
require_relative "helper"
|
2
|
-
|
3
|
-
class TestScanning < Test::Unit::TestCase
|
4
|
-
|
5
|
-
include Helper::Client
|
6
|
-
|
7
|
-
def test_scan_basic
|
8
|
-
target_version "2.7.105" do
|
9
|
-
r.debug :populate, 1000
|
10
|
-
|
11
|
-
cursor = 0
|
12
|
-
all_keys = []
|
13
|
-
loop {
|
14
|
-
cursor, keys = r.scan cursor
|
15
|
-
all_keys += keys
|
16
|
-
break if cursor == "0"
|
17
|
-
}
|
18
|
-
|
19
|
-
assert_equal 1000, all_keys.uniq.size
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_scan_count
|
24
|
-
target_version "2.7.105" do
|
25
|
-
r.debug :populate, 1000
|
26
|
-
|
27
|
-
cursor = 0
|
28
|
-
all_keys = []
|
29
|
-
loop {
|
30
|
-
cursor, keys = r.scan cursor, :count => 5
|
31
|
-
all_keys += keys
|
32
|
-
break if cursor == "0"
|
33
|
-
}
|
34
|
-
|
35
|
-
assert_equal 1000, all_keys.uniq.size
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_scan_match
|
40
|
-
target_version "2.7.105" do
|
41
|
-
r.debug :populate, 1000
|
42
|
-
|
43
|
-
cursor = 0
|
44
|
-
all_keys = []
|
45
|
-
loop {
|
46
|
-
cursor, keys = r.scan cursor, :match => "key:1??"
|
47
|
-
all_keys += keys
|
48
|
-
break if cursor == "0"
|
49
|
-
}
|
50
|
-
|
51
|
-
assert_equal 100, all_keys.uniq.size
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_scan_each_enumerator
|
56
|
-
target_version "2.7.105" do
|
57
|
-
|
58
|
-
r.debug :populate, 1000
|
59
|
-
|
60
|
-
scan_enumerator = r.scan_each
|
61
|
-
assert_equal true, scan_enumerator.is_a?(::Enumerator)
|
62
|
-
|
63
|
-
keys_from_scan = scan_enumerator.to_a.uniq
|
64
|
-
all_keys = r.keys "*"
|
65
|
-
|
66
|
-
assert all_keys.sort == keys_from_scan.sort
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_scan_each_enumerator_match
|
71
|
-
target_version "2.7.105" do
|
72
|
-
|
73
|
-
r.debug :populate, 1000
|
74
|
-
|
75
|
-
keys_from_scan = r.scan_each(:match => "key:1??").to_a.uniq
|
76
|
-
all_keys = r.keys "key:1??"
|
77
|
-
|
78
|
-
assert all_keys.sort == keys_from_scan.sort
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_scan_each_block
|
83
|
-
target_version "2.7.105" do
|
84
|
-
|
85
|
-
r.debug :populate, 100
|
86
|
-
|
87
|
-
keys_from_scan = []
|
88
|
-
r.scan_each {|key|
|
89
|
-
keys_from_scan << key
|
90
|
-
}
|
91
|
-
|
92
|
-
all_keys = r.keys "*"
|
93
|
-
|
94
|
-
assert all_keys.sort == keys_from_scan.uniq.sort
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_scan_each_block_match
|
99
|
-
target_version "2.7.105" do
|
100
|
-
|
101
|
-
r.debug :populate, 100
|
102
|
-
|
103
|
-
keys_from_scan = []
|
104
|
-
r.scan_each(:match => "key:1?") {|key|
|
105
|
-
keys_from_scan << key
|
106
|
-
}
|
107
|
-
|
108
|
-
all_keys = r.keys "key:1?"
|
109
|
-
|
110
|
-
assert all_keys.sort == keys_from_scan.uniq.sort
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
def test_sscan_with_encoding
|
115
|
-
target_version "2.7.105" do
|
116
|
-
[:intset, :hashtable].each do |enc|
|
117
|
-
r.del "set"
|
118
|
-
|
119
|
-
prefix = ""
|
120
|
-
prefix = "ele:" if enc == :hashtable
|
121
|
-
|
122
|
-
elements = []
|
123
|
-
100.times { |j| elements << "#{prefix}#{j}" }
|
124
|
-
|
125
|
-
r.sadd "set", elements
|
126
|
-
|
127
|
-
assert_equal enc.to_s, r.object("encoding", "set")
|
128
|
-
|
129
|
-
cursor = 0
|
130
|
-
all_keys = []
|
131
|
-
loop {
|
132
|
-
cursor, keys = r.sscan "set", cursor
|
133
|
-
all_keys += keys
|
134
|
-
break if cursor == "0"
|
135
|
-
}
|
136
|
-
|
137
|
-
assert_equal 100, all_keys.uniq.size
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
def test_sscan_each_enumerator
|
143
|
-
target_version "2.7.105" do
|
144
|
-
elements = []
|
145
|
-
100.times { |j| elements << "ele:#{j}" }
|
146
|
-
r.sadd "set", elements
|
147
|
-
|
148
|
-
scan_enumerator = r.sscan_each("set")
|
149
|
-
assert_equal true, scan_enumerator.is_a?(::Enumerator)
|
150
|
-
|
151
|
-
keys_from_scan = scan_enumerator.to_a.uniq
|
152
|
-
all_keys = r.smembers("set")
|
153
|
-
|
154
|
-
assert all_keys.sort == keys_from_scan.sort
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
def test_sscan_each_enumerator_match
|
159
|
-
target_version "2.7.105" do
|
160
|
-
elements = []
|
161
|
-
100.times { |j| elements << "ele:#{j}" }
|
162
|
-
r.sadd "set", elements
|
163
|
-
|
164
|
-
keys_from_scan = r.sscan_each("set", :match => "ele:1?").to_a.uniq
|
165
|
-
|
166
|
-
all_keys = r.smembers("set").grep(/^ele:1.$/)
|
167
|
-
|
168
|
-
assert all_keys.sort == keys_from_scan.sort
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
def test_sscan_each_enumerator_block
|
173
|
-
target_version "2.7.105" do
|
174
|
-
elements = []
|
175
|
-
100.times { |j| elements << "ele:#{j}" }
|
176
|
-
r.sadd "set", elements
|
177
|
-
|
178
|
-
keys_from_scan = []
|
179
|
-
r.sscan_each("set") do |key|
|
180
|
-
keys_from_scan << key
|
181
|
-
end
|
182
|
-
|
183
|
-
all_keys = r.smembers("set")
|
184
|
-
|
185
|
-
assert all_keys.sort == keys_from_scan.uniq.sort
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
def test_sscan_each_enumerator_block_match
|
190
|
-
target_version "2.7.105" do
|
191
|
-
elements = []
|
192
|
-
100.times { |j| elements << "ele:#{j}" }
|
193
|
-
r.sadd "set", elements
|
194
|
-
|
195
|
-
keys_from_scan = []
|
196
|
-
r.sscan_each("set", :match => "ele:1?") do |key|
|
197
|
-
keys_from_scan << key
|
198
|
-
end
|
199
|
-
|
200
|
-
all_keys = r.smembers("set").grep(/^ele:1.$/)
|
201
|
-
|
202
|
-
assert all_keys.sort == keys_from_scan.uniq.sort
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
def test_hscan_with_encoding
|
207
|
-
target_version "2.7.105" do
|
208
|
-
[:ziplist, :hashtable].each do |enc|
|
209
|
-
r.del "set"
|
210
|
-
|
211
|
-
count = 1000
|
212
|
-
count = 30 if enc == :ziplist
|
213
|
-
|
214
|
-
elements = []
|
215
|
-
count.times { |j| elements << "key:#{j}" << j.to_s }
|
216
|
-
|
217
|
-
r.hmset "hash", *elements
|
218
|
-
|
219
|
-
assert_equal enc.to_s, r.object("encoding", "hash")
|
220
|
-
|
221
|
-
cursor = 0
|
222
|
-
all_key_values = []
|
223
|
-
loop {
|
224
|
-
cursor, key_values = r.hscan "hash", cursor
|
225
|
-
all_key_values.concat key_values
|
226
|
-
break if cursor == "0"
|
227
|
-
}
|
228
|
-
|
229
|
-
keys2 = []
|
230
|
-
all_key_values.each do |k, v|
|
231
|
-
assert_equal "key:#{v}", k
|
232
|
-
keys2 << k
|
233
|
-
end
|
234
|
-
|
235
|
-
assert_equal count, keys2.uniq.size
|
236
|
-
end
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
def test_hscan_each_enumerator
|
241
|
-
target_version "2.7.105" do
|
242
|
-
count = 1000
|
243
|
-
elements = []
|
244
|
-
count.times { |j| elements << "key:#{j}" << j.to_s }
|
245
|
-
r.hmset "hash", *elements
|
246
|
-
|
247
|
-
scan_enumerator = r.hscan_each("hash")
|
248
|
-
assert_equal true, scan_enumerator.is_a?(::Enumerator)
|
249
|
-
|
250
|
-
keys_from_scan = scan_enumerator.to_a.uniq
|
251
|
-
all_keys = r.hgetall("hash").to_a
|
252
|
-
|
253
|
-
assert all_keys.sort == keys_from_scan.sort
|
254
|
-
end
|
255
|
-
end
|
256
|
-
|
257
|
-
def test_hscan_each_enumerator_match
|
258
|
-
target_version "2.7.105" do
|
259
|
-
count = 100
|
260
|
-
elements = []
|
261
|
-
count.times { |j| elements << "key:#{j}" << j.to_s }
|
262
|
-
r.hmset "hash", *elements
|
263
|
-
|
264
|
-
keys_from_scan = r.hscan_each("hash", :match => "key:1?").to_a.uniq
|
265
|
-
all_keys = r.hgetall("hash").to_a.select{|k,v| k =~ /^key:1.$/}
|
266
|
-
|
267
|
-
assert all_keys.sort == keys_from_scan.sort
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
def test_hscan_each_block
|
272
|
-
target_version "2.7.105" do
|
273
|
-
count = 1000
|
274
|
-
elements = []
|
275
|
-
count.times { |j| elements << "key:#{j}" << j.to_s }
|
276
|
-
r.hmset "hash", *elements
|
277
|
-
|
278
|
-
keys_from_scan = []
|
279
|
-
r.hscan_each("hash") do |field, value|
|
280
|
-
keys_from_scan << [field, value]
|
281
|
-
end
|
282
|
-
all_keys = r.hgetall("hash").to_a
|
283
|
-
|
284
|
-
assert all_keys.sort == keys_from_scan.uniq.sort
|
285
|
-
end
|
286
|
-
end
|
287
|
-
|
288
|
-
def test_hscan_each_block_match
|
289
|
-
target_version "2.7.105" do
|
290
|
-
count = 1000
|
291
|
-
elements = []
|
292
|
-
count.times { |j| elements << "key:#{j}" << j.to_s }
|
293
|
-
r.hmset "hash", *elements
|
294
|
-
|
295
|
-
keys_from_scan = []
|
296
|
-
r.hscan_each("hash", :match => "key:1?") do |field, value|
|
297
|
-
keys_from_scan << [field, value]
|
298
|
-
end
|
299
|
-
all_keys = r.hgetall("hash").to_a.select{|k,v| k =~ /^key:1.$/}
|
300
|
-
|
301
|
-
assert all_keys.sort == keys_from_scan.uniq.sort
|
302
|
-
end
|
303
|
-
end
|
304
|
-
|
305
|
-
def test_zscan_with_encoding
|
306
|
-
target_version "2.7.105" do
|
307
|
-
[:ziplist, :skiplist].each do |enc|
|
308
|
-
r.del "zset"
|
309
|
-
|
310
|
-
count = 1000
|
311
|
-
count = 30 if enc == :ziplist
|
312
|
-
|
313
|
-
elements = []
|
314
|
-
count.times { |j| elements << j << "key:#{j}" }
|
315
|
-
|
316
|
-
r.zadd "zset", elements
|
317
|
-
|
318
|
-
assert_equal enc.to_s, r.object("encoding", "zset")
|
319
|
-
|
320
|
-
cursor = 0
|
321
|
-
all_key_scores = []
|
322
|
-
loop {
|
323
|
-
cursor, key_scores = r.zscan "zset", cursor
|
324
|
-
all_key_scores.concat key_scores
|
325
|
-
break if cursor == "0"
|
326
|
-
}
|
327
|
-
|
328
|
-
keys2 = []
|
329
|
-
all_key_scores.each do |k, v|
|
330
|
-
assert_equal true, v.is_a?(Float)
|
331
|
-
assert_equal "key:#{Integer(v)}", k
|
332
|
-
keys2 << k
|
333
|
-
end
|
334
|
-
|
335
|
-
assert_equal count, keys2.uniq.size
|
336
|
-
end
|
337
|
-
end
|
338
|
-
end
|
339
|
-
|
340
|
-
def test_zscan_each_enumerator
|
341
|
-
target_version "2.7.105" do
|
342
|
-
count = 1000
|
343
|
-
elements = []
|
344
|
-
count.times { |j| elements << j << "key:#{j}" }
|
345
|
-
r.zadd "zset", elements
|
346
|
-
|
347
|
-
scan_enumerator = r.zscan_each "zset"
|
348
|
-
assert_equal true, scan_enumerator.is_a?(::Enumerator)
|
349
|
-
|
350
|
-
scores_from_scan = scan_enumerator.to_a.uniq
|
351
|
-
member_scores = r.zrange("zset", 0, -1, :with_scores => true)
|
352
|
-
|
353
|
-
assert member_scores.sort == scores_from_scan.sort
|
354
|
-
end
|
355
|
-
end
|
356
|
-
|
357
|
-
def test_zscan_each_enumerator_match
|
358
|
-
target_version "2.7.105" do
|
359
|
-
count = 1000
|
360
|
-
elements = []
|
361
|
-
count.times { |j| elements << j << "key:#{j}" }
|
362
|
-
r.zadd "zset", elements
|
363
|
-
|
364
|
-
scores_from_scan = r.zscan_each("zset", :match => "key:1??").to_a.uniq
|
365
|
-
member_scores = r.zrange("zset", 0, -1, :with_scores => true)
|
366
|
-
filtered_members = member_scores.select{|k,s| k =~ /^key:1..$/}
|
367
|
-
|
368
|
-
assert filtered_members.sort == scores_from_scan.sort
|
369
|
-
end
|
370
|
-
end
|
371
|
-
|
372
|
-
def test_zscan_each_block
|
373
|
-
target_version "2.7.105" do
|
374
|
-
count = 1000
|
375
|
-
elements = []
|
376
|
-
count.times { |j| elements << j << "key:#{j}" }
|
377
|
-
r.zadd "zset", elements
|
378
|
-
|
379
|
-
scores_from_scan = []
|
380
|
-
r.zscan_each("zset") do |member, score|
|
381
|
-
scores_from_scan << [member, score]
|
382
|
-
end
|
383
|
-
member_scores = r.zrange("zset", 0, -1, :with_scores => true)
|
384
|
-
|
385
|
-
assert member_scores.sort == scores_from_scan.sort
|
386
|
-
end
|
387
|
-
end
|
388
|
-
|
389
|
-
def test_zscan_each_block_match
|
390
|
-
target_version "2.7.105" do
|
391
|
-
count = 1000
|
392
|
-
elements = []
|
393
|
-
count.times { |j| elements << j << "key:#{j}" }
|
394
|
-
r.zadd "zset", elements
|
395
|
-
|
396
|
-
scores_from_scan = []
|
397
|
-
r.zscan_each("zset", :match => "key:1??") do |member, score|
|
398
|
-
scores_from_scan << [member, score]
|
399
|
-
end
|
400
|
-
member_scores = r.zrange("zset", 0, -1, :with_scores => true)
|
401
|
-
filtered_members = member_scores.select{|k,s| k =~ /^key:1..$/}
|
402
|
-
|
403
|
-
assert filtered_members.sort == scores_from_scan.sort
|
404
|
-
end
|
405
|
-
end
|
406
|
-
|
407
|
-
end
|