redis 3.3.5 → 4.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +32 -50
  3. data/CHANGELOG.md +7 -9
  4. data/Gemfile +0 -1
  5. data/README.md +31 -75
  6. data/benchmarking/logging.rb +1 -1
  7. data/lib/redis.rb +31 -35
  8. data/lib/redis/client.rb +13 -8
  9. data/lib/redis/connection.rb +2 -2
  10. data/lib/redis/connection/command_helper.rb +2 -8
  11. data/lib/redis/connection/hiredis.rb +2 -2
  12. data/lib/redis/connection/ruby.rb +7 -27
  13. data/lib/redis/connection/synchrony.rb +3 -3
  14. data/lib/redis/pipeline.rb +0 -6
  15. data/lib/redis/version.rb +1 -1
  16. data/makefile +42 -0
  17. data/redis.gemspec +4 -8
  18. data/test/bitpos_test.rb +13 -19
  19. data/test/blocking_commands_test.rb +147 -6
  20. data/test/client_test.rb +1 -1
  21. data/test/command_map_test.rb +3 -5
  22. data/test/commands_on_hashes_test.rb +158 -5
  23. data/test/commands_on_hyper_log_log_test.rb +55 -6
  24. data/test/commands_on_lists_test.rb +139 -5
  25. data/test/commands_on_sets_test.rb +136 -5
  26. data/test/commands_on_sorted_sets_test.rb +312 -5
  27. data/test/commands_on_strings_test.rb +243 -6
  28. data/test/commands_on_value_types_test.rb +120 -7
  29. data/test/connection_handling_test.rb +5 -7
  30. data/test/encoding_test.rb +4 -8
  31. data/test/error_replies_test.rb +2 -4
  32. data/test/fork_safety_test.rb +1 -6
  33. data/test/helper.rb +9 -62
  34. data/test/helper_test.rb +1 -3
  35. data/test/internals_test.rb +67 -49
  36. data/test/persistence_control_commands_test.rb +1 -3
  37. data/test/pipelining_commands_test.rb +4 -8
  38. data/test/publish_subscribe_test.rb +1 -3
  39. data/test/remote_server_control_commands_test.rb +61 -4
  40. data/test/scanning_test.rb +1 -7
  41. data/test/scripting_test.rb +1 -3
  42. data/test/sentinel_command_test.rb +1 -3
  43. data/test/sentinel_test.rb +1 -3
  44. data/test/sorting_test.rb +1 -3
  45. data/test/ssl_test.rb +45 -49
  46. data/test/support/connection/hiredis.rb +1 -1
  47. data/test/support/connection/ruby.rb +1 -1
  48. data/test/support/connection/synchrony.rb +1 -1
  49. data/test/synchrony_driver.rb +6 -9
  50. data/test/thread_safety_test.rb +1 -3
  51. data/test/transactions_test.rb +1 -3
  52. data/test/unknown_commands_test.rb +1 -3
  53. data/test/url_param_test.rb +44 -46
  54. metadata +31 -77
  55. data/Rakefile +0 -87
  56. data/examples/dist_redis.rb +0 -43
  57. data/lib/redis/distributed.rb +0 -873
  58. data/lib/redis/hash_ring.rb +0 -132
  59. data/test/connection_test.rb +0 -57
  60. data/test/distributed_blocking_commands_test.rb +0 -46
  61. data/test/distributed_commands_on_hashes_test.rb +0 -10
  62. data/test/distributed_commands_on_hyper_log_log_test.rb +0 -33
  63. data/test/distributed_commands_on_lists_test.rb +0 -22
  64. data/test/distributed_commands_on_sets_test.rb +0 -83
  65. data/test/distributed_commands_on_sorted_sets_test.rb +0 -18
  66. data/test/distributed_commands_on_strings_test.rb +0 -59
  67. data/test/distributed_commands_on_value_types_test.rb +0 -95
  68. data/test/distributed_commands_requiring_clustering_test.rb +0 -164
  69. data/test/distributed_connection_handling_test.rb +0 -23
  70. data/test/distributed_internals_test.rb +0 -79
  71. data/test/distributed_key_tags_test.rb +0 -52
  72. data/test/distributed_persistence_control_commands_test.rb +0 -26
  73. data/test/distributed_publish_subscribe_test.rb +0 -92
  74. data/test/distributed_remote_server_control_commands_test.rb +0 -66
  75. data/test/distributed_scripting_test.rb +0 -102
  76. data/test/distributed_sorting_test.rb +0 -20
  77. data/test/distributed_test.rb +0 -58
  78. data/test/distributed_transactions_test.rb +0 -32
  79. data/test/lint/blocking_commands.rb +0 -150
  80. data/test/lint/hashes.rb +0 -162
  81. data/test/lint/hyper_log_log.rb +0 -60
  82. data/test/lint/lists.rb +0 -143
  83. data/test/lint/sets.rb +0 -140
  84. data/test/lint/sorted_sets.rb +0 -316
  85. data/test/lint/strings.rb +0 -260
  86. data/test/lint/value_types.rb +0 -122
@@ -1,12 +1,319 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
- require "lint/sorted_sets"
1
+ require_relative "helper"
5
2
 
6
3
  class TestCommandsOnSortedSets < Test::Unit::TestCase
7
4
 
8
5
  include Helper::Client
9
- include Lint::SortedSets
6
+
7
+ Infinity = 1.0/0.0
8
+
9
+ def test_zadd
10
+ assert_equal 0, r.zcard("foo")
11
+ assert_equal true, r.zadd("foo", 1, "s1")
12
+ assert_equal false, r.zadd("foo", 1, "s1")
13
+ assert_equal 1, r.zcard("foo")
14
+ r.del "foo"
15
+
16
+ target_version "3.0.2" do
17
+ # XX option
18
+ assert_equal 0, r.zcard("foo")
19
+ assert_equal false, r.zadd("foo", 1, "s1", :xx => true)
20
+ r.zadd("foo", 1, "s1")
21
+ assert_equal false, r.zadd("foo", 2, "s1", :xx => true)
22
+ assert_equal 2, r.zscore("foo", "s1")
23
+ r.del "foo"
24
+
25
+ # NX option
26
+ assert_equal 0, r.zcard("foo")
27
+ assert_equal true, r.zadd("foo", 1, "s1", :nx => true)
28
+ assert_equal false, r.zadd("foo", 2, "s1", :nx => true)
29
+ assert_equal 1, r.zscore("foo", "s1")
30
+ assert_equal 1, r.zcard("foo")
31
+ r.del "foo"
32
+
33
+ # CH option
34
+ assert_equal 0, r.zcard("foo")
35
+ assert_equal true, r.zadd("foo", 1, "s1", :ch => true)
36
+ assert_equal false, r.zadd("foo", 1, "s1", :ch => true)
37
+ assert_equal true, r.zadd("foo", 2, "s1", :ch => true)
38
+ assert_equal 1, r.zcard("foo")
39
+ r.del "foo"
40
+
41
+ # INCR option
42
+ assert_equal 1.0, r.zadd("foo", 1, "s1", :incr => true)
43
+ assert_equal 11.0, r.zadd("foo", 10, "s1", :incr => true)
44
+ assert_equal(-Infinity, r.zadd("bar", "-inf", "s1", :incr => true))
45
+ assert_equal(+Infinity, r.zadd("bar", "+inf", "s2", :incr => true))
46
+ r.del "foo", "bar"
47
+
48
+ # Incompatible options combination
49
+ assert_raise(Redis::CommandError) { r.zadd("foo", 1, "s1", :xx => true, :nx => true) }
50
+ end
51
+ end
52
+
53
+ def test_variadic_zadd
54
+ target_version "2.3.9" do # 2.4-rc6
55
+ # Non-nested array with pairs
56
+ assert_equal 0, r.zcard("foo")
57
+ assert_equal 2, r.zadd("foo", [1, "s1", 2, "s2"])
58
+ assert_equal 1, r.zadd("foo", [4, "s1", 5, "s2", 6, "s3"])
59
+ assert_equal 3, r.zcard("foo")
60
+ r.del "foo"
61
+
62
+ # Nested array with pairs
63
+ assert_equal 0, r.zcard("foo")
64
+ assert_equal 2, r.zadd("foo", [[1, "s1"], [2, "s2"]])
65
+ assert_equal 1, r.zadd("foo", [[4, "s1"], [5, "s2"], [6, "s3"]])
66
+ assert_equal 3, r.zcard("foo")
67
+ r.del "foo"
68
+
69
+ # Wrong number of arguments
70
+ assert_raise(Redis::CommandError) { r.zadd("foo", ["bar"]) }
71
+ assert_raise(Redis::CommandError) { r.zadd("foo", ["bar", "qux", "zap"]) }
72
+ end
73
+
74
+ target_version "3.0.2" do
75
+ # XX option
76
+ assert_equal 0, r.zcard("foo")
77
+ assert_equal 0, r.zadd("foo", [1, "s1", 2, "s2"], :xx => true)
78
+ r.zadd("foo", [1, "s1", 2, "s2"])
79
+ assert_equal 0, r.zadd("foo", [2, "s1", 3, "s2", 4, "s3"], :xx => true)
80
+ assert_equal 2, r.zscore("foo", "s1")
81
+ assert_equal 3, r.zscore("foo", "s2")
82
+ assert_equal nil, r.zscore("foo", "s3")
83
+ assert_equal 2, r.zcard("foo")
84
+ r.del "foo"
85
+
86
+ # NX option
87
+ assert_equal 0, r.zcard("foo")
88
+ assert_equal 2, r.zadd("foo", [1, "s1", 2, "s2"], :nx => true)
89
+ assert_equal 1, r.zadd("foo", [2, "s1", 3, "s2", 4, "s3"], :nx => true)
90
+ assert_equal 1, r.zscore("foo", "s1")
91
+ assert_equal 2, r.zscore("foo", "s2")
92
+ assert_equal 4, r.zscore("foo", "s3")
93
+ assert_equal 3, r.zcard("foo")
94
+ r.del "foo"
95
+
96
+ # CH option
97
+ assert_equal 0, r.zcard("foo")
98
+ assert_equal 2, r.zadd("foo", [1, "s1", 2, "s2"], :ch => true)
99
+ assert_equal 2, r.zadd("foo", [1, "s1", 3, "s2", 4, "s3"], :ch => true)
100
+ assert_equal 3, r.zcard("foo")
101
+ r.del "foo"
102
+
103
+ # INCR option
104
+ assert_equal 1.0, r.zadd("foo", [1, "s1"], :incr => true)
105
+ assert_equal 11.0, r.zadd("foo", [10, "s1"], :incr => true)
106
+ assert_equal(-Infinity, r.zadd("bar", ["-inf", "s1"], :incr => true))
107
+ assert_equal(+Infinity, r.zadd("bar", ["+inf", "s2"], :incr => true))
108
+ assert_raise(Redis::CommandError) { r.zadd("foo", [1, "s1", 2, "s2"], :incr => true) }
109
+ r.del "foo", "bar"
110
+
111
+ # Incompatible options combination
112
+ assert_raise(Redis::CommandError) { r.zadd("foo", [1, "s1"], :xx => true, :nx => true) }
113
+ end
114
+ end
115
+
116
+ def test_zrem
117
+ r.zadd("foo", 1, "s1")
118
+ r.zadd("foo", 2, "s2")
119
+
120
+ assert_equal 2, r.zcard("foo")
121
+ assert_equal true, r.zrem("foo", "s1")
122
+ assert_equal false, r.zrem("foo", "s1")
123
+ assert_equal 1, r.zcard("foo")
124
+ end
125
+
126
+ def test_variadic_zrem
127
+ target_version "2.3.9" do # 2.4-rc6
128
+ r.zadd("foo", 1, "s1")
129
+ r.zadd("foo", 2, "s2")
130
+ r.zadd("foo", 3, "s3")
131
+
132
+ assert_equal 3, r.zcard("foo")
133
+ assert_equal 1, r.zrem("foo", ["s1", "aaa"])
134
+ assert_equal 0, r.zrem("foo", ["bbb", "ccc" "ddd"])
135
+ assert_equal 1, r.zrem("foo", ["eee", "s3"])
136
+ assert_equal 1, r.zcard("foo")
137
+ end
138
+ end
139
+
140
+ def test_zincrby
141
+ rv = r.zincrby "foo", 1, "s1"
142
+ assert_equal 1.0, rv
143
+
144
+ rv = r.zincrby "foo", 10, "s1"
145
+ assert_equal 11.0, rv
146
+
147
+ rv = r.zincrby "bar", "-inf", "s1"
148
+ assert_equal(-Infinity, rv)
149
+
150
+ rv = r.zincrby "bar", "+inf", "s2"
151
+ assert_equal(+Infinity, rv)
152
+ end
153
+
154
+ def test_zrank
155
+ r.zadd "foo", 1, "s1"
156
+ r.zadd "foo", 2, "s2"
157
+ r.zadd "foo", 3, "s3"
158
+
159
+ assert_equal 2, r.zrank("foo", "s3")
160
+ end
161
+
162
+ def test_zrevrank
163
+ r.zadd "foo", 1, "s1"
164
+ r.zadd "foo", 2, "s2"
165
+ r.zadd "foo", 3, "s3"
166
+
167
+ assert_equal 0, r.zrevrank("foo", "s3")
168
+ end
169
+
170
+ def test_zrange
171
+ r.zadd "foo", 1, "s1"
172
+ r.zadd "foo", 2, "s2"
173
+ r.zadd "foo", 3, "s3"
174
+
175
+ assert_equal ["s1", "s2"], r.zrange("foo", 0, 1)
176
+ assert_equal [["s1", 1.0], ["s2", 2.0]], r.zrange("foo", 0, 1, :with_scores => true)
177
+ assert_equal [["s1", 1.0], ["s2", 2.0]], r.zrange("foo", 0, 1, :withscores => true)
178
+
179
+ r.zadd "bar", "-inf", "s1"
180
+ r.zadd "bar", "+inf", "s2"
181
+ assert_equal [["s1", -Infinity], ["s2", +Infinity]], r.zrange("bar", 0, 1, :with_scores => true)
182
+ assert_equal [["s1", -Infinity], ["s2", +Infinity]], r.zrange("bar", 0, 1, :withscores => true)
183
+ end
184
+
185
+ def test_zrevrange
186
+ r.zadd "foo", 1, "s1"
187
+ r.zadd "foo", 2, "s2"
188
+ r.zadd "foo", 3, "s3"
189
+
190
+ assert_equal ["s3", "s2"], r.zrevrange("foo", 0, 1)
191
+ assert_equal [["s3", 3.0], ["s2", 2.0]], r.zrevrange("foo", 0, 1, :with_scores => true)
192
+ assert_equal [["s3", 3.0], ["s2", 2.0]], r.zrevrange("foo", 0, 1, :withscores => true)
193
+
194
+ r.zadd "bar", "-inf", "s1"
195
+ r.zadd "bar", "+inf", "s2"
196
+ assert_equal [["s2", +Infinity], ["s1", -Infinity]], r.zrevrange("bar", 0, 1, :with_scores => true)
197
+ assert_equal [["s2", +Infinity], ["s1", -Infinity]], r.zrevrange("bar", 0, 1, :withscores => true)
198
+ end
199
+
200
+ def test_zrangebyscore
201
+ r.zadd "foo", 1, "s1"
202
+ r.zadd "foo", 2, "s2"
203
+ r.zadd "foo", 3, "s3"
204
+
205
+ assert_equal ["s2", "s3"], r.zrangebyscore("foo", 2, 3)
206
+ end
207
+
208
+ def test_zrevrangebyscore
209
+ r.zadd "foo", 1, "s1"
210
+ r.zadd "foo", 2, "s2"
211
+ r.zadd "foo", 3, "s3"
212
+
213
+ assert_equal ["s3", "s2"], r.zrevrangebyscore("foo", 3, 2)
214
+ end
215
+
216
+ def test_zrangebyscore_with_limit
217
+ r.zadd "foo", 1, "s1"
218
+ r.zadd "foo", 2, "s2"
219
+ r.zadd "foo", 3, "s3"
220
+ r.zadd "foo", 4, "s4"
221
+
222
+ assert_equal ["s2"], r.zrangebyscore("foo", 2, 4, :limit => [0, 1])
223
+ assert_equal ["s3"], r.zrangebyscore("foo", 2, 4, :limit => [1, 1])
224
+ assert_equal ["s3", "s4"], r.zrangebyscore("foo", 2, 4, :limit => [1, 2])
225
+ end
226
+
227
+ def test_zrevrangebyscore_with_limit
228
+ r.zadd "foo", 1, "s1"
229
+ r.zadd "foo", 2, "s2"
230
+ r.zadd "foo", 3, "s3"
231
+ r.zadd "foo", 4, "s4"
232
+
233
+ assert_equal ["s4"], r.zrevrangebyscore("foo", 4, 2, :limit => [0, 1])
234
+ assert_equal ["s3"], r.zrevrangebyscore("foo", 4, 2, :limit => [1, 1])
235
+ assert_equal ["s3", "s2"], r.zrevrangebyscore("foo", 4, 2, :limit => [1, 2])
236
+ end
237
+
238
+ def test_zrangebyscore_with_withscores
239
+ r.zadd "foo", 1, "s1"
240
+ r.zadd "foo", 2, "s2"
241
+ r.zadd "foo", 3, "s3"
242
+ r.zadd "foo", 4, "s4"
243
+
244
+ assert_equal [["s2", 2.0]], r.zrangebyscore("foo", 2, 4, :limit => [0, 1], :with_scores => true)
245
+ assert_equal [["s3", 3.0]], r.zrangebyscore("foo", 2, 4, :limit => [1, 1], :with_scores => true)
246
+ assert_equal [["s2", 2.0]], r.zrangebyscore("foo", 2, 4, :limit => [0, 1], :withscores => true)
247
+ assert_equal [["s3", 3.0]], r.zrangebyscore("foo", 2, 4, :limit => [1, 1], :withscores => true)
248
+
249
+ r.zadd "bar", "-inf", "s1"
250
+ r.zadd "bar", "+inf", "s2"
251
+ assert_equal [["s1", -Infinity]], r.zrangebyscore("bar", -Infinity, +Infinity, :limit => [0, 1], :with_scores => true)
252
+ assert_equal [["s2", +Infinity]], r.zrangebyscore("bar", -Infinity, +Infinity, :limit => [1, 1], :with_scores => true)
253
+ assert_equal [["s1", -Infinity]], r.zrangebyscore("bar", -Infinity, +Infinity, :limit => [0, 1], :withscores => true)
254
+ assert_equal [["s2", +Infinity]], r.zrangebyscore("bar", -Infinity, +Infinity, :limit => [1, 1], :withscores => true)
255
+ end
256
+
257
+ def test_zrevrangebyscore_with_withscores
258
+ r.zadd "foo", 1, "s1"
259
+ r.zadd "foo", 2, "s2"
260
+ r.zadd "foo", 3, "s3"
261
+ r.zadd "foo", 4, "s4"
262
+
263
+ assert_equal [["s4", 4.0]], r.zrevrangebyscore("foo", 4, 2, :limit => [0, 1], :with_scores => true)
264
+ assert_equal [["s3", 3.0]], r.zrevrangebyscore("foo", 4, 2, :limit => [1, 1], :with_scores => true)
265
+ assert_equal [["s4", 4.0]], r.zrevrangebyscore("foo", 4, 2, :limit => [0, 1], :withscores => true)
266
+ assert_equal [["s3", 3.0]], r.zrevrangebyscore("foo", 4, 2, :limit => [1, 1], :withscores => true)
267
+
268
+ r.zadd "bar", "-inf", "s1"
269
+ r.zadd "bar", "+inf", "s2"
270
+ assert_equal [["s2", +Infinity]], r.zrevrangebyscore("bar", +Infinity, -Infinity, :limit => [0, 1], :with_scores => true)
271
+ assert_equal [["s1", -Infinity]], r.zrevrangebyscore("bar", +Infinity, -Infinity, :limit => [1, 1], :with_scores => true)
272
+ assert_equal [["s2", +Infinity]], r.zrevrangebyscore("bar", +Infinity, -Infinity, :limit => [0, 1], :withscores => true)
273
+ assert_equal [["s1", -Infinity]], r.zrevrangebyscore("bar", +Infinity, -Infinity, :limit => [1, 1], :withscores => true)
274
+ end
275
+
276
+ def test_zcard
277
+ assert_equal 0, r.zcard("foo")
278
+
279
+ r.zadd "foo", 1, "s1"
280
+
281
+ assert_equal 1, r.zcard("foo")
282
+ end
283
+
284
+ def test_zscore
285
+ r.zadd "foo", 1, "s1"
286
+
287
+ assert_equal 1.0, r.zscore("foo", "s1")
288
+
289
+ assert_equal nil, r.zscore("foo", "s2")
290
+ assert_equal nil, r.zscore("bar", "s1")
291
+
292
+ r.zadd "bar", "-inf", "s1"
293
+ r.zadd "bar", "+inf", "s2"
294
+ assert_equal(-Infinity, r.zscore("bar", "s1"))
295
+ assert_equal(+Infinity, r.zscore("bar", "s2"))
296
+ end
297
+
298
+ def test_zremrangebyrank
299
+ r.zadd "foo", 10, "s1"
300
+ r.zadd "foo", 20, "s2"
301
+ r.zadd "foo", 30, "s3"
302
+ r.zadd "foo", 40, "s4"
303
+
304
+ assert_equal 3, r.zremrangebyrank("foo", 1, 3)
305
+ assert_equal ["s1"], r.zrange("foo", 0, -1)
306
+ end
307
+
308
+ def test_zremrangebyscore
309
+ r.zadd "foo", 1, "s1"
310
+ r.zadd "foo", 2, "s2"
311
+ r.zadd "foo", 3, "s3"
312
+ r.zadd "foo", 4, "s4"
313
+
314
+ assert_equal 3, r.zremrangebyscore("foo", 2, 4)
315
+ assert_equal ["s1"], r.zrange("foo", 0, -1)
316
+ end
10
317
 
11
318
  def test_zrangebylex
12
319
  target_version "2.8.9" do
@@ -1,12 +1,249 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
- require "lint/strings"
1
+ require_relative "helper"
5
2
 
6
3
  class TestCommandsOnStrings < Test::Unit::TestCase
7
4
 
8
5
  include Helper::Client
9
- include Lint::Strings
6
+
7
+ def test_set_and_get
8
+ r.set("foo", "s1")
9
+
10
+ assert_equal "s1", r.get("foo")
11
+ end
12
+
13
+ def test_set_and_get_with_newline_characters
14
+ r.set("foo", "1\n")
15
+
16
+ assert_equal "1\n", r.get("foo")
17
+ end
18
+
19
+ def test_set_and_get_with_non_string_value
20
+ value = ["a", "b"]
21
+
22
+ r.set("foo", value)
23
+
24
+ assert_equal value.to_s, r.get("foo")
25
+ end
26
+
27
+ def test_set_and_get_with_ascii_characters
28
+ with_external_encoding("ASCII-8BIT") do
29
+ (0..255).each do |i|
30
+ str = "#{i.chr}---#{i.chr}"
31
+ r.set("foo", str)
32
+
33
+ assert_equal str, r.get("foo")
34
+ end
35
+ end
36
+ end
37
+
38
+ def test_set_with_ex
39
+ target_version "2.6.12" do
40
+ r.set("foo", "bar", :ex => 2)
41
+ assert_in_range 0..2, r.ttl("foo")
42
+ end
43
+ end
44
+
45
+ def test_set_with_px
46
+ target_version "2.6.12" do
47
+ r.set("foo", "bar", :px => 2000)
48
+ assert_in_range 0..2, r.ttl("foo")
49
+ end
50
+ end
51
+
52
+ def test_set_with_nx
53
+ target_version "2.6.12" do
54
+ r.set("foo", "qux", :nx => true)
55
+ assert !r.set("foo", "bar", :nx => true)
56
+ assert_equal "qux", r.get("foo")
57
+
58
+ r.del("foo")
59
+ assert r.set("foo", "bar", :nx => true)
60
+ assert_equal "bar", r.get("foo")
61
+ end
62
+ end
63
+
64
+ def test_set_with_xx
65
+ target_version "2.6.12" do
66
+ r.set("foo", "qux")
67
+ assert r.set("foo", "bar", :xx => true)
68
+ assert_equal "bar", r.get("foo")
69
+
70
+ r.del("foo")
71
+ assert !r.set("foo", "bar", :xx => true)
72
+ end
73
+ end
74
+
75
+ def test_setex
76
+ assert r.setex("foo", 1, "bar")
77
+ assert_equal "bar", r.get("foo")
78
+ assert [0, 1].include? r.ttl("foo")
79
+ end
80
+
81
+ def test_setex_with_non_string_value
82
+ value = ["b", "a", "r"]
83
+
84
+ assert r.setex("foo", 1, value)
85
+ assert_equal value.to_s, r.get("foo")
86
+ assert [0, 1].include? r.ttl("foo")
87
+ end
88
+
89
+ def test_psetex
90
+ target_version "2.5.4" do
91
+ assert r.psetex("foo", 1000, "bar")
92
+ assert_equal "bar", r.get("foo")
93
+ assert [0, 1].include? r.ttl("foo")
94
+ end
95
+ end
96
+
97
+ def test_psetex_with_non_string_value
98
+ target_version "2.5.4" do
99
+ value = ["b", "a", "r"]
100
+
101
+ assert r.psetex("foo", 1000, value)
102
+ assert_equal value.to_s, r.get("foo")
103
+ assert [0, 1].include? r.ttl("foo")
104
+ end
105
+ end
106
+
107
+ def test_getset
108
+ r.set("foo", "bar")
109
+
110
+ assert_equal "bar", r.getset("foo", "baz")
111
+ assert_equal "baz", r.get("foo")
112
+ end
113
+
114
+ def test_getset_with_non_string_value
115
+ r.set("foo", "zap")
116
+
117
+ value = ["b", "a", "r"]
118
+
119
+ assert_equal "zap", r.getset("foo", value)
120
+ assert_equal value.to_s, r.get("foo")
121
+ end
122
+
123
+ def test_setnx
124
+ r.set("foo", "qux")
125
+ assert !r.setnx("foo", "bar")
126
+ assert_equal "qux", r.get("foo")
127
+
128
+ r.del("foo")
129
+ assert r.setnx("foo", "bar")
130
+ assert_equal "bar", r.get("foo")
131
+ end
132
+
133
+ def test_setnx_with_non_string_value
134
+ value = ["b", "a", "r"]
135
+
136
+ r.set("foo", "qux")
137
+ assert !r.setnx("foo", value)
138
+ assert_equal "qux", r.get("foo")
139
+
140
+ r.del("foo")
141
+ assert r.setnx("foo", value)
142
+ assert_equal value.to_s, r.get("foo")
143
+ end
144
+
145
+ def test_incr
146
+ assert_equal 1, r.incr("foo")
147
+ assert_equal 2, r.incr("foo")
148
+ assert_equal 3, r.incr("foo")
149
+ end
150
+
151
+ def test_incrby
152
+ assert_equal 1, r.incrby("foo", 1)
153
+ assert_equal 3, r.incrby("foo", 2)
154
+ assert_equal 6, r.incrby("foo", 3)
155
+ end
156
+
157
+ def test_incrbyfloat
158
+ target_version "2.5.4" do
159
+ assert_equal 1.23, r.incrbyfloat("foo", 1.23)
160
+ assert_equal 2 , r.incrbyfloat("foo", 0.77)
161
+ assert_equal 1.9 , r.incrbyfloat("foo", -0.1)
162
+ end
163
+ end
164
+
165
+ def test_decr
166
+ r.set("foo", 3)
167
+
168
+ assert_equal 2, r.decr("foo")
169
+ assert_equal 1, r.decr("foo")
170
+ assert_equal 0, r.decr("foo")
171
+ end
172
+
173
+ def test_decrby
174
+ r.set("foo", 6)
175
+
176
+ assert_equal 3, r.decrby("foo", 3)
177
+ assert_equal 1, r.decrby("foo", 2)
178
+ assert_equal 0, r.decrby("foo", 1)
179
+ end
180
+
181
+ def test_append
182
+ r.set "foo", "s"
183
+ r.append "foo", "1"
184
+
185
+ assert_equal "s1", r.get("foo")
186
+ end
187
+
188
+ def test_getbit
189
+ r.set("foo", "a")
190
+
191
+ assert_equal 1, r.getbit("foo", 1)
192
+ assert_equal 1, r.getbit("foo", 2)
193
+ assert_equal 0, r.getbit("foo", 3)
194
+ assert_equal 0, r.getbit("foo", 4)
195
+ assert_equal 0, r.getbit("foo", 5)
196
+ assert_equal 0, r.getbit("foo", 6)
197
+ assert_equal 1, r.getbit("foo", 7)
198
+ end
199
+
200
+ def test_setbit
201
+ r.set("foo", "a")
202
+
203
+ r.setbit("foo", 6, 1)
204
+
205
+ assert_equal "c", r.get("foo")
206
+ end
207
+
208
+ def test_bitcount
209
+ target_version "2.5.10" do
210
+ r.set("foo", "abcde")
211
+
212
+ assert_equal 10, r.bitcount("foo", 1, 3)
213
+ assert_equal 17, r.bitcount("foo", 0, -1)
214
+ end
215
+ end
216
+
217
+ def test_getrange
218
+ r.set("foo", "abcde")
219
+
220
+ assert_equal "bcd", r.getrange("foo", 1, 3)
221
+ assert_equal "abcde", r.getrange("foo", 0, -1)
222
+ end
223
+
224
+ def test_setrange
225
+ r.set("foo", "abcde")
226
+
227
+ r.setrange("foo", 1, "bar")
228
+
229
+ assert_equal "abare", r.get("foo")
230
+ end
231
+
232
+ def test_setrange_with_non_string_value
233
+ r.set("foo", "abcde")
234
+
235
+ value = ["b", "a", "r"]
236
+
237
+ r.setrange("foo", 2, value)
238
+
239
+ assert_equal "ab#{value.to_s}", r.get("foo")
240
+ end
241
+
242
+ def test_strlen
243
+ r.set "foo", "lorem"
244
+
245
+ assert_equal 5, r.strlen("foo")
246
+ end
10
247
 
11
248
  def test_mget
12
249
  r.set("foo", "s1")
@@ -82,7 +319,7 @@ class TestCommandsOnStrings < Test::Unit::TestCase
82
319
  end
83
320
 
84
321
  def test_bitop
85
- try_encoding("UTF-8") do
322
+ with_external_encoding("UTF-8") do
86
323
  target_version "2.5.10" do
87
324
  r.set("foo", "a")
88
325
  r.set("bar", "b")