redis 3.0.5 → 3.0.6

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 (58) hide show
  1. checksums.yaml +8 -8
  2. data/.gitignore +9 -8
  3. data/.travis.yml +10 -8
  4. data/CHANGELOG.md +4 -0
  5. data/Rakefile +21 -10
  6. data/lib/redis.rb +229 -72
  7. data/lib/redis/version.rb +1 -1
  8. data/test/blocking_commands_test.rb +1 -1
  9. data/test/command_map_test.rb +1 -1
  10. data/test/commands_on_hashes_test.rb +1 -1
  11. data/test/commands_on_lists_test.rb +1 -1
  12. data/test/commands_on_sets_test.rb +1 -1
  13. data/test/commands_on_sorted_sets_test.rb +1 -1
  14. data/test/commands_on_strings_test.rb +14 -14
  15. data/test/commands_on_value_types_test.rb +1 -1
  16. data/test/connection_handling_test.rb +1 -1
  17. data/test/distributed_blocking_commands_test.rb +1 -1
  18. data/test/distributed_commands_on_hashes_test.rb +1 -1
  19. data/test/distributed_commands_on_lists_test.rb +1 -1
  20. data/test/distributed_commands_on_sets_test.rb +1 -1
  21. data/test/distributed_commands_on_sorted_sets_test.rb +1 -1
  22. data/test/distributed_commands_on_strings_test.rb +7 -7
  23. data/test/distributed_commands_on_value_types_test.rb +1 -1
  24. data/test/distributed_commands_requiring_clustering_test.rb +14 -14
  25. data/test/distributed_connection_handling_test.rb +1 -1
  26. data/test/distributed_internals_test.rb +1 -1
  27. data/test/distributed_key_tags_test.rb +1 -1
  28. data/test/distributed_persistence_control_commands_test.rb +1 -1
  29. data/test/distributed_publish_subscribe_test.rb +1 -1
  30. data/test/distributed_remote_server_control_commands_test.rb +15 -15
  31. data/test/distributed_scripting_test.rb +57 -57
  32. data/test/distributed_sorting_test.rb +1 -1
  33. data/test/distributed_test.rb +1 -1
  34. data/test/distributed_transactions_test.rb +1 -1
  35. data/test/encoding_test.rb +1 -1
  36. data/test/error_replies_test.rb +1 -1
  37. data/test/helper.rb +10 -1
  38. data/test/helper_test.rb +1 -1
  39. data/test/internals_test.rb +20 -9
  40. data/test/lint/hashes.rb +17 -17
  41. data/test/lint/lists.rb +10 -10
  42. data/test/lint/sets.rb +14 -14
  43. data/test/lint/sorted_sets.rb +30 -30
  44. data/test/lint/strings.rb +45 -45
  45. data/test/lint/value_types.rb +32 -32
  46. data/test/persistence_control_commands_test.rb +1 -1
  47. data/test/pipelining_commands_test.rb +1 -1
  48. data/test/publish_subscribe_test.rb +1 -1
  49. data/test/remote_server_control_commands_test.rb +7 -7
  50. data/test/scanning_test.rb +413 -0
  51. data/test/scripting_test.rb +45 -45
  52. data/test/sorting_test.rb +1 -1
  53. data/test/thread_safety_test.rb +1 -1
  54. data/test/transactions_test.rb +1 -1
  55. data/test/unknown_commands_test.rb +1 -1
  56. data/test/url_param_test.rb +1 -1
  57. metadata +6 -4
  58. data/test/db/.gitignore +0 -1
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require "helper"
3
+ require File.expand_path("helper", File.dirname(__FILE__))
4
4
 
5
5
  class TestDistributedSorting < Test::Unit::TestCase
6
6
 
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require "helper"
3
+ require File.expand_path("helper", File.dirname(__FILE__))
4
4
 
5
5
  class TestDistributed < Test::Unit::TestCase
6
6
 
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require "helper"
3
+ require File.expand_path("helper", File.dirname(__FILE__))
4
4
 
5
5
  class TestDistributedTransactions < Test::Unit::TestCase
6
6
 
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require "helper"
3
+ require File.expand_path("helper", File.dirname(__FILE__))
4
4
 
5
5
  class TestEncoding < Test::Unit::TestCase
6
6
 
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require "helper"
3
+ require File.expand_path("helper", File.dirname(__FILE__))
4
4
 
5
5
  class TestErrorReplies < Test::Unit::TestCase
6
6
 
@@ -1,4 +1,5 @@
1
- $:.unshift File.expand_path('../lib', File.dirname(__FILE__))
1
+ $:.unshift File.expand_path("../lib", File.dirname(__FILE__))
2
+ $:.unshift File.expand_path(File.dirname(__FILE__))
2
3
 
3
4
  require "test/unit"
4
5
  require "logger"
@@ -153,6 +154,14 @@ module Helper
153
154
  def assert_in_range(range, value)
154
155
  assert range.include?(value), "expected #{value} to be in #{range.inspect}"
155
156
  end
157
+
158
+ def target_version(target)
159
+ if version < target
160
+ skip("Requires Redis > #{target}") if respond_to?(:skip)
161
+ else
162
+ yield
163
+ end
164
+ end
156
165
  end
157
166
 
158
167
  module Client
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require "helper"
3
+ require File.expand_path("helper", File.dirname(__FILE__))
4
4
 
5
5
  class TestHelper < Test::Unit::TestCase
6
6
 
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require "helper"
3
+ require File.expand_path("helper", File.dirname(__FILE__))
4
4
 
5
5
  class TestInternals < Test::Unit::TestCase
6
6
 
@@ -109,6 +109,17 @@ class TestInternals < Test::Unit::TestCase
109
109
  end
110
110
  end
111
111
 
112
+ def test_id_inside_multi
113
+ redis = Redis.new(OPTIONS)
114
+ id = nil
115
+
116
+ redis.multi do
117
+ id = redis.id
118
+ end
119
+
120
+ assert_equal id, "redis://127.0.0.1:6381/15"
121
+ end
122
+
112
123
  driver(:ruby) do
113
124
  def test_tcp_keepalive
114
125
  keepalive = {:time => 20, :intvl => 10, :probes => 5}
@@ -128,16 +139,16 @@ class TestInternals < Test::Unit::TestCase
128
139
  end
129
140
 
130
141
  def test_time
131
- return if version < "2.5.4"
132
-
133
- # Test that the difference between the time that Ruby reports and the time
134
- # that Redis reports is minimal (prevents the test from being racy).
135
- rv = r.time
142
+ target_version "2.5.4" do
143
+ # Test that the difference between the time that Ruby reports and the time
144
+ # that Redis reports is minimal (prevents the test from being racy).
145
+ rv = r.time
136
146
 
137
- redis_usec = rv[0] * 1_000_000 + rv[1]
138
- ruby_usec = Integer(Time.now.to_f * 1_000_000)
147
+ redis_usec = rv[0] * 1_000_000 + rv[1]
148
+ ruby_usec = Integer(Time.now.to_f * 1_000_000)
139
149
 
140
- assert 500_000 > (ruby_usec - redis_usec).abs
150
+ assert 500_000 > (ruby_usec - redis_usec).abs
151
+ end
141
152
  end
142
153
 
143
154
  def test_connection_timeout
@@ -31,18 +31,18 @@ module Lint
31
31
  end
32
32
 
33
33
  def test_variadic_hdel
34
- return if version < "2.3.9"
34
+ target_version "2.3.9" do
35
+ r.hset("foo", "f1", "s1")
36
+ r.hset("foo", "f2", "s2")
35
37
 
36
- r.hset("foo", "f1", "s1")
37
- r.hset("foo", "f2", "s2")
38
-
39
- assert_equal "s1", r.hget("foo", "f1")
40
- assert_equal "s2", r.hget("foo", "f2")
38
+ assert_equal "s1", r.hget("foo", "f1")
39
+ assert_equal "s2", r.hget("foo", "f2")
41
40
 
42
- assert_equal 2, r.hdel("foo", ["f1", "f2"])
41
+ assert_equal 2, r.hdel("foo", ["f1", "f2"])
43
42
 
44
- assert_equal nil, r.hget("foo", "f1")
45
- assert_equal nil, r.hget("foo", "f2")
43
+ assert_equal nil, r.hget("foo", "f1")
44
+ assert_equal nil, r.hget("foo", "f2")
45
+ end
46
46
  end
47
47
 
48
48
  def test_hexists
@@ -144,19 +144,19 @@ module Lint
144
144
  end
145
145
 
146
146
  def test_hincrbyfloat
147
- return if version < "2.5.4"
147
+ target_version "2.5.4" do
148
+ r.hincrbyfloat("foo", "f1", 1.23)
148
149
 
149
- r.hincrbyfloat("foo", "f1", 1.23)
150
+ assert_equal "1.23", r.hget("foo", "f1")
150
151
 
151
- assert_equal "1.23", r.hget("foo", "f1")
152
+ r.hincrbyfloat("foo", "f1", 0.77)
152
153
 
153
- r.hincrbyfloat("foo", "f1", 0.77)
154
+ assert_equal "2", r.hget("foo", "f1")
154
155
 
155
- assert_equal "2", r.hget("foo", "f1")
156
+ r.hincrbyfloat("foo", "f1", -0.1)
156
157
 
157
- r.hincrbyfloat("foo", "f1", -0.1)
158
-
159
- assert_equal "1.9", r.hget("foo", "f1")
158
+ assert_equal "1.9", r.hget("foo", "f1")
159
+ end
160
160
  end
161
161
  end
162
162
  end
@@ -11,11 +11,11 @@ module Lint
11
11
  end
12
12
 
13
13
  def test_variadic_lpush
14
- return if version < "2.3.9" # 2.4-rc6
15
-
16
- assert_equal 3, r.lpush("foo", ["s1", "s2", "s3"])
17
- assert_equal 3, r.llen("foo")
18
- assert_equal "s3", r.lpop("foo")
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
19
  end
20
20
 
21
21
  def test_lpushx
@@ -36,11 +36,11 @@ module Lint
36
36
  end
37
37
 
38
38
  def test_variadic_rpush
39
- return if version < "2.3.9" # 2.4-rc6
40
-
41
- assert_equal 3, r.rpush("foo", ["s1", "s2", "s3"])
42
- assert_equal 3, r.llen("foo")
43
- assert_equal "s3", r.rpop("foo")
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
44
  end
45
45
 
46
46
  def test_rpushx
@@ -11,12 +11,12 @@ module Lint
11
11
  end
12
12
 
13
13
  def test_variadic_sadd
14
- return if version < "2.3.9" # 2.4-rc6
14
+ target_version "2.3.9" do # 2.4-rc6
15
+ assert_equal 2, r.sadd("foo", ["s1", "s2"])
16
+ assert_equal 1, r.sadd("foo", ["s1", "s2", "s3"])
15
17
 
16
- assert_equal 2, r.sadd("foo", ["s1", "s2"])
17
- assert_equal 1, r.sadd("foo", ["s1", "s2", "s3"])
18
-
19
- assert_equal ["s1", "s2", "s3"], r.smembers("foo").sort
18
+ assert_equal ["s1", "s2", "s3"], r.smembers("foo").sort
19
+ end
20
20
  end
21
21
 
22
22
  def test_srem
@@ -30,17 +30,17 @@ module Lint
30
30
  end
31
31
 
32
32
  def test_variadic_srem
33
- return if version < "2.3.9" # 2.4-rc6
33
+ target_version "2.3.9" do # 2.4-rc6
34
+ r.sadd("foo", "s1")
35
+ r.sadd("foo", "s2")
36
+ r.sadd("foo", "s3")
34
37
 
35
- r.sadd("foo", "s1")
36
- r.sadd("foo", "s2")
37
- r.sadd("foo", "s3")
38
+ assert_equal 1, r.srem("foo", ["s1", "aaa"])
39
+ assert_equal 0, r.srem("foo", ["bbb", "ccc" "ddd"])
40
+ assert_equal 1, r.srem("foo", ["eee", "s3"])
38
41
 
39
- assert_equal 1, r.srem("foo", ["s1", "aaa"])
40
- assert_equal 0, r.srem("foo", ["bbb", "ccc" "ddd"])
41
- assert_equal 1, r.srem("foo", ["eee", "s3"])
42
-
43
- assert_equal ["s2"], r.smembers("foo")
42
+ assert_equal ["s2"], r.smembers("foo")
43
+ end
44
44
  end
45
45
 
46
46
  def test_spop
@@ -12,25 +12,25 @@ module Lint
12
12
  end
13
13
 
14
14
  def test_variadic_zadd
15
- return if version < "2.3.9" # 2.4-rc6
16
-
17
- # Non-nested array with pairs
18
- assert_equal 0, r.zcard("foo")
19
- assert_equal 2, r.zadd("foo", [1, "s1", 2, "s2"])
20
- assert_equal 1, r.zadd("foo", [4, "s1", 5, "s2", 6, "s3"])
21
- assert_equal 3, r.zcard("foo")
22
- r.del "foo"
23
-
24
- # Nested array with pairs
25
- assert_equal 0, r.zcard("foo")
26
- assert_equal 2, r.zadd("foo", [[1, "s1"], [2, "s2"]])
27
- assert_equal 1, r.zadd("foo", [[4, "s1"], [5, "s2"], [6, "s3"]])
28
- assert_equal 3, r.zcard("foo")
29
- r.del "foo"
30
-
31
- # Wrong number of arguments
32
- assert_raise(Redis::CommandError) { r.zadd("foo", ["bar"]) }
33
- assert_raise(Redis::CommandError) { r.zadd("foo", ["bar", "qux", "zap"]) }
15
+ target_version "2.3.9" do # 2.4-rc6
16
+ # Non-nested array with pairs
17
+ assert_equal 0, r.zcard("foo")
18
+ assert_equal 2, r.zadd("foo", [1, "s1", 2, "s2"])
19
+ assert_equal 1, r.zadd("foo", [4, "s1", 5, "s2", 6, "s3"])
20
+ assert_equal 3, r.zcard("foo")
21
+ r.del "foo"
22
+
23
+ # Nested array with pairs
24
+ assert_equal 0, r.zcard("foo")
25
+ assert_equal 2, r.zadd("foo", [[1, "s1"], [2, "s2"]])
26
+ assert_equal 1, r.zadd("foo", [[4, "s1"], [5, "s2"], [6, "s3"]])
27
+ assert_equal 3, r.zcard("foo")
28
+ r.del "foo"
29
+
30
+ # Wrong number of arguments
31
+ assert_raise(Redis::CommandError) { r.zadd("foo", ["bar"]) }
32
+ assert_raise(Redis::CommandError) { r.zadd("foo", ["bar", "qux", "zap"]) }
33
+ end
34
34
  end
35
35
 
36
36
  def test_zrem
@@ -44,17 +44,17 @@ module Lint
44
44
  end
45
45
 
46
46
  def test_variadic_zrem
47
- return if version < "2.3.9" # 2.4-rc6
48
-
49
- r.zadd("foo", 1, "s1")
50
- r.zadd("foo", 2, "s2")
51
- r.zadd("foo", 3, "s3")
52
-
53
- assert_equal 3, r.zcard("foo")
54
- assert_equal 1, r.zrem("foo", ["s1", "aaa"])
55
- assert_equal 0, r.zrem("foo", ["bbb", "ccc" "ddd"])
56
- assert_equal 1, r.zrem("foo", ["eee", "s3"])
57
- assert_equal 1, r.zcard("foo")
47
+ target_version "2.3.9" do # 2.4-rc6
48
+ r.zadd("foo", 1, "s1")
49
+ r.zadd("foo", 2, "s2")
50
+ r.zadd("foo", 3, "s3")
51
+
52
+ assert_equal 3, r.zcard("foo")
53
+ assert_equal 1, r.zrem("foo", ["s1", "aaa"])
54
+ assert_equal 0, r.zrem("foo", ["bbb", "ccc" "ddd"])
55
+ assert_equal 1, r.zrem("foo", ["eee", "s3"])
56
+ assert_equal 1, r.zcard("foo")
57
+ end
58
58
  end
59
59
 
60
60
  def test_zincrby
@@ -48,40 +48,40 @@ module Lint
48
48
  end
49
49
 
50
50
  def test_set_with_ex
51
- return if version < "2.6.12"
52
-
53
- r.set("foo", "bar", :ex => 2)
54
- assert_in_range 0..2, r.ttl("foo")
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
55
  end
56
56
 
57
57
  def test_set_with_px
58
- return if version < "2.6.12"
59
-
60
- r.set("foo", "bar", :px => 2000)
61
- assert_in_range 0..2, r.ttl("foo")
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
62
  end
63
63
 
64
64
  def test_set_with_nx
65
- return if version < "2.6.12"
66
-
67
- r.set("foo", "qux", :nx => true)
68
- assert !r.set("foo", "bar", :nx => true)
69
- assert_equal "qux", r.get("foo")
70
-
71
- r.del("foo")
72
- assert r.set("foo", "bar", :nx => true)
73
- assert_equal "bar", r.get("foo")
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
74
  end
75
75
 
76
76
  def test_set_with_xx
77
- return if version < "2.6.12"
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")
78
81
 
79
- r.set("foo", "qux")
80
- assert r.set("foo", "bar", :xx => true)
81
- assert_equal "bar", r.get("foo")
82
-
83
- r.del("foo")
84
- assert !r.set("foo", "bar", :xx => true)
82
+ r.del("foo")
83
+ assert !r.set("foo", "bar", :xx => true)
84
+ end
85
85
  end
86
86
 
87
87
  def test_setex
@@ -99,21 +99,21 @@ module Lint
99
99
  end
100
100
 
101
101
  def test_psetex
102
- return if version < "2.5.4"
103
-
104
- assert r.psetex("foo", 1000, "bar")
105
- assert_equal "bar", r.get("foo")
106
- assert [0, 1].include? r.ttl("foo")
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
107
  end
108
108
 
109
109
  def test_psetex_with_non_string_value
110
- return if version < "2.5.4"
110
+ target_version "2.5.4" do
111
+ value = ["b", "a", "r"]
111
112
 
112
- value = ["b", "a", "r"]
113
-
114
- assert r.psetex("foo", 1000, value)
115
- assert_equal value.to_s, r.get("foo")
116
- assert [0, 1].include? r.ttl("foo")
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
117
  end
118
118
 
119
119
  def test_getset
@@ -167,11 +167,11 @@ module Lint
167
167
  end
168
168
 
169
169
  def test_incrbyfloat
170
- return if version < "2.5.4"
171
-
172
- assert_equal 1.23, r.incrbyfloat("foo", 1.23)
173
- assert_equal 2 , r.incrbyfloat("foo", 0.77)
174
- assert_equal 1.9 , r.incrbyfloat("foo", -0.1)
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
175
  end
176
176
 
177
177
  def test_decr
@@ -218,12 +218,12 @@ module Lint
218
218
  end
219
219
 
220
220
  def test_bitcount
221
- return if version < "2.5.10"
221
+ target_version "2.5.10" do
222
+ r.set("foo", "abcde")
222
223
 
223
- r.set("foo", "abcde")
224
-
225
- assert_equal 10, r.bitcount("foo", 1, 3)
226
- assert_equal 17, r.bitcount("foo", 0, -1)
224
+ assert_equal 10, r.bitcount("foo", 1, 3)
225
+ assert_equal 17, r.bitcount("foo", 0, -1)
226
+ end
227
227
  end
228
228
 
229
229
  def test_getrange