redis 4.0.3 → 4.5.0

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.
Files changed (157) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +110 -0
  3. data/README.md +126 -17
  4. data/lib/redis/client.rb +130 -82
  5. data/lib/redis/cluster/command_loader.rb +8 -7
  6. data/lib/redis/cluster/node.rb +5 -1
  7. data/lib/redis/cluster/node_key.rb +3 -7
  8. data/lib/redis/cluster/node_loader.rb +2 -0
  9. data/lib/redis/cluster/option.rb +31 -14
  10. data/lib/redis/cluster/slot.rb +30 -13
  11. data/lib/redis/cluster/slot_loader.rb +6 -4
  12. data/lib/redis/cluster.rb +23 -17
  13. data/lib/redis/connection/command_helper.rb +5 -2
  14. data/lib/redis/connection/hiredis.rb +4 -3
  15. data/lib/redis/connection/registry.rb +2 -1
  16. data/lib/redis/connection/ruby.rb +139 -106
  17. data/lib/redis/connection/synchrony.rb +9 -4
  18. data/lib/redis/connection.rb +2 -0
  19. data/lib/redis/distributed.rb +171 -70
  20. data/lib/redis/errors.rb +2 -0
  21. data/lib/redis/hash_ring.rb +15 -14
  22. data/lib/redis/pipeline.rb +46 -8
  23. data/lib/redis/subscribe.rb +11 -12
  24. data/lib/redis/version.rb +3 -1
  25. data/lib/redis.rb +1239 -426
  26. metadata +16 -262
  27. data/.gitignore +0 -19
  28. data/.travis/Gemfile +0 -18
  29. data/.travis.yml +0 -61
  30. data/.yardopts +0 -3
  31. data/Gemfile +0 -8
  32. data/benchmarking/logging.rb +0 -71
  33. data/benchmarking/pipeline.rb +0 -51
  34. data/benchmarking/speed.rb +0 -21
  35. data/benchmarking/suite.rb +0 -24
  36. data/benchmarking/worker.rb +0 -71
  37. data/bin/build +0 -71
  38. data/bors.toml +0 -14
  39. data/examples/basic.rb +0 -15
  40. data/examples/consistency.rb +0 -114
  41. data/examples/dist_redis.rb +0 -43
  42. data/examples/incr-decr.rb +0 -17
  43. data/examples/list.rb +0 -26
  44. data/examples/pubsub.rb +0 -37
  45. data/examples/sentinel/sentinel.conf +0 -9
  46. data/examples/sentinel/start +0 -49
  47. data/examples/sentinel.rb +0 -41
  48. data/examples/sets.rb +0 -36
  49. data/examples/unicorn/config.ru +0 -3
  50. data/examples/unicorn/unicorn.rb +0 -20
  51. data/makefile +0 -74
  52. data/redis.gemspec +0 -43
  53. data/test/bitpos_test.rb +0 -63
  54. data/test/blocking_commands_test.rb +0 -40
  55. data/test/client_test.rb +0 -76
  56. data/test/cluster_abnormal_state_test.rb +0 -38
  57. data/test/cluster_blocking_commands_test.rb +0 -15
  58. data/test/cluster_client_internals_test.rb +0 -77
  59. data/test/cluster_client_key_hash_tags_test.rb +0 -88
  60. data/test/cluster_client_options_test.rb +0 -147
  61. data/test/cluster_client_pipelining_test.rb +0 -59
  62. data/test/cluster_client_replicas_test.rb +0 -36
  63. data/test/cluster_client_slots_test.rb +0 -94
  64. data/test/cluster_client_transactions_test.rb +0 -71
  65. data/test/cluster_commands_on_cluster_test.rb +0 -165
  66. data/test/cluster_commands_on_connection_test.rb +0 -40
  67. data/test/cluster_commands_on_geo_test.rb +0 -74
  68. data/test/cluster_commands_on_hashes_test.rb +0 -11
  69. data/test/cluster_commands_on_hyper_log_log_test.rb +0 -17
  70. data/test/cluster_commands_on_keys_test.rb +0 -134
  71. data/test/cluster_commands_on_lists_test.rb +0 -15
  72. data/test/cluster_commands_on_pub_sub_test.rb +0 -101
  73. data/test/cluster_commands_on_scripting_test.rb +0 -56
  74. data/test/cluster_commands_on_server_test.rb +0 -221
  75. data/test/cluster_commands_on_sets_test.rb +0 -39
  76. data/test/cluster_commands_on_sorted_sets_test.rb +0 -35
  77. data/test/cluster_commands_on_streams_test.rb +0 -196
  78. data/test/cluster_commands_on_strings_test.rb +0 -15
  79. data/test/cluster_commands_on_transactions_test.rb +0 -41
  80. data/test/cluster_commands_on_value_types_test.rb +0 -14
  81. data/test/command_map_test.rb +0 -28
  82. data/test/commands_on_geo_test.rb +0 -116
  83. data/test/commands_on_hashes_test.rb +0 -7
  84. data/test/commands_on_hyper_log_log_test.rb +0 -7
  85. data/test/commands_on_lists_test.rb +0 -7
  86. data/test/commands_on_sets_test.rb +0 -7
  87. data/test/commands_on_sorted_sets_test.rb +0 -7
  88. data/test/commands_on_strings_test.rb +0 -7
  89. data/test/commands_on_value_types_test.rb +0 -207
  90. data/test/connection_handling_test.rb +0 -275
  91. data/test/connection_test.rb +0 -57
  92. data/test/db/.gitkeep +0 -0
  93. data/test/distributed_blocking_commands_test.rb +0 -52
  94. data/test/distributed_commands_on_hashes_test.rb +0 -21
  95. data/test/distributed_commands_on_hyper_log_log_test.rb +0 -26
  96. data/test/distributed_commands_on_lists_test.rb +0 -19
  97. data/test/distributed_commands_on_sets_test.rb +0 -105
  98. data/test/distributed_commands_on_sorted_sets_test.rb +0 -59
  99. data/test/distributed_commands_on_strings_test.rb +0 -79
  100. data/test/distributed_commands_on_value_types_test.rb +0 -129
  101. data/test/distributed_commands_requiring_clustering_test.rb +0 -162
  102. data/test/distributed_connection_handling_test.rb +0 -21
  103. data/test/distributed_internals_test.rb +0 -68
  104. data/test/distributed_key_tags_test.rb +0 -50
  105. data/test/distributed_persistence_control_commands_test.rb +0 -24
  106. data/test/distributed_publish_subscribe_test.rb +0 -90
  107. data/test/distributed_remote_server_control_commands_test.rb +0 -64
  108. data/test/distributed_scripting_test.rb +0 -100
  109. data/test/distributed_sorting_test.rb +0 -18
  110. data/test/distributed_test.rb +0 -56
  111. data/test/distributed_transactions_test.rb +0 -30
  112. data/test/encoding_test.rb +0 -14
  113. data/test/error_replies_test.rb +0 -57
  114. data/test/fork_safety_test.rb +0 -60
  115. data/test/helper.rb +0 -345
  116. data/test/helper_test.rb +0 -22
  117. data/test/internals_test.rb +0 -408
  118. data/test/lint/blocking_commands.rb +0 -174
  119. data/test/lint/hashes.rb +0 -203
  120. data/test/lint/hyper_log_log.rb +0 -74
  121. data/test/lint/lists.rb +0 -159
  122. data/test/lint/sets.rb +0 -282
  123. data/test/lint/sorted_sets.rb +0 -497
  124. data/test/lint/strings.rb +0 -348
  125. data/test/lint/value_types.rb +0 -130
  126. data/test/persistence_control_commands_test.rb +0 -24
  127. data/test/pipelining_commands_test.rb +0 -246
  128. data/test/publish_subscribe_test.rb +0 -280
  129. data/test/remote_server_control_commands_test.rb +0 -175
  130. data/test/scanning_test.rb +0 -407
  131. data/test/scripting_test.rb +0 -76
  132. data/test/sentinel_command_test.rb +0 -78
  133. data/test/sentinel_test.rb +0 -253
  134. data/test/sorting_test.rb +0 -57
  135. data/test/ssl_test.rb +0 -69
  136. data/test/support/cluster/orchestrator.rb +0 -199
  137. data/test/support/connection/hiredis.rb +0 -1
  138. data/test/support/connection/ruby.rb +0 -1
  139. data/test/support/connection/synchrony.rb +0 -17
  140. data/test/support/redis_mock.rb +0 -130
  141. data/test/support/ssl/gen_certs.sh +0 -31
  142. data/test/support/ssl/trusted-ca.crt +0 -25
  143. data/test/support/ssl/trusted-ca.key +0 -27
  144. data/test/support/ssl/trusted-cert.crt +0 -81
  145. data/test/support/ssl/trusted-cert.key +0 -28
  146. data/test/support/ssl/untrusted-ca.crt +0 -26
  147. data/test/support/ssl/untrusted-ca.key +0 -27
  148. data/test/support/ssl/untrusted-cert.crt +0 -82
  149. data/test/support/ssl/untrusted-cert.key +0 -28
  150. data/test/support/wire/synchrony.rb +0 -24
  151. data/test/support/wire/thread.rb +0 -5
  152. data/test/synchrony_driver.rb +0 -85
  153. data/test/test.conf.erb +0 -9
  154. data/test/thread_safety_test.rb +0 -60
  155. data/test/transactions_test.rb +0 -272
  156. data/test/unknown_commands_test.rb +0 -12
  157. data/test/url_param_test.rb +0 -136
data/test/lint/hashes.rb DELETED
@@ -1,203 +0,0 @@
1
- module Lint
2
-
3
- module Hashes
4
-
5
- def test_hset_and_hget
6
- r.hset("foo", "f1", "s1")
7
-
8
- assert_equal "s1", r.hget("foo", "f1")
9
- end
10
-
11
- def test_hsetnx
12
- r.hset("foo", "f1", "s1")
13
- r.hsetnx("foo", "f1", "s2")
14
-
15
- assert_equal "s1", r.hget("foo", "f1")
16
-
17
- r.del("foo")
18
- r.hsetnx("foo", "f1", "s2")
19
-
20
- assert_equal "s2", r.hget("foo", "f1")
21
- end
22
-
23
- def test_hdel
24
- r.hset("foo", "f1", "s1")
25
-
26
- assert_equal "s1", r.hget("foo", "f1")
27
-
28
- assert_equal 1, r.hdel("foo", "f1")
29
-
30
- assert_equal nil, r.hget("foo", "f1")
31
- end
32
-
33
- def test_splat_hdel
34
- target_version "2.3.9" do
35
- r.hset("foo", "f1", "s1")
36
- r.hset("foo", "f2", "s2")
37
-
38
- assert_equal "s1", r.hget("foo", "f1")
39
- assert_equal "s2", r.hget("foo", "f2")
40
-
41
- assert_equal 2, r.hdel("foo", "f1", "f2")
42
-
43
- assert_equal nil, r.hget("foo", "f1")
44
- assert_equal nil, r.hget("foo", "f2")
45
- end
46
- end
47
-
48
- def test_variadic_hdel
49
- target_version "2.3.9" do
50
- r.hset("foo", "f1", "s1")
51
- r.hset("foo", "f2", "s2")
52
-
53
- assert_equal "s1", r.hget("foo", "f1")
54
- assert_equal "s2", r.hget("foo", "f2")
55
-
56
- assert_equal 2, r.hdel("foo", ["f1", "f2"])
57
-
58
- assert_equal nil, r.hget("foo", "f1")
59
- assert_equal nil, r.hget("foo", "f2")
60
- end
61
- end
62
-
63
- def test_hexists
64
- assert_equal false, r.hexists("foo", "f1")
65
-
66
- r.hset("foo", "f1", "s1")
67
-
68
- assert r.hexists("foo", "f1")
69
- end
70
-
71
- def test_hlen
72
- assert_equal 0, r.hlen("foo")
73
-
74
- r.hset("foo", "f1", "s1")
75
-
76
- assert_equal 1, r.hlen("foo")
77
-
78
- r.hset("foo", "f2", "s2")
79
-
80
- assert_equal 2, r.hlen("foo")
81
- end
82
-
83
- def test_hkeys
84
- assert_equal [], r.hkeys("foo")
85
-
86
- r.hset("foo", "f1", "s1")
87
- r.hset("foo", "f2", "s2")
88
-
89
- assert_equal ["f1", "f2"], r.hkeys("foo")
90
- end
91
-
92
- def test_hvals
93
- assert_equal [], r.hvals("foo")
94
-
95
- r.hset("foo", "f1", "s1")
96
- r.hset("foo", "f2", "s2")
97
-
98
- assert_equal ["s1", "s2"], r.hvals("foo")
99
- end
100
-
101
- def test_hgetall
102
- assert({} == r.hgetall("foo"))
103
-
104
- r.hset("foo", "f1", "s1")
105
- r.hset("foo", "f2", "s2")
106
-
107
- assert({"f1" => "s1", "f2" => "s2"} == r.hgetall("foo"))
108
- end
109
-
110
- def test_hmset
111
- r.hmset("hash", "foo1", "bar1", "foo2", "bar2")
112
-
113
- assert_equal "bar1", r.hget("hash", "foo1")
114
- assert_equal "bar2", r.hget("hash", "foo2")
115
- end
116
-
117
- def test_hmset_with_invalid_arguments
118
- assert_raise(Redis::CommandError) do
119
- r.hmset("hash", "foo1", "bar1", "foo2", "bar2", "foo3")
120
- end
121
- end
122
-
123
- def test_mapped_hmset
124
- r.mapped_hmset("foo", :f1 => "s1", :f2 => "s2")
125
-
126
- assert_equal "s1", r.hget("foo", "f1")
127
- assert_equal "s2", r.hget("foo", "f2")
128
- end
129
-
130
- def test_hmget
131
- r.hset("foo", "f1", "s1")
132
- r.hset("foo", "f2", "s2")
133
- r.hset("foo", "f3", "s3")
134
-
135
- assert_equal ["s2", "s3"], r.hmget("foo", "f2", "f3")
136
- end
137
-
138
- def test_hmget_mapped
139
- r.hset("foo", "f1", "s1")
140
- r.hset("foo", "f2", "s2")
141
- r.hset("foo", "f3", "s3")
142
-
143
- assert({"f1" => "s1"} == r.mapped_hmget("foo", "f1"))
144
- assert({"f1" => "s1", "f2" => "s2"} == r.mapped_hmget("foo", "f1", "f2"))
145
- end
146
-
147
- def test_mapped_hmget_in_a_pipeline_returns_hash
148
- r.hset("foo", "f1", "s1")
149
- r.hset("foo", "f2", "s2")
150
-
151
- result = r.pipelined do
152
- r.mapped_hmget("foo", "f1", "f2")
153
- end
154
-
155
- assert_equal result[0], { "f1" => "s1", "f2" => "s2" }
156
- end
157
-
158
- def test_hincrby
159
- r.hincrby("foo", "f1", 1)
160
-
161
- assert_equal "1", r.hget("foo", "f1")
162
-
163
- r.hincrby("foo", "f1", 2)
164
-
165
- assert_equal "3", r.hget("foo", "f1")
166
-
167
- r.hincrby("foo", "f1", -1)
168
-
169
- assert_equal "2", r.hget("foo", "f1")
170
- end
171
-
172
- def test_hincrbyfloat
173
- target_version "2.5.4" do
174
- r.hincrbyfloat("foo", "f1", 1.23)
175
-
176
- assert_equal "1.23", r.hget("foo", "f1")
177
-
178
- r.hincrbyfloat("foo", "f1", 0.77)
179
-
180
- assert_equal "2", r.hget("foo", "f1")
181
-
182
- r.hincrbyfloat("foo", "f1", -0.1)
183
-
184
- assert_equal "1.9", r.hget("foo", "f1")
185
- end
186
- end
187
-
188
- def test_hstrlen
189
- target_version('3.2.0') do
190
- redis.hmset('foo', 'f1', 'HelloWorld', 'f2', 99, 'f3', -256)
191
- assert_equal 10, r.hstrlen('foo', 'f1')
192
- assert_equal 2, r.hstrlen('foo', 'f2')
193
- assert_equal 4, r.hstrlen('foo', 'f3')
194
- end
195
- end
196
-
197
- def test_hscan
198
- redis.hmset('foo', 'f1', 'Jack', 'f2', 33)
199
- expected = ['0', [%w[f1 Jack], %w[f2 33]]]
200
- assert_equal expected, redis.hscan('foo', 0)
201
- end
202
- end
203
- end
@@ -1,74 +0,0 @@
1
- module Lint
2
-
3
- module HyperLogLog
4
-
5
- def test_pfadd
6
- target_version "2.8.9" do
7
- assert_equal true, r.pfadd("foo", "s1")
8
- assert_equal true, r.pfadd("foo", "s2")
9
- assert_equal false, r.pfadd("foo", "s1")
10
-
11
- assert_equal 2, r.pfcount("foo")
12
- end
13
- end
14
-
15
- def test_variadic_pfadd
16
- target_version "2.8.9" do
17
- assert_equal true, r.pfadd("foo", ["s1", "s2"])
18
- assert_equal true, r.pfadd("foo", ["s1", "s2", "s3"])
19
-
20
- assert_equal 3, r.pfcount("foo")
21
- end
22
- end
23
-
24
- def test_pfcount
25
- target_version "2.8.9" do
26
- assert_equal 0, r.pfcount("foo")
27
-
28
- assert_equal true, r.pfadd("foo", "s1")
29
-
30
- assert_equal 1, r.pfcount("foo")
31
- end
32
- end
33
-
34
- def test_variadic_pfcount
35
- target_version "2.8.9" do
36
- assert_equal 0, r.pfcount(["{1}foo", "{1}bar"])
37
-
38
- assert_equal true, r.pfadd("{1}foo", "s1")
39
- assert_equal true, r.pfadd("{1}bar", "s1")
40
- assert_equal true, r.pfadd("{1}bar", "s2")
41
-
42
- assert_equal 2, r.pfcount("{1}foo", "{1}bar")
43
- end
44
- end
45
-
46
- def test_variadic_pfcount_expanded
47
- target_version "2.8.9" do
48
- assert_equal 0, r.pfcount("{1}foo", "{1}bar")
49
-
50
- assert_equal true, r.pfadd("{1}foo", "s1")
51
- assert_equal true, r.pfadd("{1}bar", "s1")
52
- assert_equal true, r.pfadd("{1}bar", "s2")
53
-
54
- assert_equal 2, r.pfcount("{1}foo", "{1}bar")
55
- end
56
- end
57
-
58
- def test_pfmerge
59
- target_version '2.8.9' do
60
- r.pfadd 'foo', 's1'
61
- r.pfadd 'bar', 's2'
62
-
63
- assert_equal true, r.pfmerge('res', 'foo', 'bar')
64
- assert_equal 2, r.pfcount('res')
65
- end
66
- end
67
-
68
- def test_variadic_pfmerge_expanded
69
- redis.pfadd('{1}foo', %w[foo bar zap a])
70
- redis.pfadd('{1}bar', %w[a b c foo])
71
- assert_equal true, redis.pfmerge('{1}baz', '{1}foo', '{1}bar')
72
- end
73
- end
74
- end
data/test/lint/lists.rb DELETED
@@ -1,159 +0,0 @@
1
- module Lint
2
-
3
- module Lists
4
-
5
- def test_lpush
6
- r.lpush "foo", "s1"
7
- r.lpush "foo", "s2"
8
-
9
- assert_equal 2, r.llen("foo")
10
- assert_equal "s2", r.lpop("foo")
11
- end
12
-
13
- def test_variadic_lpush
14
- target_version "2.3.9" do # 2.4-rc6
15
- assert_equal 3, r.lpush("foo", ["s1", "s2", "s3"])
16
- assert_equal 3, r.llen("foo")
17
- assert_equal "s3", r.lpop("foo")
18
- end
19
- end
20
-
21
- def test_lpushx
22
- r.lpushx "foo", "s1"
23
- r.lpush "foo", "s2"
24
- r.lpushx "foo", "s3"
25
-
26
- assert_equal 2, r.llen("foo")
27
- assert_equal ["s3", "s2"], r.lrange("foo", 0, -1)
28
- end
29
-
30
- def test_rpush
31
- r.rpush "foo", "s1"
32
- r.rpush "foo", "s2"
33
-
34
- assert_equal 2, r.llen("foo")
35
- assert_equal "s2", r.rpop("foo")
36
- end
37
-
38
- def test_variadic_rpush
39
- target_version "2.3.9" do # 2.4-rc6
40
- assert_equal 3, r.rpush("foo", ["s1", "s2", "s3"])
41
- assert_equal 3, r.llen("foo")
42
- assert_equal "s3", r.rpop("foo")
43
- end
44
- end
45
-
46
- def test_rpushx
47
- r.rpushx "foo", "s1"
48
- r.rpush "foo", "s2"
49
- r.rpushx "foo", "s3"
50
-
51
- assert_equal 2, r.llen("foo")
52
- assert_equal ["s2", "s3"], r.lrange("foo", 0, -1)
53
- end
54
-
55
- def test_llen
56
- r.rpush "foo", "s1"
57
- r.rpush "foo", "s2"
58
-
59
- assert_equal 2, r.llen("foo")
60
- end
61
-
62
- def test_lrange
63
- r.rpush "foo", "s1"
64
- r.rpush "foo", "s2"
65
- r.rpush "foo", "s3"
66
-
67
- assert_equal ["s2", "s3"], r.lrange("foo", 1, -1)
68
- assert_equal ["s1", "s2"], r.lrange("foo", 0, 1)
69
-
70
- assert_equal [], r.lrange("bar", 0, -1)
71
- end
72
-
73
- def test_ltrim
74
- r.rpush "foo", "s1"
75
- r.rpush "foo", "s2"
76
- r.rpush "foo", "s3"
77
-
78
- r.ltrim "foo", 0, 1
79
-
80
- assert_equal 2, r.llen("foo")
81
- assert_equal ["s1", "s2"], r.lrange("foo", 0, -1)
82
- end
83
-
84
- def test_lindex
85
- r.rpush "foo", "s1"
86
- r.rpush "foo", "s2"
87
-
88
- assert_equal "s1", r.lindex("foo", 0)
89
- assert_equal "s2", r.lindex("foo", 1)
90
- end
91
-
92
- def test_lset
93
- r.rpush "foo", "s1"
94
- r.rpush "foo", "s2"
95
-
96
- assert_equal "s2", r.lindex("foo", 1)
97
- assert r.lset("foo", 1, "s3")
98
- assert_equal "s3", r.lindex("foo", 1)
99
-
100
- assert_raise Redis::CommandError do
101
- r.lset("foo", 4, "s3")
102
- end
103
- end
104
-
105
- def test_lrem
106
- r.rpush "foo", "s1"
107
- r.rpush "foo", "s2"
108
-
109
- assert_equal 1, r.lrem("foo", 1, "s1")
110
- assert_equal ["s2"], r.lrange("foo", 0, -1)
111
- end
112
-
113
- def test_lpop
114
- r.rpush "foo", "s1"
115
- r.rpush "foo", "s2"
116
-
117
- assert_equal 2, r.llen("foo")
118
- assert_equal "s1", r.lpop("foo")
119
- assert_equal 1, r.llen("foo")
120
- end
121
-
122
- def test_rpop
123
- r.rpush "foo", "s1"
124
- r.rpush "foo", "s2"
125
-
126
- assert_equal 2, r.llen("foo")
127
- assert_equal "s2", r.rpop("foo")
128
- assert_equal 1, r.llen("foo")
129
- end
130
-
131
- def test_linsert
132
- r.rpush "foo", "s1"
133
- r.rpush "foo", "s3"
134
- r.linsert "foo", :before, "s3", "s2"
135
-
136
- assert_equal ["s1", "s2", "s3"], r.lrange("foo", 0, -1)
137
-
138
- assert_raise(Redis::CommandError) do
139
- r.linsert "foo", :anywhere, "s3", "s2"
140
- end
141
- end
142
-
143
- def test_rpoplpush
144
- r.rpush 'foo', 's1'
145
- r.rpush 'foo', 's2'
146
-
147
- assert_equal 's2', r.rpoplpush('foo', 'bar')
148
- assert_equal ['s2'], r.lrange('bar', 0, -1)
149
- assert_equal 's1', r.rpoplpush('foo', 'bar')
150
- assert_equal %w[s1 s2], r.lrange('bar', 0, -1)
151
- end
152
-
153
- def test_variadic_rpoplpush_expand
154
- redis.rpush('{1}foo', %w[a b c])
155
- redis.rpush('{1}bar', %w[d e f])
156
- assert_equal 'c', redis.rpoplpush('{1}foo', '{1}bar')
157
- end
158
- end
159
- end