redis 3.3.5 → 4.0.3

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 (127) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.travis/Gemfile +8 -1
  4. data/.travis.yml +34 -62
  5. data/CHANGELOG.md +45 -2
  6. data/Gemfile +5 -1
  7. data/README.md +32 -76
  8. data/benchmarking/logging.rb +1 -1
  9. data/bin/build +71 -0
  10. data/bors.toml +14 -0
  11. data/lib/redis/client.rb +38 -20
  12. data/lib/redis/cluster/command.rb +81 -0
  13. data/lib/redis/cluster/command_loader.rb +32 -0
  14. data/lib/redis/cluster/key_slot_converter.rb +72 -0
  15. data/lib/redis/cluster/node.rb +104 -0
  16. data/lib/redis/cluster/node_key.rb +35 -0
  17. data/lib/redis/cluster/node_loader.rb +35 -0
  18. data/lib/redis/cluster/option.rb +76 -0
  19. data/lib/redis/cluster/slot.rb +69 -0
  20. data/lib/redis/cluster/slot_loader.rb +47 -0
  21. data/lib/redis/cluster.rb +285 -0
  22. data/lib/redis/connection/command_helper.rb +2 -8
  23. data/lib/redis/connection/hiredis.rb +2 -2
  24. data/lib/redis/connection/ruby.rb +13 -30
  25. data/lib/redis/connection/synchrony.rb +12 -4
  26. data/lib/redis/connection.rb +2 -2
  27. data/lib/redis/distributed.rb +29 -8
  28. data/lib/redis/errors.rb +46 -0
  29. data/lib/redis/hash_ring.rb +20 -64
  30. data/lib/redis/pipeline.rb +9 -7
  31. data/lib/redis/version.rb +1 -1
  32. data/lib/redis.rb +287 -52
  33. data/makefile +74 -0
  34. data/redis.gemspec +9 -10
  35. data/test/bitpos_test.rb +13 -19
  36. data/test/blocking_commands_test.rb +3 -5
  37. data/test/client_test.rb +18 -1
  38. data/test/cluster_abnormal_state_test.rb +38 -0
  39. data/test/cluster_blocking_commands_test.rb +15 -0
  40. data/test/cluster_client_internals_test.rb +77 -0
  41. data/test/cluster_client_key_hash_tags_test.rb +88 -0
  42. data/test/cluster_client_options_test.rb +147 -0
  43. data/test/cluster_client_pipelining_test.rb +59 -0
  44. data/test/cluster_client_replicas_test.rb +36 -0
  45. data/test/cluster_client_slots_test.rb +94 -0
  46. data/test/cluster_client_transactions_test.rb +71 -0
  47. data/test/cluster_commands_on_cluster_test.rb +165 -0
  48. data/test/cluster_commands_on_connection_test.rb +40 -0
  49. data/test/cluster_commands_on_geo_test.rb +74 -0
  50. data/test/cluster_commands_on_hashes_test.rb +11 -0
  51. data/test/cluster_commands_on_hyper_log_log_test.rb +17 -0
  52. data/test/cluster_commands_on_keys_test.rb +134 -0
  53. data/test/cluster_commands_on_lists_test.rb +15 -0
  54. data/test/cluster_commands_on_pub_sub_test.rb +101 -0
  55. data/test/cluster_commands_on_scripting_test.rb +56 -0
  56. data/test/cluster_commands_on_server_test.rb +221 -0
  57. data/test/cluster_commands_on_sets_test.rb +39 -0
  58. data/test/cluster_commands_on_sorted_sets_test.rb +35 -0
  59. data/test/cluster_commands_on_streams_test.rb +196 -0
  60. data/test/cluster_commands_on_strings_test.rb +15 -0
  61. data/test/cluster_commands_on_transactions_test.rb +41 -0
  62. data/test/cluster_commands_on_value_types_test.rb +14 -0
  63. data/test/command_map_test.rb +3 -5
  64. data/test/commands_on_geo_test.rb +116 -0
  65. data/test/commands_on_hashes_test.rb +2 -16
  66. data/test/commands_on_hyper_log_log_test.rb +3 -17
  67. data/test/commands_on_lists_test.rb +2 -15
  68. data/test/commands_on_sets_test.rb +2 -72
  69. data/test/commands_on_sorted_sets_test.rb +2 -132
  70. data/test/commands_on_strings_test.rb +2 -96
  71. data/test/commands_on_value_types_test.rb +80 -6
  72. data/test/connection_handling_test.rb +5 -7
  73. data/test/distributed_blocking_commands_test.rb +10 -4
  74. data/test/distributed_commands_on_hashes_test.rb +16 -5
  75. data/test/distributed_commands_on_hyper_log_log_test.rb +8 -15
  76. data/test/distributed_commands_on_lists_test.rb +4 -7
  77. data/test/distributed_commands_on_sets_test.rb +58 -36
  78. data/test/distributed_commands_on_sorted_sets_test.rb +51 -10
  79. data/test/distributed_commands_on_strings_test.rb +30 -10
  80. data/test/distributed_commands_on_value_types_test.rb +38 -4
  81. data/test/distributed_commands_requiring_clustering_test.rb +1 -3
  82. data/test/distributed_connection_handling_test.rb +1 -3
  83. data/test/distributed_internals_test.rb +8 -19
  84. data/test/distributed_key_tags_test.rb +4 -6
  85. data/test/distributed_persistence_control_commands_test.rb +1 -3
  86. data/test/distributed_publish_subscribe_test.rb +1 -3
  87. data/test/distributed_remote_server_control_commands_test.rb +1 -3
  88. data/test/distributed_scripting_test.rb +1 -3
  89. data/test/distributed_sorting_test.rb +1 -3
  90. data/test/distributed_test.rb +12 -14
  91. data/test/distributed_transactions_test.rb +1 -3
  92. data/test/encoding_test.rb +4 -8
  93. data/test/error_replies_test.rb +2 -4
  94. data/test/fork_safety_test.rb +1 -6
  95. data/test/helper.rb +179 -66
  96. data/test/helper_test.rb +1 -3
  97. data/test/internals_test.rb +47 -56
  98. data/test/lint/blocking_commands.rb +40 -16
  99. data/test/lint/hashes.rb +41 -0
  100. data/test/lint/hyper_log_log.rb +15 -1
  101. data/test/lint/lists.rb +16 -0
  102. data/test/lint/sets.rb +142 -0
  103. data/test/lint/sorted_sets.rb +183 -2
  104. data/test/lint/strings.rb +108 -20
  105. data/test/lint/value_types.rb +8 -0
  106. data/test/persistence_control_commands_test.rb +1 -3
  107. data/test/pipelining_commands_test.rb +12 -8
  108. data/test/publish_subscribe_test.rb +1 -3
  109. data/test/remote_server_control_commands_test.rb +60 -3
  110. data/test/scanning_test.rb +1 -7
  111. data/test/scripting_test.rb +1 -3
  112. data/test/sentinel_command_test.rb +1 -3
  113. data/test/sentinel_test.rb +1 -3
  114. data/test/sorting_test.rb +1 -3
  115. data/test/ssl_test.rb +45 -49
  116. data/test/support/cluster/orchestrator.rb +199 -0
  117. data/test/support/connection/hiredis.rb +1 -1
  118. data/test/support/connection/ruby.rb +1 -1
  119. data/test/support/connection/synchrony.rb +1 -1
  120. data/test/support/redis_mock.rb +1 -1
  121. data/test/synchrony_driver.rb +6 -9
  122. data/test/thread_safety_test.rb +1 -3
  123. data/test/transactions_test.rb +11 -3
  124. data/test/unknown_commands_test.rb +1 -3
  125. data/test/url_param_test.rb +44 -46
  126. metadata +109 -16
  127. data/Rakefile +0 -87
@@ -0,0 +1,116 @@
1
+ require_relative "helper"
2
+
3
+ class TestCommandsGeo < Test::Unit::TestCase
4
+ include Helper::Client
5
+
6
+ def setup
7
+ super
8
+
9
+ target_version "3.2.0" do
10
+ added_items_count = r.geoadd("Sicily", 13.361389, 38.115556, "Palermo", 15.087269, 37.502669, "Catania")
11
+ assert_equal 2, added_items_count
12
+ end
13
+ end
14
+
15
+ def test_georadius_with_sort
16
+ target_version "3.2.0" do
17
+ nearest_cities = r.georadius("Sicily", 15, 37, 200, 'km', sort: 'asc')
18
+ assert_equal %w(Catania Palermo), nearest_cities
19
+
20
+ farthest_cities = r.georadius("Sicily", 15, 37, 200, 'km', sort: 'desc')
21
+ assert_equal %w(Palermo Catania), farthest_cities
22
+ end
23
+ end
24
+
25
+ def test_georadius_with_count
26
+ target_version "3.2.0" do
27
+ city = r.georadius("Sicily", 15, 37, 200, 'km', count: 1)
28
+ assert_equal %w(Catania), city
29
+ end
30
+ end
31
+
32
+ def test_georadius_with_options_count_sort
33
+ target_version "3.2.0" do
34
+ city = r.georadius("Sicily", 15, 37, 200, 'km', sort: :desc, options: :WITHDIST, count: 1)
35
+ assert_equal [["Palermo", "190.4424"]], city
36
+ end
37
+ end
38
+
39
+ def test_georadiusbymember_with_sort
40
+ target_version "3.2.0" do
41
+ nearest_cities = r.georadiusbymember("Sicily", "Catania", 200, 'km', sort: 'asc')
42
+ assert_equal %w(Catania Palermo), nearest_cities
43
+
44
+ farthest_cities = r.georadiusbymember("Sicily", "Catania", 200, 'km', sort: 'desc')
45
+ assert_equal %w(Palermo Catania), farthest_cities
46
+ end
47
+ end
48
+
49
+ def test_georadiusbymember_with_count
50
+ target_version "3.2.0" do
51
+ city = r.georadiusbymember("Sicily", "Catania", 200, 'km', count: 1)
52
+ assert_equal %w(Catania), city
53
+ end
54
+ end
55
+
56
+ def test_georadiusbymember_with_options_count_sort
57
+ target_version "3.2.0" do
58
+ city = r.georadiusbymember("Sicily", "Catania", 200, 'km', sort: :desc, options: :WITHDIST, count: 1)
59
+ assert_equal [["Palermo", "166.2742"]], city
60
+ end
61
+ end
62
+
63
+ def test_geopos
64
+ target_version "3.2.0" do
65
+ location = r.geopos("Sicily", "Catania")
66
+ assert_equal [["15.08726745843887329", "37.50266842333162032"]], location
67
+
68
+ locations = r.geopos("Sicily", ["Palermo", "Catania"])
69
+ assert_equal [["13.36138933897018433", "38.11555639549629859"], ["15.08726745843887329", "37.50266842333162032"]], locations
70
+ end
71
+ end
72
+
73
+ def test_geopos_nonexistant_location
74
+ target_version "3.2.0" do
75
+ location = r.geopos("Sicily", "Rome")
76
+ assert_equal [nil], location
77
+
78
+ locations = r.geopos("Sicily", ["Rome", "Catania"])
79
+ assert_equal [nil, ["15.08726745843887329", "37.50266842333162032"]], locations
80
+ end
81
+ end
82
+
83
+ def test_geodist
84
+ target_version "3.2.0" do
85
+ distination_in_meters = r.geodist("Sicily", "Palermo", "Catania")
86
+ assert_equal "166274.1516", distination_in_meters
87
+
88
+ distination_in_feet = r.geodist("Sicily", "Palermo", "Catania", 'ft')
89
+ assert_equal "545518.8700", distination_in_feet
90
+ end
91
+ end
92
+
93
+ def test_geodist_with_nonexistant_location
94
+ target_version "3.2.0" do
95
+ distination = r.geodist("Sicily", "Palermo", "Rome")
96
+ assert_equal nil, distination
97
+ end
98
+ end
99
+
100
+ def test_geohash
101
+ target_version "3.2.0" do
102
+ geohash = r.geohash("Sicily", "Palermo")
103
+ assert_equal ["sqc8b49rny0"], geohash
104
+
105
+ geohashes = r.geohash("Sicily", ["Palermo", "Catania"])
106
+ assert_equal %w(sqc8b49rny0 sqdtr74hyu0), geohashes
107
+ end
108
+ end
109
+
110
+ def test_geohash_with_nonexistant_location
111
+ target_version "3.2.0" do
112
+ geohashes = r.geohash("Sicily", ["Palermo", "Rome"])
113
+ assert_equal ["sqc8b49rny0", nil], geohashes
114
+ end
115
+ end
116
+ end
@@ -1,21 +1,7 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
- require "lint/hashes"
1
+ require_relative 'helper'
2
+ require_relative 'lint/hashes'
5
3
 
6
4
  class TestCommandsOnHashes < Test::Unit::TestCase
7
-
8
5
  include Helper::Client
9
6
  include Lint::Hashes
10
-
11
- def test_mapped_hmget_in_a_pipeline_returns_hash
12
- r.hset("foo", "f1", "s1")
13
- r.hset("foo", "f2", "s2")
14
-
15
- result = r.pipelined do
16
- r.mapped_hmget("foo", "f1", "f2")
17
- end
18
-
19
- assert_equal result[0], { "f1" => "s1", "f2" => "s2" }
20
- end
21
7
  end
@@ -1,21 +1,7 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
- require "lint/hyper_log_log"
1
+ require_relative 'helper'
2
+ require_relative 'lint/hyper_log_log'
5
3
 
6
4
  class TestCommandsOnHyperLogLog < Test::Unit::TestCase
7
-
8
5
  include Helper::Client
9
6
  include Lint::HyperLogLog
10
-
11
- def test_pfmerge
12
- target_version "2.8.9" do
13
- r.pfadd "foo", "s1"
14
- r.pfadd "bar", "s2"
15
-
16
- assert_equal true, r.pfmerge("res", "foo", "bar")
17
- assert_equal 2, r.pfcount("res")
18
- end
19
- end
20
-
21
- end
7
+ end
@@ -1,20 +1,7 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
- require "lint/lists"
1
+ require_relative 'helper'
2
+ require_relative 'lint/lists'
5
3
 
6
4
  class TestCommandsOnLists < Test::Unit::TestCase
7
-
8
5
  include Helper::Client
9
6
  include Lint::Lists
10
-
11
- def test_rpoplpush
12
- r.rpush "foo", "s1"
13
- r.rpush "foo", "s2"
14
-
15
- assert_equal "s2", r.rpoplpush("foo", "bar")
16
- assert_equal ["s2"], r.lrange("bar", 0, -1)
17
- assert_equal "s1", r.rpoplpush("foo", "bar")
18
- assert_equal ["s1", "s2"], r.lrange("bar", 0, -1)
19
- end
20
7
  end
@@ -1,77 +1,7 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
- require "lint/sets"
1
+ require_relative 'helper'
2
+ require_relative 'lint/sets'
5
3
 
6
4
  class TestCommandsOnSets < Test::Unit::TestCase
7
-
8
5
  include Helper::Client
9
6
  include Lint::Sets
10
-
11
- def test_smove
12
- r.sadd "foo", "s1"
13
- r.sadd "bar", "s2"
14
-
15
- assert r.smove("foo", "bar", "s1")
16
- assert r.sismember("bar", "s1")
17
- end
18
-
19
- def test_sinter
20
- r.sadd "foo", "s1"
21
- r.sadd "foo", "s2"
22
- r.sadd "bar", "s2"
23
-
24
- assert_equal ["s2"], r.sinter("foo", "bar")
25
- end
26
-
27
- def test_sinterstore
28
- r.sadd "foo", "s1"
29
- r.sadd "foo", "s2"
30
- r.sadd "bar", "s2"
31
-
32
- r.sinterstore("baz", "foo", "bar")
33
-
34
- assert_equal ["s2"], r.smembers("baz")
35
- end
36
-
37
- def test_sunion
38
- r.sadd "foo", "s1"
39
- r.sadd "foo", "s2"
40
- r.sadd "bar", "s2"
41
- r.sadd "bar", "s3"
42
-
43
- assert_equal ["s1", "s2", "s3"], r.sunion("foo", "bar").sort
44
- end
45
-
46
- def test_sunionstore
47
- r.sadd "foo", "s1"
48
- r.sadd "foo", "s2"
49
- r.sadd "bar", "s2"
50
- r.sadd "bar", "s3"
51
-
52
- r.sunionstore("baz", "foo", "bar")
53
-
54
- assert_equal ["s1", "s2", "s3"], r.smembers("baz").sort
55
- end
56
-
57
- def test_sdiff
58
- r.sadd "foo", "s1"
59
- r.sadd "foo", "s2"
60
- r.sadd "bar", "s2"
61
- r.sadd "bar", "s3"
62
-
63
- assert_equal ["s1"], r.sdiff("foo", "bar")
64
- assert_equal ["s3"], r.sdiff("bar", "foo")
65
- end
66
-
67
- def test_sdiffstore
68
- r.sadd "foo", "s1"
69
- r.sadd "foo", "s2"
70
- r.sadd "bar", "s2"
71
- r.sadd "bar", "s3"
72
-
73
- r.sdiffstore("baz", "foo", "bar")
74
-
75
- assert_equal ["s1"], r.smembers("baz")
76
- end
77
7
  end
@@ -1,137 +1,7 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
- require "lint/sorted_sets"
1
+ require_relative 'helper'
2
+ require_relative 'lint/sorted_sets'
5
3
 
6
4
  class TestCommandsOnSortedSets < Test::Unit::TestCase
7
-
8
5
  include Helper::Client
9
6
  include Lint::SortedSets
10
-
11
- def test_zrangebylex
12
- target_version "2.8.9" do
13
- r.zadd "foo", 0, "aaren"
14
- r.zadd "foo", 0, "abagael"
15
- r.zadd "foo", 0, "abby"
16
- r.zadd "foo", 0, "abbygail"
17
-
18
- assert_equal ["aaren", "abagael", "abby", "abbygail"], r.zrangebylex("foo", "[a", "[a\xff")
19
- assert_equal ["aaren", "abagael"], r.zrangebylex("foo", "[a", "[a\xff", :limit => [0, 2])
20
- assert_equal ["abby", "abbygail"], r.zrangebylex("foo", "(abb", "(abb\xff")
21
- assert_equal ["abbygail"], r.zrangebylex("foo", "(abby", "(abby\xff")
22
- end
23
- end
24
-
25
- def test_zrevrangebylex
26
- target_version "2.9.9" do
27
- r.zadd "foo", 0, "aaren"
28
- r.zadd "foo", 0, "abagael"
29
- r.zadd "foo", 0, "abby"
30
- r.zadd "foo", 0, "abbygail"
31
-
32
- assert_equal ["abbygail", "abby", "abagael", "aaren"], r.zrevrangebylex("foo", "[a\xff", "[a")
33
- assert_equal ["abbygail", "abby"], r.zrevrangebylex("foo", "[a\xff", "[a", :limit => [0, 2])
34
- assert_equal ["abbygail", "abby"], r.zrevrangebylex("foo", "(abb\xff", "(abb")
35
- assert_equal ["abbygail"], r.zrevrangebylex("foo", "(abby\xff", "(abby")
36
- end
37
- end
38
-
39
- def test_zcount
40
- r.zadd "foo", 1, "s1"
41
- r.zadd "foo", 2, "s2"
42
- r.zadd "foo", 3, "s3"
43
-
44
- assert_equal 2, r.zcount("foo", 2, 3)
45
- end
46
-
47
- def test_zunionstore
48
- r.zadd "foo", 1, "s1"
49
- r.zadd "bar", 2, "s2"
50
- r.zadd "foo", 3, "s3"
51
- r.zadd "bar", 4, "s4"
52
-
53
- assert_equal 4, r.zunionstore("foobar", ["foo", "bar"])
54
- assert_equal ["s1", "s2", "s3", "s4"], r.zrange("foobar", 0, -1)
55
- end
56
-
57
- def test_zunionstore_with_weights
58
- r.zadd "foo", 1, "s1"
59
- r.zadd "foo", 3, "s3"
60
- r.zadd "bar", 20, "s2"
61
- r.zadd "bar", 40, "s4"
62
-
63
- assert_equal 4, r.zunionstore("foobar", ["foo", "bar"])
64
- assert_equal ["s1", "s3", "s2", "s4"], r.zrange("foobar", 0, -1)
65
-
66
- assert_equal 4, r.zunionstore("foobar", ["foo", "bar"], :weights => [10, 1])
67
- assert_equal ["s1", "s2", "s3", "s4"], r.zrange("foobar", 0, -1)
68
- end
69
-
70
- def test_zunionstore_with_aggregate
71
- r.zadd "foo", 1, "s1"
72
- r.zadd "foo", 2, "s2"
73
- r.zadd "bar", 4, "s2"
74
- r.zadd "bar", 3, "s3"
75
-
76
- assert_equal 3, r.zunionstore("foobar", ["foo", "bar"])
77
- assert_equal ["s1", "s3", "s2"], r.zrange("foobar", 0, -1)
78
-
79
- assert_equal 3, r.zunionstore("foobar", ["foo", "bar"], :aggregate => :min)
80
- assert_equal ["s1", "s2", "s3"], r.zrange("foobar", 0, -1)
81
-
82
- assert_equal 3, r.zunionstore("foobar", ["foo", "bar"], :aggregate => :max)
83
- assert_equal ["s1", "s3", "s2"], r.zrange("foobar", 0, -1)
84
- end
85
-
86
- def test_zinterstore
87
- r.zadd "foo", 1, "s1"
88
- r.zadd "bar", 2, "s1"
89
- r.zadd "foo", 3, "s3"
90
- r.zadd "bar", 4, "s4"
91
-
92
- assert_equal 1, r.zinterstore("foobar", ["foo", "bar"])
93
- assert_equal ["s1"], r.zrange("foobar", 0, -1)
94
- end
95
-
96
- def test_zinterstore_with_weights
97
- r.zadd "foo", 1, "s1"
98
- r.zadd "foo", 2, "s2"
99
- r.zadd "foo", 3, "s3"
100
- r.zadd "bar", 20, "s2"
101
- r.zadd "bar", 30, "s3"
102
- r.zadd "bar", 40, "s4"
103
-
104
- assert_equal 2, r.zinterstore("foobar", ["foo", "bar"])
105
- assert_equal ["s2", "s3"], r.zrange("foobar", 0, -1)
106
-
107
- assert_equal 2, r.zinterstore("foobar", ["foo", "bar"], :weights => [10, 1])
108
- assert_equal ["s2", "s3"], r.zrange("foobar", 0, -1)
109
-
110
- assert_equal 40.0, r.zscore("foobar", "s2")
111
- assert_equal 60.0, r.zscore("foobar", "s3")
112
- end
113
-
114
- def test_zinterstore_with_aggregate
115
- r.zadd "foo", 1, "s1"
116
- r.zadd "foo", 2, "s2"
117
- r.zadd "foo", 3, "s3"
118
- r.zadd "bar", 20, "s2"
119
- r.zadd "bar", 30, "s3"
120
- r.zadd "bar", 40, "s4"
121
-
122
- assert_equal 2, r.zinterstore("foobar", ["foo", "bar"])
123
- assert_equal ["s2", "s3"], r.zrange("foobar", 0, -1)
124
- assert_equal 22.0, r.zscore("foobar", "s2")
125
- assert_equal 33.0, r.zscore("foobar", "s3")
126
-
127
- assert_equal 2, r.zinterstore("foobar", ["foo", "bar"], :aggregate => :min)
128
- assert_equal ["s2", "s3"], r.zrange("foobar", 0, -1)
129
- assert_equal 2.0, r.zscore("foobar", "s2")
130
- assert_equal 3.0, r.zscore("foobar", "s3")
131
-
132
- assert_equal 2, r.zinterstore("foobar", ["foo", "bar"], :aggregate => :max)
133
- assert_equal ["s2", "s3"], r.zrange("foobar", 0, -1)
134
- assert_equal 20.0, r.zscore("foobar", "s2")
135
- assert_equal 30.0, r.zscore("foobar", "s3")
136
- end
137
7
  end
@@ -1,101 +1,7 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
- require "lint/strings"
1
+ require_relative 'helper'
2
+ require_relative 'lint/strings'
5
3
 
6
4
  class TestCommandsOnStrings < Test::Unit::TestCase
7
-
8
5
  include Helper::Client
9
6
  include Lint::Strings
10
-
11
- def test_mget
12
- r.set("foo", "s1")
13
- r.set("bar", "s2")
14
-
15
- assert_equal ["s1", "s2"] , r.mget("foo", "bar")
16
- assert_equal ["s1", "s2", nil], r.mget("foo", "bar", "baz")
17
- end
18
-
19
- def test_mget_mapped
20
- r.set("foo", "s1")
21
- r.set("bar", "s2")
22
-
23
- response = r.mapped_mget("foo", "bar")
24
-
25
- assert_equal "s1", response["foo"]
26
- assert_equal "s2", response["bar"]
27
-
28
- response = r.mapped_mget("foo", "bar", "baz")
29
-
30
- assert_equal "s1", response["foo"]
31
- assert_equal "s2", response["bar"]
32
- assert_equal nil , response["baz"]
33
- end
34
-
35
- def test_mapped_mget_in_a_pipeline_returns_hash
36
- r.set("foo", "s1")
37
- r.set("bar", "s2")
38
-
39
- result = r.pipelined do
40
- r.mapped_mget("foo", "bar")
41
- end
42
-
43
- assert_equal result[0], { "foo" => "s1", "bar" => "s2" }
44
- end
45
-
46
- def test_mset
47
- r.mset(:foo, "s1", :bar, "s2")
48
-
49
- assert_equal "s1", r.get("foo")
50
- assert_equal "s2", r.get("bar")
51
- end
52
-
53
- def test_mset_mapped
54
- r.mapped_mset(:foo => "s1", :bar => "s2")
55
-
56
- assert_equal "s1", r.get("foo")
57
- assert_equal "s2", r.get("bar")
58
- end
59
-
60
- def test_msetnx
61
- r.set("foo", "s1")
62
- assert_equal false, r.msetnx(:foo, "s2", :bar, "s3")
63
- assert_equal "s1", r.get("foo")
64
- assert_equal nil, r.get("bar")
65
-
66
- r.del("foo")
67
- assert_equal true, r.msetnx(:foo, "s2", :bar, "s3")
68
- assert_equal "s2", r.get("foo")
69
- assert_equal "s3", r.get("bar")
70
- end
71
-
72
- def test_msetnx_mapped
73
- r.set("foo", "s1")
74
- assert_equal false, r.mapped_msetnx(:foo => "s2", :bar => "s3")
75
- assert_equal "s1", r.get("foo")
76
- assert_equal nil, r.get("bar")
77
-
78
- r.del("foo")
79
- assert_equal true, r.mapped_msetnx(:foo => "s2", :bar => "s3")
80
- assert_equal "s2", r.get("foo")
81
- assert_equal "s3", r.get("bar")
82
- end
83
-
84
- def test_bitop
85
- try_encoding("UTF-8") do
86
- target_version "2.5.10" do
87
- r.set("foo", "a")
88
- r.set("bar", "b")
89
-
90
- r.bitop(:and, "foo&bar", "foo", "bar")
91
- assert_equal "\x60", r.get("foo&bar")
92
- r.bitop(:or, "foo|bar", "foo", "bar")
93
- assert_equal "\x63", r.get("foo|bar")
94
- r.bitop(:xor, "foo^bar", "foo", "bar")
95
- assert_equal "\x03", r.get("foo^bar")
96
- r.bitop(:not, "~foo", "foo")
97
- assert_equal "\x9E", r.get("~foo")
98
- end
99
- end
100
- end
101
7
  end
@@ -1,7 +1,5 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
4
- require "lint/value_types"
1
+ require_relative "helper"
2
+ require_relative "lint/value_types"
5
3
 
6
4
  class TestCommandsOnValueTypes < Test::Unit::TestCase
7
5
 
@@ -40,6 +38,42 @@ class TestCommandsOnValueTypes < Test::Unit::TestCase
40
38
  assert_equal [], r.keys("*").sort
41
39
  end
42
40
 
41
+ def test_unlink
42
+ target_version "4.0.0" do
43
+ r.set "foo", "s1"
44
+ r.set "bar", "s2"
45
+ r.set "baz", "s3"
46
+
47
+ assert_equal ["bar", "baz", "foo"], r.keys("*").sort
48
+
49
+ assert_equal 1, r.unlink("foo")
50
+
51
+ assert_equal ["bar", "baz"], r.keys("*").sort
52
+
53
+ assert_equal 2, r.unlink("bar", "baz")
54
+
55
+ assert_equal [], r.keys("*").sort
56
+ end
57
+ end
58
+
59
+ def test_unlink_with_array_argument
60
+ target_version "4.0.0" do
61
+ r.set "foo", "s1"
62
+ r.set "bar", "s2"
63
+ r.set "baz", "s3"
64
+
65
+ assert_equal ["bar", "baz", "foo"], r.keys("*").sort
66
+
67
+ assert_equal 1, r.unlink(["foo"])
68
+
69
+ assert_equal ["bar", "baz"], r.keys("*").sort
70
+
71
+ assert_equal 2, r.unlink(["bar", "baz"])
72
+
73
+ assert_equal [], r.keys("*").sort
74
+ end
75
+ end
76
+
43
77
  def test_randomkey
44
78
  assert r.randomkey.to_s.empty?
45
79
 
@@ -81,6 +115,7 @@ class TestCommandsOnValueTypes < Test::Unit::TestCase
81
115
  end
82
116
 
83
117
  def test_flushdb
118
+ # Test defaults
84
119
  r.set("foo", "s1")
85
120
  r.set("bar", "s2")
86
121
 
@@ -89,12 +124,51 @@ class TestCommandsOnValueTypes < Test::Unit::TestCase
89
124
  r.flushdb
90
125
 
91
126
  assert_equal 0, r.dbsize
127
+
128
+ # Test sync
129
+ r.set("foo", "s1")
130
+ r.set("bar", "s2")
131
+
132
+ assert_equal 2, r.dbsize
133
+
134
+ r.flushdb(:async => false)
135
+
136
+ assert_equal 0, r.dbsize
137
+
138
+ # Test async
139
+ target_version "3.9.101" do
140
+ r.set("foo", "s1")
141
+ r.set("bar", "s2")
142
+
143
+ assert_equal 2, r.dbsize
144
+
145
+ r.flushdb(:async => true)
146
+
147
+ assert_equal 0, r.dbsize
148
+
149
+ redis_mock(:flushdb => lambda { |args| "+FLUSHDB #{args.upcase}" }) do |redis|
150
+ assert_equal "FLUSHDB ASYNC", redis.flushdb(:async => true)
151
+ end
152
+ end
92
153
  end
93
154
 
94
155
  def test_flushall
156
+ # Test defaults
95
157
  redis_mock(:flushall => lambda { "+FLUSHALL" }) do |redis|
96
158
  assert_equal "FLUSHALL", redis.flushall
97
159
  end
160
+
161
+ # Test sync
162
+ redis_mock(:flushall => lambda { "+FLUSHALL" }) do |redis|
163
+ assert_equal "FLUSHALL", redis.flushall(:async => false)
164
+ end
165
+
166
+ # Test async
167
+ target_version "3.9.101" do
168
+ redis_mock(:flushall => lambda { |args| "+FLUSHALL #{args.upcase}" }) do |redis|
169
+ assert_equal "FLUSHALL ASYNC", redis.flushall(:async => true)
170
+ end
171
+ end
98
172
  end
99
173
 
100
174
  def test_migrate
@@ -111,8 +185,8 @@ class TestCommandsOnValueTypes < Test::Unit::TestCase
111
185
  end
112
186
  assert ex.message =~ /port not specified/
113
187
 
114
- default_db = redis.client.db.to_i
115
- default_timeout = redis.client.timeout.to_i
188
+ default_db = redis._client.db.to_i
189
+ default_timeout = redis._client.timeout.to_i
116
190
 
117
191
  # Test defaults
118
192
  actual = redis.migrate("foo", options)
@@ -1,6 +1,4 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path("helper", File.dirname(__FILE__))
1
+ require_relative "helper"
4
2
 
5
3
  class TestConnectionHandling < Test::Unit::TestCase
6
4
 
@@ -40,7 +38,7 @@ class TestConnectionHandling < Test::Unit::TestCase
40
38
  r.select 14
41
39
  assert_equal nil, r.get("foo")
42
40
 
43
- r.client.disconnect
41
+ r._client.disconnect
44
42
 
45
43
  assert_equal nil, r.get("foo")
46
44
  end
@@ -48,7 +46,7 @@ class TestConnectionHandling < Test::Unit::TestCase
48
46
  def test_quit
49
47
  r.quit
50
48
 
51
- assert !r.client.connected?
49
+ assert !r._client.connected?
52
50
  end
53
51
 
54
52
  def test_close
@@ -148,7 +146,7 @@ class TestConnectionHandling < Test::Unit::TestCase
148
146
  end
149
147
 
150
148
  assert_equal nil, result
151
- assert !redis.client.connected?
149
+ assert !redis._client.connected?
152
150
  end
153
151
  end
154
152
 
@@ -188,7 +186,7 @@ class TestConnectionHandling < Test::Unit::TestCase
188
186
  end
189
187
 
190
188
  assert_equal nil, result
191
- assert !redis.client.connected?
189
+ assert !redis._client.connected?
192
190
  end
193
191
  end
194
192