redis 3.3.5 → 4.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +132 -2
  3. data/README.md +144 -79
  4. data/lib/redis.rb +1174 -405
  5. data/lib/redis/client.rb +150 -90
  6. data/lib/redis/cluster.rb +295 -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 +107 -0
  11. data/lib/redis/cluster/node_key.rb +31 -0
  12. data/lib/redis/cluster/node_loader.rb +37 -0
  13. data/lib/redis/cluster/option.rb +93 -0
  14. data/lib/redis/cluster/slot.rb +86 -0
  15. data/lib/redis/cluster/slot_loader.rb +49 -0
  16. data/lib/redis/connection.rb +4 -2
  17. data/lib/redis/connection/command_helper.rb +5 -10
  18. data/lib/redis/connection/hiredis.rb +6 -5
  19. data/lib/redis/connection/registry.rb +2 -1
  20. data/lib/redis/connection/ruby.rb +126 -128
  21. data/lib/redis/connection/synchrony.rb +21 -8
  22. data/lib/redis/distributed.rb +147 -72
  23. data/lib/redis/errors.rb +48 -0
  24. data/lib/redis/hash_ring.rb +30 -73
  25. data/lib/redis/pipeline.rb +55 -15
  26. data/lib/redis/subscribe.rb +11 -12
  27. data/lib/redis/version.rb +3 -1
  28. metadata +49 -202
  29. data/.gitignore +0 -16
  30. data/.travis.yml +0 -89
  31. data/.travis/Gemfile +0 -11
  32. data/.yardopts +0 -3
  33. data/Gemfile +0 -4
  34. data/Rakefile +0 -87
  35. data/benchmarking/logging.rb +0 -71
  36. data/benchmarking/pipeline.rb +0 -51
  37. data/benchmarking/speed.rb +0 -21
  38. data/benchmarking/suite.rb +0 -24
  39. data/benchmarking/worker.rb +0 -71
  40. data/examples/basic.rb +0 -15
  41. data/examples/consistency.rb +0 -114
  42. data/examples/dist_redis.rb +0 -43
  43. data/examples/incr-decr.rb +0 -17
  44. data/examples/list.rb +0 -26
  45. data/examples/pubsub.rb +0 -37
  46. data/examples/sentinel.rb +0 -41
  47. data/examples/sentinel/sentinel.conf +0 -9
  48. data/examples/sentinel/start +0 -49
  49. data/examples/sets.rb +0 -36
  50. data/examples/unicorn/config.ru +0 -3
  51. data/examples/unicorn/unicorn.rb +0 -20
  52. data/redis.gemspec +0 -44
  53. data/test/bitpos_test.rb +0 -69
  54. data/test/blocking_commands_test.rb +0 -42
  55. data/test/client_test.rb +0 -59
  56. data/test/command_map_test.rb +0 -30
  57. data/test/commands_on_hashes_test.rb +0 -21
  58. data/test/commands_on_hyper_log_log_test.rb +0 -21
  59. data/test/commands_on_lists_test.rb +0 -20
  60. data/test/commands_on_sets_test.rb +0 -77
  61. data/test/commands_on_sorted_sets_test.rb +0 -137
  62. data/test/commands_on_strings_test.rb +0 -101
  63. data/test/commands_on_value_types_test.rb +0 -133
  64. data/test/connection_handling_test.rb +0 -277
  65. data/test/connection_test.rb +0 -57
  66. data/test/db/.gitkeep +0 -0
  67. data/test/distributed_blocking_commands_test.rb +0 -46
  68. data/test/distributed_commands_on_hashes_test.rb +0 -10
  69. data/test/distributed_commands_on_hyper_log_log_test.rb +0 -33
  70. data/test/distributed_commands_on_lists_test.rb +0 -22
  71. data/test/distributed_commands_on_sets_test.rb +0 -83
  72. data/test/distributed_commands_on_sorted_sets_test.rb +0 -18
  73. data/test/distributed_commands_on_strings_test.rb +0 -59
  74. data/test/distributed_commands_on_value_types_test.rb +0 -95
  75. data/test/distributed_commands_requiring_clustering_test.rb +0 -164
  76. data/test/distributed_connection_handling_test.rb +0 -23
  77. data/test/distributed_internals_test.rb +0 -79
  78. data/test/distributed_key_tags_test.rb +0 -52
  79. data/test/distributed_persistence_control_commands_test.rb +0 -26
  80. data/test/distributed_publish_subscribe_test.rb +0 -92
  81. data/test/distributed_remote_server_control_commands_test.rb +0 -66
  82. data/test/distributed_scripting_test.rb +0 -102
  83. data/test/distributed_sorting_test.rb +0 -20
  84. data/test/distributed_test.rb +0 -58
  85. data/test/distributed_transactions_test.rb +0 -32
  86. data/test/encoding_test.rb +0 -18
  87. data/test/error_replies_test.rb +0 -59
  88. data/test/fork_safety_test.rb +0 -65
  89. data/test/helper.rb +0 -232
  90. data/test/helper_test.rb +0 -24
  91. data/test/internals_test.rb +0 -417
  92. data/test/lint/blocking_commands.rb +0 -150
  93. data/test/lint/hashes.rb +0 -162
  94. data/test/lint/hyper_log_log.rb +0 -60
  95. data/test/lint/lists.rb +0 -143
  96. data/test/lint/sets.rb +0 -140
  97. data/test/lint/sorted_sets.rb +0 -316
  98. data/test/lint/strings.rb +0 -260
  99. data/test/lint/value_types.rb +0 -122
  100. data/test/persistence_control_commands_test.rb +0 -26
  101. data/test/pipelining_commands_test.rb +0 -242
  102. data/test/publish_subscribe_test.rb +0 -282
  103. data/test/remote_server_control_commands_test.rb +0 -118
  104. data/test/scanning_test.rb +0 -413
  105. data/test/scripting_test.rb +0 -78
  106. data/test/sentinel_command_test.rb +0 -80
  107. data/test/sentinel_test.rb +0 -255
  108. data/test/sorting_test.rb +0 -59
  109. data/test/ssl_test.rb +0 -73
  110. data/test/support/connection/hiredis.rb +0 -1
  111. data/test/support/connection/ruby.rb +0 -1
  112. data/test/support/connection/synchrony.rb +0 -17
  113. data/test/support/redis_mock.rb +0 -130
  114. data/test/support/ssl/gen_certs.sh +0 -31
  115. data/test/support/ssl/trusted-ca.crt +0 -25
  116. data/test/support/ssl/trusted-ca.key +0 -27
  117. data/test/support/ssl/trusted-cert.crt +0 -81
  118. data/test/support/ssl/trusted-cert.key +0 -28
  119. data/test/support/ssl/untrusted-ca.crt +0 -26
  120. data/test/support/ssl/untrusted-ca.key +0 -27
  121. data/test/support/ssl/untrusted-cert.crt +0 -82
  122. data/test/support/ssl/untrusted-cert.key +0 -28
  123. data/test/support/wire/synchrony.rb +0 -24
  124. data/test/support/wire/thread.rb +0 -5
  125. data/test/synchrony_driver.rb +0 -88
  126. data/test/test.conf.erb +0 -9
  127. data/test/thread_safety_test.rb +0 -62
  128. data/test/transactions_test.rb +0 -264
  129. data/test/unknown_commands_test.rb +0 -14
  130. data/test/url_param_test.rb +0 -138
@@ -1,57 +0,0 @@
1
- require_relative "helper"
2
-
3
- class TestConnection < Test::Unit::TestCase
4
-
5
- include Helper::Client
6
-
7
- def test_provides_a_meaningful_inspect
8
- assert_equal "#<Redis client v#{Redis::VERSION} for redis://127.0.0.1:#{PORT}/15>", r.inspect
9
- end
10
-
11
- def test_connection_information
12
- assert_equal "127.0.0.1", r.connection.fetch(:host)
13
- assert_equal 6381, r.connection.fetch(:port)
14
- assert_equal 15, r.connection.fetch(:db)
15
- assert_equal "127.0.0.1:6381", r.connection.fetch(:location)
16
- assert_equal "redis://127.0.0.1:6381/15", r.connection.fetch(:id)
17
- end
18
-
19
- def test_default_id_with_host_and_port
20
- redis = Redis.new(OPTIONS.merge(:host => "host", :port => "1234", :db => 0))
21
- assert_equal "redis://host:1234/0", redis.connection.fetch(:id)
22
- end
23
-
24
- def test_default_id_with_host_and_port_and_explicit_scheme
25
- redis = Redis.new(OPTIONS.merge(:host => "host", :port => "1234", :db => 0, :scheme => "foo"))
26
- assert_equal "redis://host:1234/0", redis.connection.fetch(:id)
27
- end
28
-
29
- def test_default_id_with_path
30
- redis = Redis.new(OPTIONS.merge(:path => "/tmp/redis.sock", :db => 0))
31
- assert_equal "redis:///tmp/redis.sock/0", redis.connection.fetch(:id)
32
- end
33
-
34
- def test_default_id_with_path_and_explicit_scheme
35
- redis = Redis.new(OPTIONS.merge(:path => "/tmp/redis.sock", :db => 0, :scheme => "foo"))
36
- assert_equal "redis:///tmp/redis.sock/0", redis.connection.fetch(:id)
37
- end
38
-
39
- def test_override_id
40
- redis = Redis.new(OPTIONS.merge(:id => "test"))
41
- assert_equal "test", redis.connection.fetch(:id)
42
- end
43
-
44
- def test_id_inside_multi
45
- redis = Redis.new(OPTIONS)
46
- id = nil
47
- connection_id = nil
48
-
49
- redis.multi do
50
- id = redis.id
51
- connection_id = redis.connection.fetch(:id)
52
- end
53
-
54
- assert_equal "redis://127.0.0.1:6381/15", id
55
- assert_equal "redis://127.0.0.1:6381/15", connection_id
56
- end
57
- end
data/test/db/.gitkeep DELETED
File without changes
@@ -1,46 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
- require "lint/blocking_commands"
5
-
6
- class TestDistributedBlockingCommands < Test::Unit::TestCase
7
-
8
- include Helper::Distributed
9
- include Lint::BlockingCommands
10
-
11
- def test_blpop_raises
12
- assert_raises(Redis::Distributed::CannotDistribute) do
13
- r.blpop(["foo", "bar"])
14
- end
15
- end
16
-
17
- def test_blpop_raises_with_old_prototype
18
- assert_raises(Redis::Distributed::CannotDistribute) do
19
- r.blpop("foo", "bar", 0)
20
- end
21
- end
22
-
23
- def test_brpop_raises
24
- assert_raises(Redis::Distributed::CannotDistribute) do
25
- r.brpop(["foo", "bar"])
26
- end
27
- end
28
-
29
- def test_brpop_raises_with_old_prototype
30
- assert_raises(Redis::Distributed::CannotDistribute) do
31
- r.brpop("foo", "bar", 0)
32
- end
33
- end
34
-
35
- def test_brpoplpush_raises
36
- assert_raises(Redis::Distributed::CannotDistribute) do
37
- r.brpoplpush("foo", "bar")
38
- end
39
- end
40
-
41
- def test_brpoplpush_raises_with_old_prototype
42
- assert_raises(Redis::Distributed::CannotDistribute) do
43
- r.brpoplpush("foo", "bar", 0)
44
- end
45
- end
46
- end
@@ -1,10 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
- require "lint/hashes"
5
-
6
- class TestDistributedCommandsOnHashes < Test::Unit::TestCase
7
-
8
- include Helper::Distributed
9
- include Lint::Hashes
10
- end
@@ -1,33 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
- require "lint/hyper_log_log"
5
-
6
- class TestDistributedCommandsOnHyperLogLog < Test::Unit::TestCase
7
-
8
- include Helper::Distributed
9
- include Lint::HyperLogLog
10
-
11
- def test_pfmerge
12
- target_version "2.8.9" do
13
- assert_raise Redis::Distributed::CannotDistribute do
14
- r.pfadd "foo", "s1"
15
- r.pfadd "bar", "s2"
16
-
17
- assert r.pfmerge("res", "foo", "bar")
18
- end
19
- end
20
- end
21
-
22
- def test_pfcount_multiple_keys_diff_nodes
23
- target_version "2.8.9" do
24
- assert_raise Redis::Distributed::CannotDistribute do
25
- r.pfadd "foo", "s1"
26
- r.pfadd "bar", "s2"
27
-
28
- assert r.pfcount("res", "foo", "bar")
29
- end
30
- end
31
- end
32
-
33
- end
@@ -1,22 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
- require "lint/lists"
5
-
6
- class TestDistributedCommandsOnLists < Test::Unit::TestCase
7
-
8
- include Helper::Distributed
9
- include Lint::Lists
10
-
11
- def test_rpoplpush
12
- assert_raise Redis::Distributed::CannotDistribute do
13
- r.rpoplpush("foo", "bar")
14
- end
15
- end
16
-
17
- def test_brpoplpush
18
- assert_raise Redis::Distributed::CannotDistribute do
19
- r.brpoplpush("foo", "bar", :timeout => 1)
20
- end
21
- end
22
- end
@@ -1,83 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
- require "lint/sets"
5
-
6
- class TestDistributedCommandsOnSets < Test::Unit::TestCase
7
-
8
- include Helper::Distributed
9
- include Lint::Sets
10
-
11
- def test_smove
12
- assert_raise Redis::Distributed::CannotDistribute do
13
- r.sadd "foo", "s1"
14
- r.sadd "bar", "s2"
15
-
16
- r.smove("foo", "bar", "s1")
17
- end
18
- end
19
-
20
- def test_sinter
21
- assert_raise Redis::Distributed::CannotDistribute do
22
- r.sadd "foo", "s1"
23
- r.sadd "foo", "s2"
24
- r.sadd "bar", "s2"
25
-
26
- r.sinter("foo", "bar")
27
- end
28
- end
29
-
30
- def test_sinterstore
31
- assert_raise Redis::Distributed::CannotDistribute do
32
- r.sadd "foo", "s1"
33
- r.sadd "foo", "s2"
34
- r.sadd "bar", "s2"
35
-
36
- r.sinterstore("baz", "foo", "bar")
37
- end
38
- end
39
-
40
- def test_sunion
41
- assert_raise Redis::Distributed::CannotDistribute do
42
- r.sadd "foo", "s1"
43
- r.sadd "foo", "s2"
44
- r.sadd "bar", "s2"
45
- r.sadd "bar", "s3"
46
-
47
- r.sunion("foo", "bar")
48
- end
49
- end
50
-
51
- def test_sunionstore
52
- assert_raise Redis::Distributed::CannotDistribute do
53
- r.sadd "foo", "s1"
54
- r.sadd "foo", "s2"
55
- r.sadd "bar", "s2"
56
- r.sadd "bar", "s3"
57
-
58
- r.sunionstore("baz", "foo", "bar")
59
- end
60
- end
61
-
62
- def test_sdiff
63
- assert_raise Redis::Distributed::CannotDistribute do
64
- r.sadd "foo", "s1"
65
- r.sadd "foo", "s2"
66
- r.sadd "bar", "s2"
67
- r.sadd "bar", "s3"
68
-
69
- r.sdiff("foo", "bar")
70
- end
71
- end
72
-
73
- def test_sdiffstore
74
- assert_raise Redis::Distributed::CannotDistribute do
75
- r.sadd "foo", "s1"
76
- r.sadd "foo", "s2"
77
- r.sadd "bar", "s2"
78
- r.sadd "bar", "s3"
79
-
80
- r.sdiffstore("baz", "foo", "bar")
81
- end
82
- end
83
- end
@@ -1,18 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
- require "lint/sorted_sets"
5
-
6
- class TestDistributedCommandsOnSortedSets < Test::Unit::TestCase
7
-
8
- include Helper::Distributed
9
- include Lint::SortedSets
10
-
11
- def test_zcount
12
- r.zadd "foo", 1, "s1"
13
- r.zadd "foo", 2, "s2"
14
- r.zadd "foo", 3, "s3"
15
-
16
- assert_equal 2, r.zcount("foo", 2, 3)
17
- end
18
- end
@@ -1,59 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
- require "lint/strings"
5
-
6
- class TestDistributedCommandsOnStrings < Test::Unit::TestCase
7
-
8
- include Helper::Distributed
9
- include Lint::Strings
10
-
11
- def test_mget
12
- assert_raise Redis::Distributed::CannotDistribute do
13
- r.mget("foo", "bar")
14
- end
15
- end
16
-
17
- def test_mget_mapped
18
- assert_raise Redis::Distributed::CannotDistribute do
19
- r.mapped_mget("foo", "bar")
20
- end
21
- end
22
-
23
- def test_mset
24
- assert_raise Redis::Distributed::CannotDistribute do
25
- r.mset(:foo, "s1", :bar, "s2")
26
- end
27
- end
28
-
29
- def test_mset_mapped
30
- assert_raise Redis::Distributed::CannotDistribute do
31
- r.mapped_mset(:foo => "s1", :bar => "s2")
32
- end
33
- end
34
-
35
- def test_msetnx
36
- assert_raise Redis::Distributed::CannotDistribute do
37
- r.set("foo", "s1")
38
- r.msetnx(:foo, "s2", :bar, "s3")
39
- end
40
- end
41
-
42
- def test_msetnx_mapped
43
- assert_raise Redis::Distributed::CannotDistribute do
44
- r.set("foo", "s1")
45
- r.mapped_msetnx(:foo => "s2", :bar => "s3")
46
- end
47
- end
48
-
49
- def test_bitop
50
- target_version "2.5.10" do
51
- assert_raise Redis::Distributed::CannotDistribute do
52
- r.set("foo", "a")
53
- r.set("bar", "b")
54
-
55
- r.bitop(:and, "foo&bar", "foo", "bar")
56
- end
57
- end
58
- end
59
- end
@@ -1,95 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
- require "lint/value_types"
5
-
6
- class TestDistributedCommandsOnValueTypes < Test::Unit::TestCase
7
-
8
- include Helper::Distributed
9
- include Lint::ValueTypes
10
-
11
- def test_del
12
- r.set "foo", "s1"
13
- r.set "bar", "s2"
14
- r.set "baz", "s3"
15
-
16
- assert_equal ["bar", "baz", "foo"], r.keys("*").sort
17
-
18
- assert_equal 1, r.del("foo")
19
-
20
- assert_equal ["bar", "baz"], r.keys("*").sort
21
-
22
- assert_equal 2, r.del("bar", "baz")
23
-
24
- assert_equal [], r.keys("*").sort
25
- end
26
-
27
- def test_del_with_array_argument
28
- r.set "foo", "s1"
29
- r.set "bar", "s2"
30
- r.set "baz", "s3"
31
-
32
- assert_equal ["bar", "baz", "foo"], r.keys("*").sort
33
-
34
- assert_equal 1, r.del(["foo"])
35
-
36
- assert_equal ["bar", "baz"], r.keys("*").sort
37
-
38
- assert_equal 2, r.del(["bar", "baz"])
39
-
40
- assert_equal [], r.keys("*").sort
41
- end
42
-
43
- def test_randomkey
44
- assert_raise Redis::Distributed::CannotDistribute do
45
- r.randomkey
46
- end
47
- end
48
-
49
- def test_rename
50
- assert_raise Redis::Distributed::CannotDistribute do
51
- r.set("foo", "s1")
52
- r.rename "foo", "bar"
53
- end
54
-
55
- assert_equal "s1", r.get("foo")
56
- assert_equal nil, r.get("bar")
57
- end
58
-
59
- def test_renamenx
60
- assert_raise Redis::Distributed::CannotDistribute do
61
- r.set("foo", "s1")
62
- r.rename "foo", "bar"
63
- end
64
-
65
- assert_equal "s1", r.get("foo")
66
- assert_equal nil , r.get("bar")
67
- end
68
-
69
- def test_dbsize
70
- assert_equal [0], r.dbsize
71
-
72
- r.set("foo", "s1")
73
-
74
- assert_equal [1], r.dbsize
75
- end
76
-
77
- def test_flushdb
78
- r.set("foo", "s1")
79
- r.set("bar", "s2")
80
-
81
- assert_equal [2], r.dbsize
82
-
83
- r.flushdb
84
-
85
- assert_equal [0], r.dbsize
86
- end
87
-
88
- def test_migrate
89
- r.set("foo", "s1")
90
-
91
- assert_raise Redis::Distributed::CannotDistribute do
92
- r.migrate("foo", {})
93
- end
94
- end
95
- end
@@ -1,164 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
-
5
- class TestDistributedCommandsRequiringClustering < Test::Unit::TestCase
6
-
7
- include Helper::Distributed
8
-
9
- def test_rename
10
- r.set("{qux}foo", "s1")
11
- r.rename "{qux}foo", "{qux}bar"
12
-
13
- assert_equal "s1", r.get("{qux}bar")
14
- assert_equal nil, r.get("{qux}foo")
15
- end
16
-
17
- def test_renamenx
18
- r.set("{qux}foo", "s1")
19
- r.set("{qux}bar", "s2")
20
-
21
- assert_equal false, r.renamenx("{qux}foo", "{qux}bar")
22
-
23
- assert_equal "s1", r.get("{qux}foo")
24
- assert_equal "s2", r.get("{qux}bar")
25
- end
26
-
27
- def test_brpoplpush
28
- r.rpush "{qux}foo", "s1"
29
- r.rpush "{qux}foo", "s2"
30
-
31
- assert_equal "s2", r.brpoplpush("{qux}foo", "{qux}bar", :timeout => 1)
32
- assert_equal ["s2"], r.lrange("{qux}bar", 0, -1)
33
- end
34
-
35
- def test_rpoplpush
36
- r.rpush "{qux}foo", "s1"
37
- r.rpush "{qux}foo", "s2"
38
-
39
- assert_equal "s2", r.rpoplpush("{qux}foo", "{qux}bar")
40
- assert_equal ["s2"], r.lrange("{qux}bar", 0, -1)
41
- assert_equal "s1", r.rpoplpush("{qux}foo", "{qux}bar")
42
- assert_equal ["s1", "s2"], r.lrange("{qux}bar", 0, -1)
43
- end
44
-
45
- def test_smove
46
- r.sadd "{qux}foo", "s1"
47
- r.sadd "{qux}bar", "s2"
48
-
49
- assert r.smove("{qux}foo", "{qux}bar", "s1")
50
- assert r.sismember("{qux}bar", "s1")
51
- end
52
-
53
- def test_sinter
54
- r.sadd "{qux}foo", "s1"
55
- r.sadd "{qux}foo", "s2"
56
- r.sadd "{qux}bar", "s2"
57
-
58
- assert_equal ["s2"], r.sinter("{qux}foo", "{qux}bar")
59
- end
60
-
61
- def test_sinterstore
62
- r.sadd "{qux}foo", "s1"
63
- r.sadd "{qux}foo", "s2"
64
- r.sadd "{qux}bar", "s2"
65
-
66
- r.sinterstore("{qux}baz", "{qux}foo", "{qux}bar")
67
-
68
- assert_equal ["s2"], r.smembers("{qux}baz")
69
- end
70
-
71
- def test_sunion
72
- r.sadd "{qux}foo", "s1"
73
- r.sadd "{qux}foo", "s2"
74
- r.sadd "{qux}bar", "s2"
75
- r.sadd "{qux}bar", "s3"
76
-
77
- assert_equal ["s1", "s2", "s3"], r.sunion("{qux}foo", "{qux}bar").sort
78
- end
79
-
80
- def test_sunionstore
81
- r.sadd "{qux}foo", "s1"
82
- r.sadd "{qux}foo", "s2"
83
- r.sadd "{qux}bar", "s2"
84
- r.sadd "{qux}bar", "s3"
85
-
86
- r.sunionstore("{qux}baz", "{qux}foo", "{qux}bar")
87
-
88
- assert_equal ["s1", "s2", "s3"], r.smembers("{qux}baz").sort
89
- end
90
-
91
- def test_sdiff
92
- r.sadd "{qux}foo", "s1"
93
- r.sadd "{qux}foo", "s2"
94
- r.sadd "{qux}bar", "s2"
95
- r.sadd "{qux}bar", "s3"
96
-
97
- assert_equal ["s1"], r.sdiff("{qux}foo", "{qux}bar")
98
- assert_equal ["s3"], r.sdiff("{qux}bar", "{qux}foo")
99
- end
100
-
101
- def test_sdiffstore
102
- r.sadd "{qux}foo", "s1"
103
- r.sadd "{qux}foo", "s2"
104
- r.sadd "{qux}bar", "s2"
105
- r.sadd "{qux}bar", "s3"
106
-
107
- r.sdiffstore("{qux}baz", "{qux}foo", "{qux}bar")
108
-
109
- assert_equal ["s1"], r.smembers("{qux}baz")
110
- end
111
-
112
- def test_sort
113
- r.set("{qux}foo:1", "s1")
114
- r.set("{qux}foo:2", "s2")
115
-
116
- r.rpush("{qux}bar", "1")
117
- r.rpush("{qux}bar", "2")
118
-
119
- assert_equal ["s1"], r.sort("{qux}bar", :get => "{qux}foo:*", :limit => [0, 1])
120
- assert_equal ["s2"], r.sort("{qux}bar", :get => "{qux}foo:*", :limit => [0, 1], :order => "desc alpha")
121
- end
122
-
123
- def test_sort_with_an_array_of_gets
124
- r.set("{qux}foo:1:a", "s1a")
125
- r.set("{qux}foo:1:b", "s1b")
126
-
127
- r.set("{qux}foo:2:a", "s2a")
128
- r.set("{qux}foo:2:b", "s2b")
129
-
130
- r.rpush("{qux}bar", "1")
131
- r.rpush("{qux}bar", "2")
132
-
133
- assert_equal [["s1a", "s1b"]], r.sort("{qux}bar", :get => ["{qux}foo:*:a", "{qux}foo:*:b"], :limit => [0, 1])
134
- assert_equal [["s2a", "s2b"]], r.sort("{qux}bar", :get => ["{qux}foo:*:a", "{qux}foo:*:b"], :limit => [0, 1], :order => "desc alpha")
135
- assert_equal [["s1a", "s1b"], ["s2a", "s2b"]], r.sort("{qux}bar", :get => ["{qux}foo:*:a", "{qux}foo:*:b"])
136
- end
137
-
138
- def test_sort_with_store
139
- r.set("{qux}foo:1", "s1")
140
- r.set("{qux}foo:2", "s2")
141
-
142
- r.rpush("{qux}bar", "1")
143
- r.rpush("{qux}bar", "2")
144
-
145
- r.sort("{qux}bar", :get => "{qux}foo:*", :store => "{qux}baz")
146
- assert_equal ["s1", "s2"], r.lrange("{qux}baz", 0, -1)
147
- end
148
-
149
- def test_bitop
150
- target_version "2.5.10" do
151
- r.set("{qux}foo", "a")
152
- r.set("{qux}bar", "b")
153
-
154
- r.bitop(:and, "{qux}foo&bar", "{qux}foo", "{qux}bar")
155
- assert_equal "\x60", r.get("{qux}foo&bar")
156
- r.bitop(:or, "{qux}foo|bar", "{qux}foo", "{qux}bar")
157
- assert_equal "\x63", r.get("{qux}foo|bar")
158
- r.bitop(:xor, "{qux}foo^bar", "{qux}foo", "{qux}bar")
159
- assert_equal "\x03", r.get("{qux}foo^bar")
160
- r.bitop(:not, "{qux}~foo", "{qux}foo")
161
- assert_equal "\x9E", r.get("{qux}~foo")
162
- end
163
- end
164
- end