forked from redis/redis-rb
/
distributed_commands_requiring_clustering_test.rb
148 lines (110 loc) · 3.45 KB
/
distributed_commands_requiring_clustering_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# encoding: UTF-8
require File.expand_path("./helper", File.dirname(__FILE__))
require "redis/distributed"
setup do
log = StringIO.new
init Redis::Distributed.new(NODES, :logger => ::Logger.new(log))
end
test "RENAME" do |r|
r.set("{qux}foo", "s1")
r.rename "{qux}foo", "{qux}bar"
assert "s1" == r.get("{qux}bar")
assert nil == r.get("{qux}foo")
end
test "RENAMENX" do |r|
r.set("{qux}foo", "s1")
r.set("{qux}bar", "s2")
assert false == r.renamenx("{qux}foo", "{qux}bar")
assert "s1" == r.get("{qux}foo")
assert "s2" == r.get("{qux}bar")
end
test "BRPOPLPUSH" do |r|
r.rpush "{qux}foo", "s1"
r.rpush "{qux}foo", "s2"
assert_equal "s2", r.brpoplpush("{qux}foo", "{qux}bar", 1)
assert_equal ["s2"], r.lrange("{qux}bar", 0, -1)
end
test "RPOPLPUSH" do |r|
r.rpush "{qux}foo", "s1"
r.rpush "{qux}foo", "s2"
assert "s2" == r.rpoplpush("{qux}foo", "{qux}bar")
assert ["s2"] == r.lrange("{qux}bar", 0, -1)
assert "s1" == r.rpoplpush("{qux}foo", "{qux}bar")
assert ["s1", "s2"] == r.lrange("{qux}bar", 0, -1)
end
test "SMOVE" do |r|
r.sadd "{qux}foo", "s1"
r.sadd "{qux}bar", "s2"
assert r.smove("{qux}foo", "{qux}bar", "s1")
assert r.sismember("{qux}bar", "s1")
end
test "SINTER" do |r|
r.sadd "{qux}foo", "s1"
r.sadd "{qux}foo", "s2"
r.sadd "{qux}bar", "s2"
assert ["s2"] == r.sinter("{qux}foo", "{qux}bar")
end
test "SINTERSTORE" do |r|
r.sadd "{qux}foo", "s1"
r.sadd "{qux}foo", "s2"
r.sadd "{qux}bar", "s2"
r.sinterstore("{qux}baz", "{qux}foo", "{qux}bar")
assert ["s2"] == r.smembers("{qux}baz")
end
test "SUNION" do |r|
r.sadd "{qux}foo", "s1"
r.sadd "{qux}foo", "s2"
r.sadd "{qux}bar", "s2"
r.sadd "{qux}bar", "s3"
assert ["s1", "s2", "s3"] == r.sunion("{qux}foo", "{qux}bar").sort
end
test "SUNIONSTORE" do |r|
r.sadd "{qux}foo", "s1"
r.sadd "{qux}foo", "s2"
r.sadd "{qux}bar", "s2"
r.sadd "{qux}bar", "s3"
r.sunionstore("{qux}baz", "{qux}foo", "{qux}bar")
assert ["s1", "s2", "s3"] == r.smembers("{qux}baz").sort
end
test "SDIFF" do |r|
r.sadd "{qux}foo", "s1"
r.sadd "{qux}foo", "s2"
r.sadd "{qux}bar", "s2"
r.sadd "{qux}bar", "s3"
assert ["s1"] == r.sdiff("{qux}foo", "{qux}bar")
assert ["s3"] == r.sdiff("{qux}bar", "{qux}foo")
end
test "SDIFFSTORE" do |r|
r.sadd "{qux}foo", "s1"
r.sadd "{qux}foo", "s2"
r.sadd "{qux}bar", "s2"
r.sadd "{qux}bar", "s3"
r.sdiffstore("{qux}baz", "{qux}foo", "{qux}bar")
assert ["s1"] == r.smembers("{qux}baz")
end
test "SORT" do |r|
r.set("{qux}foo:1", "s1")
r.set("{qux}foo:2", "s2")
r.rpush("{qux}bar", "1")
r.rpush("{qux}bar", "2")
assert ["s1"] == r.sort("{qux}bar", :get => "{qux}foo:*", :limit => [0, 1])
assert ["s2"] == r.sort("{qux}bar", :get => "{qux}foo:*", :limit => [0, 1], :order => "desc alpha")
end
test "SORT with an array of GETs" do |r|
r.set("{qux}foo:1:a", "s1a")
r.set("{qux}foo:1:b", "s1b")
r.set("{qux}foo:2:a", "s2a")
r.set("{qux}foo:2:b", "s2b")
r.rpush("{qux}bar", "1")
r.rpush("{qux}bar", "2")
assert ["s1a", "s1b"] == r.sort("{qux}bar", :get => ["{qux}foo:*:a", "{qux}foo:*:b"], :limit => [0, 1])
assert ["s2a", "s2b"] == r.sort("{qux}bar", :get => ["{qux}foo:*:a", "{qux}foo:*:b"], :limit => [0, 1], :order => "desc alpha")
end
test "SORT with STORE" do |r|
r.set("{qux}foo:1", "s1")
r.set("{qux}foo:2", "s2")
r.rpush("{qux}bar", "1")
r.rpush("{qux}bar", "2")
r.sort("{qux}bar", :get => "{qux}foo:*", :store => "{qux}baz")
assert ["s1", "s2"] == r.lrange("{qux}baz", 0, -1)
end