redis 3.3.5 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +54 -2
  3. data/README.md +77 -76
  4. data/lib/redis.rb +779 -63
  5. data/lib/redis/client.rb +41 -20
  6. data/lib/redis/cluster.rb +286 -0
  7. data/lib/redis/cluster/command.rb +81 -0
  8. data/lib/redis/cluster/command_loader.rb +34 -0
  9. data/lib/redis/cluster/key_slot_converter.rb +72 -0
  10. data/lib/redis/cluster/node.rb +104 -0
  11. data/lib/redis/cluster/node_key.rb +35 -0
  12. data/lib/redis/cluster/node_loader.rb +37 -0
  13. data/lib/redis/cluster/option.rb +77 -0
  14. data/lib/redis/cluster/slot.rb +69 -0
  15. data/lib/redis/cluster/slot_loader.rb +49 -0
  16. data/lib/redis/connection.rb +2 -2
  17. data/lib/redis/connection/command_helper.rb +2 -8
  18. data/lib/redis/connection/hiredis.rb +2 -2
  19. data/lib/redis/connection/ruby.rb +13 -30
  20. data/lib/redis/connection/synchrony.rb +12 -4
  21. data/lib/redis/distributed.rb +32 -12
  22. data/lib/redis/errors.rb +46 -0
  23. data/lib/redis/hash_ring.rb +20 -64
  24. data/lib/redis/pipeline.rb +9 -7
  25. data/lib/redis/version.rb +1 -1
  26. metadata +53 -196
  27. data/.gitignore +0 -16
  28. data/.travis.yml +0 -89
  29. data/.travis/Gemfile +0 -11
  30. data/.yardopts +0 -3
  31. data/Gemfile +0 -4
  32. data/Rakefile +0 -87
  33. data/benchmarking/logging.rb +0 -71
  34. data/benchmarking/pipeline.rb +0 -51
  35. data/benchmarking/speed.rb +0 -21
  36. data/benchmarking/suite.rb +0 -24
  37. data/benchmarking/worker.rb +0 -71
  38. data/examples/basic.rb +0 -15
  39. data/examples/consistency.rb +0 -114
  40. data/examples/dist_redis.rb +0 -43
  41. data/examples/incr-decr.rb +0 -17
  42. data/examples/list.rb +0 -26
  43. data/examples/pubsub.rb +0 -37
  44. data/examples/sentinel.rb +0 -41
  45. data/examples/sentinel/start +0 -49
  46. data/examples/sets.rb +0 -36
  47. data/examples/unicorn/config.ru +0 -3
  48. data/examples/unicorn/unicorn.rb +0 -20
  49. data/redis.gemspec +0 -44
  50. data/test/bitpos_test.rb +0 -69
  51. data/test/blocking_commands_test.rb +0 -42
  52. data/test/client_test.rb +0 -59
  53. data/test/command_map_test.rb +0 -30
  54. data/test/commands_on_hashes_test.rb +0 -21
  55. data/test/commands_on_hyper_log_log_test.rb +0 -21
  56. data/test/commands_on_lists_test.rb +0 -20
  57. data/test/commands_on_sets_test.rb +0 -77
  58. data/test/commands_on_sorted_sets_test.rb +0 -137
  59. data/test/commands_on_strings_test.rb +0 -101
  60. data/test/commands_on_value_types_test.rb +0 -133
  61. data/test/connection_handling_test.rb +0 -277
  62. data/test/connection_test.rb +0 -57
  63. data/test/distributed_blocking_commands_test.rb +0 -46
  64. data/test/distributed_commands_on_hashes_test.rb +0 -10
  65. data/test/distributed_commands_on_hyper_log_log_test.rb +0 -33
  66. data/test/distributed_commands_on_lists_test.rb +0 -22
  67. data/test/distributed_commands_on_sets_test.rb +0 -83
  68. data/test/distributed_commands_on_sorted_sets_test.rb +0 -18
  69. data/test/distributed_commands_on_strings_test.rb +0 -59
  70. data/test/distributed_commands_on_value_types_test.rb +0 -95
  71. data/test/distributed_commands_requiring_clustering_test.rb +0 -164
  72. data/test/distributed_connection_handling_test.rb +0 -23
  73. data/test/distributed_internals_test.rb +0 -79
  74. data/test/distributed_key_tags_test.rb +0 -52
  75. data/test/distributed_persistence_control_commands_test.rb +0 -26
  76. data/test/distributed_publish_subscribe_test.rb +0 -92
  77. data/test/distributed_remote_server_control_commands_test.rb +0 -66
  78. data/test/distributed_scripting_test.rb +0 -102
  79. data/test/distributed_sorting_test.rb +0 -20
  80. data/test/distributed_test.rb +0 -58
  81. data/test/distributed_transactions_test.rb +0 -32
  82. data/test/encoding_test.rb +0 -18
  83. data/test/error_replies_test.rb +0 -59
  84. data/test/fork_safety_test.rb +0 -65
  85. data/test/helper.rb +0 -232
  86. data/test/helper_test.rb +0 -24
  87. data/test/internals_test.rb +0 -417
  88. data/test/lint/blocking_commands.rb +0 -150
  89. data/test/lint/hashes.rb +0 -162
  90. data/test/lint/hyper_log_log.rb +0 -60
  91. data/test/lint/lists.rb +0 -143
  92. data/test/lint/sets.rb +0 -140
  93. data/test/lint/sorted_sets.rb +0 -316
  94. data/test/lint/strings.rb +0 -260
  95. data/test/lint/value_types.rb +0 -122
  96. data/test/persistence_control_commands_test.rb +0 -26
  97. data/test/pipelining_commands_test.rb +0 -242
  98. data/test/publish_subscribe_test.rb +0 -282
  99. data/test/remote_server_control_commands_test.rb +0 -118
  100. data/test/scanning_test.rb +0 -413
  101. data/test/scripting_test.rb +0 -78
  102. data/test/sentinel_command_test.rb +0 -80
  103. data/test/sentinel_test.rb +0 -255
  104. data/test/sorting_test.rb +0 -59
  105. data/test/ssl_test.rb +0 -73
  106. data/test/support/connection/hiredis.rb +0 -1
  107. data/test/support/connection/ruby.rb +0 -1
  108. data/test/support/connection/synchrony.rb +0 -17
  109. data/test/support/redis_mock.rb +0 -130
  110. data/test/support/ssl/gen_certs.sh +0 -31
  111. data/test/support/ssl/trusted-ca.crt +0 -25
  112. data/test/support/ssl/trusted-ca.key +0 -27
  113. data/test/support/ssl/trusted-cert.crt +0 -81
  114. data/test/support/ssl/trusted-cert.key +0 -28
  115. data/test/support/ssl/untrusted-ca.crt +0 -26
  116. data/test/support/ssl/untrusted-ca.key +0 -27
  117. data/test/support/ssl/untrusted-cert.crt +0 -82
  118. data/test/support/ssl/untrusted-cert.key +0 -28
  119. data/test/support/wire/synchrony.rb +0 -24
  120. data/test/support/wire/thread.rb +0 -5
  121. data/test/synchrony_driver.rb +0 -88
  122. data/test/test.conf.erb +0 -9
  123. data/test/thread_safety_test.rb +0 -62
  124. data/test/transactions_test.rb +0 -264
  125. data/test/unknown_commands_test.rb +0 -14
  126. data/test/url_param_test.rb +0 -138
@@ -1,260 +0,0 @@
1
- module Lint
2
-
3
- module Strings
4
-
5
- def test_set_and_get
6
- r.set("foo", "s1")
7
-
8
- assert_equal "s1", r.get("foo")
9
- end
10
-
11
- def test_set_and_get_with_brackets
12
- r["foo"] = "s1"
13
-
14
- assert_equal "s1", r["foo"]
15
- end
16
-
17
- def test_set_and_get_with_brackets_and_symbol
18
- r[:foo] = "s1"
19
-
20
- assert_equal "s1", r[:foo]
21
- end
22
-
23
- def test_set_and_get_with_newline_characters
24
- r.set("foo", "1\n")
25
-
26
- assert_equal "1\n", r.get("foo")
27
- end
28
-
29
- def test_set_and_get_with_non_string_value
30
- value = ["a", "b"]
31
-
32
- r.set("foo", value)
33
-
34
- assert_equal value.to_s, r.get("foo")
35
- end
36
-
37
- def test_set_and_get_with_ascii_characters
38
- if defined?(Encoding)
39
- with_external_encoding("ASCII-8BIT") do
40
- (0..255).each do |i|
41
- str = "#{i.chr}---#{i.chr}"
42
- r.set("foo", str)
43
-
44
- assert_equal str, r.get("foo")
45
- end
46
- end
47
- end
48
- end
49
-
50
- def test_set_with_ex
51
- target_version "2.6.12" do
52
- r.set("foo", "bar", :ex => 2)
53
- assert_in_range 0..2, r.ttl("foo")
54
- end
55
- end
56
-
57
- def test_set_with_px
58
- target_version "2.6.12" do
59
- r.set("foo", "bar", :px => 2000)
60
- assert_in_range 0..2, r.ttl("foo")
61
- end
62
- end
63
-
64
- def test_set_with_nx
65
- target_version "2.6.12" do
66
- r.set("foo", "qux", :nx => true)
67
- assert !r.set("foo", "bar", :nx => true)
68
- assert_equal "qux", r.get("foo")
69
-
70
- r.del("foo")
71
- assert r.set("foo", "bar", :nx => true)
72
- assert_equal "bar", r.get("foo")
73
- end
74
- end
75
-
76
- def test_set_with_xx
77
- target_version "2.6.12" do
78
- r.set("foo", "qux")
79
- assert r.set("foo", "bar", :xx => true)
80
- assert_equal "bar", r.get("foo")
81
-
82
- r.del("foo")
83
- assert !r.set("foo", "bar", :xx => true)
84
- end
85
- end
86
-
87
- def test_setex
88
- assert r.setex("foo", 1, "bar")
89
- assert_equal "bar", r.get("foo")
90
- assert [0, 1].include? r.ttl("foo")
91
- end
92
-
93
- def test_setex_with_non_string_value
94
- value = ["b", "a", "r"]
95
-
96
- assert r.setex("foo", 1, value)
97
- assert_equal value.to_s, r.get("foo")
98
- assert [0, 1].include? r.ttl("foo")
99
- end
100
-
101
- def test_psetex
102
- target_version "2.5.4" do
103
- assert r.psetex("foo", 1000, "bar")
104
- assert_equal "bar", r.get("foo")
105
- assert [0, 1].include? r.ttl("foo")
106
- end
107
- end
108
-
109
- def test_psetex_with_non_string_value
110
- target_version "2.5.4" do
111
- value = ["b", "a", "r"]
112
-
113
- assert r.psetex("foo", 1000, value)
114
- assert_equal value.to_s, r.get("foo")
115
- assert [0, 1].include? r.ttl("foo")
116
- end
117
- end
118
-
119
- def test_getset
120
- r.set("foo", "bar")
121
-
122
- assert_equal "bar", r.getset("foo", "baz")
123
- assert_equal "baz", r.get("foo")
124
- end
125
-
126
- def test_getset_with_non_string_value
127
- r.set("foo", "zap")
128
-
129
- value = ["b", "a", "r"]
130
-
131
- assert_equal "zap", r.getset("foo", value)
132
- assert_equal value.to_s, r.get("foo")
133
- end
134
-
135
- def test_setnx
136
- r.set("foo", "qux")
137
- assert !r.setnx("foo", "bar")
138
- assert_equal "qux", r.get("foo")
139
-
140
- r.del("foo")
141
- assert r.setnx("foo", "bar")
142
- assert_equal "bar", r.get("foo")
143
- end
144
-
145
- def test_setnx_with_non_string_value
146
- value = ["b", "a", "r"]
147
-
148
- r.set("foo", "qux")
149
- assert !r.setnx("foo", value)
150
- assert_equal "qux", r.get("foo")
151
-
152
- r.del("foo")
153
- assert r.setnx("foo", value)
154
- assert_equal value.to_s, r.get("foo")
155
- end
156
-
157
- def test_incr
158
- assert_equal 1, r.incr("foo")
159
- assert_equal 2, r.incr("foo")
160
- assert_equal 3, r.incr("foo")
161
- end
162
-
163
- def test_incrby
164
- assert_equal 1, r.incrby("foo", 1)
165
- assert_equal 3, r.incrby("foo", 2)
166
- assert_equal 6, r.incrby("foo", 3)
167
- end
168
-
169
- def test_incrbyfloat
170
- target_version "2.5.4" do
171
- assert_equal 1.23, r.incrbyfloat("foo", 1.23)
172
- assert_equal 2 , r.incrbyfloat("foo", 0.77)
173
- assert_equal 1.9 , r.incrbyfloat("foo", -0.1)
174
- end
175
- end
176
-
177
- def test_decr
178
- r.set("foo", 3)
179
-
180
- assert_equal 2, r.decr("foo")
181
- assert_equal 1, r.decr("foo")
182
- assert_equal 0, r.decr("foo")
183
- end
184
-
185
- def test_decrby
186
- r.set("foo", 6)
187
-
188
- assert_equal 3, r.decrby("foo", 3)
189
- assert_equal 1, r.decrby("foo", 2)
190
- assert_equal 0, r.decrby("foo", 1)
191
- end
192
-
193
- def test_append
194
- r.set "foo", "s"
195
- r.append "foo", "1"
196
-
197
- assert_equal "s1", r.get("foo")
198
- end
199
-
200
- def test_getbit
201
- r.set("foo", "a")
202
-
203
- assert_equal 1, r.getbit("foo", 1)
204
- assert_equal 1, r.getbit("foo", 2)
205
- assert_equal 0, r.getbit("foo", 3)
206
- assert_equal 0, r.getbit("foo", 4)
207
- assert_equal 0, r.getbit("foo", 5)
208
- assert_equal 0, r.getbit("foo", 6)
209
- assert_equal 1, r.getbit("foo", 7)
210
- end
211
-
212
- def test_setbit
213
- r.set("foo", "a")
214
-
215
- r.setbit("foo", 6, 1)
216
-
217
- assert_equal "c", r.get("foo")
218
- end
219
-
220
- def test_bitcount
221
- target_version "2.5.10" do
222
- r.set("foo", "abcde")
223
-
224
- assert_equal 10, r.bitcount("foo", 1, 3)
225
- assert_equal 17, r.bitcount("foo", 0, -1)
226
- end
227
- end
228
-
229
- def test_getrange
230
- r.set("foo", "abcde")
231
-
232
- assert_equal "bcd", r.getrange("foo", 1, 3)
233
- assert_equal "abcde", r.getrange("foo", 0, -1)
234
- end
235
-
236
- def test_setrange
237
- r.set("foo", "abcde")
238
-
239
- r.setrange("foo", 1, "bar")
240
-
241
- assert_equal "abare", r.get("foo")
242
- end
243
-
244
- def test_setrange_with_non_string_value
245
- r.set("foo", "abcde")
246
-
247
- value = ["b", "a", "r"]
248
-
249
- r.setrange("foo", 2, value)
250
-
251
- assert_equal "ab#{value.to_s}", r.get("foo")
252
- end
253
-
254
- def test_strlen
255
- r.set "foo", "lorem"
256
-
257
- assert_equal 5, r.strlen("foo")
258
- end
259
- end
260
- end
@@ -1,122 +0,0 @@
1
- module Lint
2
-
3
- module ValueTypes
4
-
5
- def test_exists
6
- assert_equal false, r.exists("foo")
7
-
8
- r.set("foo", "s1")
9
-
10
- assert_equal true, r.exists("foo")
11
- end
12
-
13
- def test_type
14
- assert_equal "none", r.type("foo")
15
-
16
- r.set("foo", "s1")
17
-
18
- assert_equal "string", r.type("foo")
19
- end
20
-
21
- def test_keys
22
- r.set("f", "s1")
23
- r.set("fo", "s2")
24
- r.set("foo", "s3")
25
-
26
- assert_equal ["f","fo", "foo"], r.keys("f*").sort
27
- end
28
-
29
- def test_expire
30
- r.set("foo", "s1")
31
- assert r.expire("foo", 2)
32
- assert_in_range 0..2, r.ttl("foo")
33
- end
34
-
35
- def test_pexpire
36
- target_version "2.5.4" do
37
- r.set("foo", "s1")
38
- assert r.pexpire("foo", 2000)
39
- assert_in_range 0..2, r.ttl("foo")
40
- end
41
- end
42
-
43
- def test_expireat
44
- r.set("foo", "s1")
45
- assert r.expireat("foo", (Time.now + 2).to_i)
46
- assert_in_range 0..2, r.ttl("foo")
47
- end
48
-
49
- def test_pexpireat
50
- target_version "2.5.4" do
51
- r.set("foo", "s1")
52
- assert r.pexpireat("foo", (Time.now + 2).to_i * 1_000)
53
- assert_in_range 0..2, r.ttl("foo")
54
- end
55
- end
56
-
57
- def test_persist
58
- r.set("foo", "s1")
59
- r.expire("foo", 1)
60
- r.persist("foo")
61
-
62
- assert(-1 == r.ttl("foo"))
63
- end
64
-
65
- def test_ttl
66
- r.set("foo", "s1")
67
- r.expire("foo", 2)
68
- assert_in_range 0..2, r.ttl("foo")
69
- end
70
-
71
- def test_pttl
72
- target_version "2.5.4" do
73
- r.set("foo", "s1")
74
- r.expire("foo", 2)
75
- assert_in_range 1..2000, r.pttl("foo")
76
- end
77
- end
78
-
79
- def test_dump_and_restore
80
- target_version "2.5.7" do
81
- r.set("foo", "a")
82
- v = r.dump("foo")
83
- r.del("foo")
84
-
85
- assert r.restore("foo", 1000, v)
86
- assert_equal "a", r.get("foo")
87
- assert [0, 1].include? r.ttl("foo")
88
-
89
- r.rpush("bar", ["b", "c", "d"])
90
- w = r.dump("bar")
91
- r.del("bar")
92
-
93
- assert r.restore("bar", 1000, w)
94
- assert_equal ["b", "c", "d"], r.lrange("bar", 0, -1)
95
- assert [0, 1].include? r.ttl("bar")
96
- end
97
- end
98
-
99
- def test_move
100
- r.select 14
101
- r.flushdb
102
-
103
- r.set "bar", "s3"
104
-
105
- r.select 15
106
-
107
- r.set "foo", "s1"
108
- r.set "bar", "s2"
109
-
110
- assert r.move("foo", 14)
111
- assert_equal nil, r.get("foo")
112
-
113
- assert !r.move("bar", 14)
114
- assert_equal "s2", r.get("bar")
115
-
116
- r.select 14
117
-
118
- assert_equal "s1", r.get("foo")
119
- assert_equal "s3", r.get("bar")
120
- end
121
- end
122
- end
@@ -1,26 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
-
5
- class TestPersistenceControlCommands < Test::Unit::TestCase
6
-
7
- include Helper::Client
8
-
9
- def test_save
10
- redis_mock(:save => lambda { "+SAVE" }) do |redis|
11
- assert_equal "SAVE", redis.save
12
- end
13
- end
14
-
15
- def test_bgsave
16
- redis_mock(:bgsave => lambda { "+BGSAVE" }) do |redis|
17
- assert_equal "BGSAVE", redis.bgsave
18
- end
19
- end
20
-
21
- def test_lastsave
22
- redis_mock(:lastsave => lambda { "+LASTSAVE" }) do |redis|
23
- assert_equal "LASTSAVE", redis.lastsave
24
- end
25
- end
26
- end
@@ -1,242 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
-
5
- class TestPipeliningCommands < Test::Unit::TestCase
6
-
7
- include Helper::Client
8
-
9
- def test_bulk_commands
10
- r.pipelined do
11
- r.lpush "foo", "s1"
12
- r.lpush "foo", "s2"
13
- end
14
-
15
- assert_equal 2, r.llen("foo")
16
- assert_equal "s2", r.lpop("foo")
17
- assert_equal "s1", r.lpop("foo")
18
- end
19
-
20
- def test_multi_bulk_commands
21
- r.pipelined do
22
- r.mset("foo", "s1", "bar", "s2")
23
- r.mset("baz", "s3", "qux", "s4")
24
- end
25
-
26
- assert_equal "s1", r.get("foo")
27
- assert_equal "s2", r.get("bar")
28
- assert_equal "s3", r.get("baz")
29
- assert_equal "s4", r.get("qux")
30
- end
31
-
32
- def test_bulk_and_multi_bulk_commands_mixed
33
- r.pipelined do
34
- r.lpush "foo", "s1"
35
- r.lpush "foo", "s2"
36
- r.mset("baz", "s3", "qux", "s4")
37
- end
38
-
39
- assert_equal 2, r.llen("foo")
40
- assert_equal "s2", r.lpop("foo")
41
- assert_equal "s1", r.lpop("foo")
42
- assert_equal "s3", r.get("baz")
43
- assert_equal "s4", r.get("qux")
44
- end
45
-
46
- def test_multi_bulk_and_bulk_commands_mixed
47
- r.pipelined do
48
- r.mset("baz", "s3", "qux", "s4")
49
- r.lpush "foo", "s1"
50
- r.lpush "foo", "s2"
51
- end
52
-
53
- assert_equal 2, r.llen("foo")
54
- assert_equal "s2", r.lpop("foo")
55
- assert_equal "s1", r.lpop("foo")
56
- assert_equal "s3", r.get("baz")
57
- assert_equal "s4", r.get("qux")
58
- end
59
-
60
- def test_pipelined_with_an_empty_block
61
- assert_nothing_raised do
62
- r.pipelined do
63
- end
64
- end
65
-
66
- assert_equal 0, r.dbsize
67
- end
68
-
69
- def test_returning_the_result_of_a_pipeline
70
- result = r.pipelined do
71
- r.set "foo", "bar"
72
- r.get "foo"
73
- r.get "bar"
74
- end
75
-
76
- assert_equal ["OK", "bar", nil], result
77
- end
78
-
79
- def test_assignment_of_results_inside_the_block
80
- r.pipelined do
81
- @first = r.sadd("foo", 1)
82
- @second = r.sadd("foo", 1)
83
- end
84
-
85
- assert_equal true, @first.value
86
- assert_equal false, @second.value
87
- end
88
-
89
- # Although we could support accessing the values in these futures,
90
- # it doesn't make a lot of sense.
91
- def test_assignment_of_results_inside_the_block_with_errors
92
- assert_raise(Redis::CommandError) do
93
- r.pipelined do
94
- r.doesnt_exist
95
- @first = r.sadd("foo", 1)
96
- @second = r.sadd("foo", 1)
97
- end
98
- end
99
-
100
- assert_raise(Redis::FutureNotReady) { @first.value }
101
- assert_raise(Redis::FutureNotReady) { @second.value }
102
- end
103
-
104
- def test_assignment_of_results_inside_a_nested_block
105
- r.pipelined do
106
- @first = r.sadd("foo", 1)
107
-
108
- r.pipelined do
109
- @second = r.sadd("foo", 1)
110
- end
111
- end
112
-
113
- assert_equal true, @first.value
114
- assert_equal false, @second.value
115
- end
116
-
117
- def test_futures_raise_when_confused_with_something_else
118
- r.pipelined do
119
- @result = r.sadd("foo", 1)
120
- end
121
-
122
- assert_raise(NoMethodError) { @result.to_s }
123
- end
124
-
125
- def test_futures_raise_when_trying_to_access_their_values_too_early
126
- r.pipelined do
127
- assert_raise(Redis::FutureNotReady) do
128
- r.sadd("foo", 1).value
129
- end
130
- end
131
- end
132
-
133
- def test_futures_can_be_identified
134
- r.pipelined do
135
- @result = r.sadd("foo", 1)
136
- end
137
-
138
- assert_equal true, @result.is_a?(Redis::Future)
139
- if defined?(::BasicObject)
140
- assert_equal true, @result.is_a?(::BasicObject)
141
- end
142
- assert_equal Redis::Future, @result.class
143
- end
144
-
145
- def test_returning_the_result_of_an_empty_pipeline
146
- result = r.pipelined do
147
- end
148
-
149
- assert_equal [], result
150
- end
151
-
152
- def test_nesting_pipeline_blocks
153
- r.pipelined do
154
- r.set("foo", "s1")
155
- r.pipelined do
156
- r.set("bar", "s2")
157
- end
158
- end
159
-
160
- assert_equal "s1", r.get("foo")
161
- assert_equal "s2", r.get("bar")
162
- end
163
-
164
- def test_info_in_a_pipeline_returns_hash
165
- result = r.pipelined do
166
- r.info
167
- end
168
-
169
- assert result.first.kind_of?(Hash)
170
- end
171
-
172
- def test_config_get_in_a_pipeline_returns_hash
173
- result = r.pipelined do
174
- r.config(:get, "*")
175
- end
176
-
177
- assert result.first.kind_of?(Hash)
178
- end
179
-
180
- def test_hgetall_in_a_pipeline_returns_hash
181
- r.hmset("hash", "field", "value")
182
- result = r.pipelined do
183
- r.hgetall("hash")
184
- end
185
-
186
- assert_equal result.first, { "field" => "value" }
187
- end
188
-
189
- def test_keys_in_a_pipeline
190
- r.set("key", "value")
191
- result = r.pipelined do
192
- r.keys("*")
193
- end
194
-
195
- assert_equal ["key"], result.first
196
- end
197
-
198
- def test_pipeline_yields_a_connection
199
- r.pipelined do |p|
200
- p.set("foo", "bar")
201
- end
202
-
203
- assert_equal "bar", r.get("foo")
204
- end
205
-
206
- def test_pipeline_select
207
- r.select 1
208
- r.set("db", "1")
209
-
210
- r.pipelined do |p|
211
- p.select 2
212
- p.set("db", "2")
213
- end
214
-
215
- r.select 1
216
- assert_equal "1", r.get("db")
217
-
218
- r.select 2
219
- assert_equal "2", r.get("db")
220
- end
221
-
222
- def test_pipeline_select_client_db
223
- r.select 1
224
- r.pipelined do |p2|
225
- p2.select 2
226
- end
227
-
228
- assert_equal 2, r.client.db
229
- end
230
-
231
- def test_nested_pipeline_select_client_db
232
- r.select 1
233
- r.pipelined do |p2|
234
- p2.select 2
235
- p2.pipelined do |p3|
236
- p3.select 3
237
- end
238
- end
239
-
240
- assert_equal 3, r.client.db
241
- end
242
- end