ryansch-mock_redis 0.2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.rspec +1 -0
- data/CHANGELOG.md +20 -0
- data/Gemfile +9 -0
- data/LICENSE +19 -0
- data/README.md +94 -0
- data/Rakefile +10 -0
- data/lib/mock_redis.rb +32 -0
- data/lib/mock_redis/assertions.rb +13 -0
- data/lib/mock_redis/database.rb +432 -0
- data/lib/mock_redis/exceptions.rb +3 -0
- data/lib/mock_redis/expire_wrapper.rb +25 -0
- data/lib/mock_redis/hash_methods.rb +102 -0
- data/lib/mock_redis/list_methods.rb +187 -0
- data/lib/mock_redis/multi_db_wrapper.rb +86 -0
- data/lib/mock_redis/set_methods.rb +125 -0
- data/lib/mock_redis/string_methods.rb +195 -0
- data/lib/mock_redis/transaction_wrapper.rb +80 -0
- data/lib/mock_redis/undef_redis_methods.rb +11 -0
- data/lib/mock_redis/utility_methods.rb +22 -0
- data/lib/mock_redis/version.rb +3 -0
- data/lib/mock_redis/zset.rb +110 -0
- data/lib/mock_redis/zset_methods.rb +209 -0
- data/mock_redis.gemspec +24 -0
- data/spec/cloning_spec.rb +96 -0
- data/spec/commands/append_spec.rb +24 -0
- data/spec/commands/auth_spec.rb +7 -0
- data/spec/commands/bgrewriteaof_spec.rb +7 -0
- data/spec/commands/bgsave_spec.rb +7 -0
- data/spec/commands/blpop_spec.rb +55 -0
- data/spec/commands/brpop_spec.rb +54 -0
- data/spec/commands/brpoplpush_spec.rb +53 -0
- data/spec/commands/dbsize_spec.rb +18 -0
- data/spec/commands/decr_spec.rb +34 -0
- data/spec/commands/decrby_spec.rb +34 -0
- data/spec/commands/del_spec.rb +20 -0
- data/spec/commands/echo_spec.rb +11 -0
- data/spec/commands/exists_spec.rb +14 -0
- data/spec/commands/expire_spec.rb +83 -0
- data/spec/commands/expireat_spec.rb +48 -0
- data/spec/commands/flushall_spec.rb +38 -0
- data/spec/commands/flushdb_spec.rb +38 -0
- data/spec/commands/get_spec.rb +23 -0
- data/spec/commands/getbit_spec.rb +34 -0
- data/spec/commands/getrange_spec.rb +22 -0
- data/spec/commands/getset_spec.rb +23 -0
- data/spec/commands/hdel_spec.rb +35 -0
- data/spec/commands/hexists_spec.rb +22 -0
- data/spec/commands/hget_spec.rb +23 -0
- data/spec/commands/hgetall_spec.rb +22 -0
- data/spec/commands/hincrby_spec.rb +52 -0
- data/spec/commands/hkeys_spec.rb +19 -0
- data/spec/commands/hlen_spec.rb +19 -0
- data/spec/commands/hmget_spec.rb +30 -0
- data/spec/commands/hmset_spec.rb +43 -0
- data/spec/commands/hset_spec.rb +23 -0
- data/spec/commands/hsetnx_spec.rb +39 -0
- data/spec/commands/hvals_spec.rb +19 -0
- data/spec/commands/incr_spec.rb +34 -0
- data/spec/commands/incrby_spec.rb +44 -0
- data/spec/commands/info_spec.rb +13 -0
- data/spec/commands/keys_spec.rb +87 -0
- data/spec/commands/lastsave_spec.rb +8 -0
- data/spec/commands/lindex_spec.rb +39 -0
- data/spec/commands/linsert_spec.rb +68 -0
- data/spec/commands/llen_spec.rb +16 -0
- data/spec/commands/lpop_spec.rb +34 -0
- data/spec/commands/lpush_spec.rb +30 -0
- data/spec/commands/lpushx_spec.rb +33 -0
- data/spec/commands/lrange_spec.rb +35 -0
- data/spec/commands/lrem_spec.rb +79 -0
- data/spec/commands/lset_spec.rb +38 -0
- data/spec/commands/ltrim_spec.rb +35 -0
- data/spec/commands/mget_spec.rb +34 -0
- data/spec/commands/move_spec.rb +147 -0
- data/spec/commands/mset_spec.rb +29 -0
- data/spec/commands/msetnx_spec.rb +40 -0
- data/spec/commands/persist_spec.rb +49 -0
- data/spec/commands/ping_spec.rb +7 -0
- data/spec/commands/quit_spec.rb +7 -0
- data/spec/commands/randomkey_spec.rb +20 -0
- data/spec/commands/rename_spec.rb +31 -0
- data/spec/commands/renamenx_spec.rb +36 -0
- data/spec/commands/rpop_spec.rb +34 -0
- data/spec/commands/rpoplpush_spec.rb +45 -0
- data/spec/commands/rpush_spec.rb +30 -0
- data/spec/commands/rpushx_spec.rb +33 -0
- data/spec/commands/sadd_spec.rb +22 -0
- data/spec/commands/save_spec.rb +7 -0
- data/spec/commands/scard_spec.rb +18 -0
- data/spec/commands/sdiff_spec.rb +47 -0
- data/spec/commands/sdiffstore_spec.rb +58 -0
- data/spec/commands/select_spec.rb +53 -0
- data/spec/commands/set_spec.rb +7 -0
- data/spec/commands/setbit_spec.rb +46 -0
- data/spec/commands/setex_spec.rb +22 -0
- data/spec/commands/setnx_spec.rb +25 -0
- data/spec/commands/setrange_spec.rb +30 -0
- data/spec/commands/sinter_spec.rb +41 -0
- data/spec/commands/sinterstore_spec.rb +53 -0
- data/spec/commands/sismember_spec.rb +29 -0
- data/spec/commands/smembers_spec.rb +18 -0
- data/spec/commands/smove_spec.rb +41 -0
- data/spec/commands/spop_spec.rb +25 -0
- data/spec/commands/srandmember_spec.rb +25 -0
- data/spec/commands/srem_spec.rb +35 -0
- data/spec/commands/strlen_spec.rb +19 -0
- data/spec/commands/sunion_spec.rb +40 -0
- data/spec/commands/sunionstore_spec.rb +53 -0
- data/spec/commands/ttl_spec.rb +36 -0
- data/spec/commands/type_spec.rb +36 -0
- data/spec/commands/unwatch_spec.rb +7 -0
- data/spec/commands/watch_spec.rb +7 -0
- data/spec/commands/zadd_spec.rb +29 -0
- data/spec/commands/zcard_spec.rb +19 -0
- data/spec/commands/zcount_spec.rb +23 -0
- data/spec/commands/zincrby_spec.rb +24 -0
- data/spec/commands/zinterstore_spec.rb +96 -0
- data/spec/commands/zrange_spec.rb +31 -0
- data/spec/commands/zrangebyscore_spec.rb +68 -0
- data/spec/commands/zrank_spec.rb +23 -0
- data/spec/commands/zrem_spec.rb +25 -0
- data/spec/commands/zremrangebyrank_spec.rb +22 -0
- data/spec/commands/zremrangebyscore_spec.rb +28 -0
- data/spec/commands/zrevrange_spec.rb +31 -0
- data/spec/commands/zrevrangebyscore_spec.rb +47 -0
- data/spec/commands/zrevrank_spec.rb +23 -0
- data/spec/commands/zscore_spec.rb +16 -0
- data/spec/commands/zunionstore_spec.rb +104 -0
- data/spec/spec_helper.rb +44 -0
- data/spec/support/redis_multiplexer.rb +91 -0
- data/spec/support/shared_examples/only_operates_on_hashes.rb +13 -0
- data/spec/support/shared_examples/only_operates_on_lists.rb +13 -0
- data/spec/support/shared_examples/only_operates_on_sets.rb +13 -0
- data/spec/support/shared_examples/only_operates_on_strings.rb +13 -0
- data/spec/support/shared_examples/only_operates_on_zsets.rb +57 -0
- data/spec/transactions_spec.rb +96 -0
- metadata +361 -0
@@ -0,0 +1,147 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#move(key, db)' do
|
4
|
+
before do
|
5
|
+
@srcdb = 0
|
6
|
+
@destdb = 1
|
7
|
+
|
8
|
+
@key = 'mock-redis-test:move'
|
9
|
+
end
|
10
|
+
|
11
|
+
context "when key exists in destdb" do
|
12
|
+
before do
|
13
|
+
@redises.set(@key, 'srcvalue')
|
14
|
+
@redises.select(@destdb)
|
15
|
+
@redises.set(@key, 'destvalue')
|
16
|
+
@redises.select(@srcdb)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns false" do
|
20
|
+
@redises.move(@key, @destdb).should be_false
|
21
|
+
end
|
22
|
+
|
23
|
+
it "leaves destdb/key alone" do
|
24
|
+
@redises.select(@destdb)
|
25
|
+
@redises.get(@key).should == "destvalue"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "leaves srcdb/key alone" do
|
29
|
+
@redises.get(@key).should == "srcvalue"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when key does not exist in srcdb" do
|
34
|
+
before do
|
35
|
+
@redises.select(@destdb)
|
36
|
+
@redises.set(@key, 'destvalue')
|
37
|
+
@redises.select(@srcdb)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "returns false" do
|
41
|
+
@redises.move(@key, @destdb).should be_false
|
42
|
+
end
|
43
|
+
|
44
|
+
it "leaves destdb/key alone" do
|
45
|
+
@redises.select(@destdb)
|
46
|
+
@redises.get(@key).should == "destvalue"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "when key exists in the currently-selected DB and not in db" do
|
51
|
+
before do
|
52
|
+
@redises.set(@key, 'value')
|
53
|
+
end
|
54
|
+
|
55
|
+
it "returns true" do
|
56
|
+
@redises.move(@key, @destdb).should be_true
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "on a string" do
|
61
|
+
before do
|
62
|
+
@redises.set(@key, 'value')
|
63
|
+
@redises.move(@key, @destdb)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "removes key from srcdb" do
|
67
|
+
@redises.exists(@key).should be_false
|
68
|
+
end
|
69
|
+
|
70
|
+
it "copies key to destdb" do
|
71
|
+
@redises.select(@destdb)
|
72
|
+
@redises.get(@key).should == 'value'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "on a list" do
|
77
|
+
before do
|
78
|
+
@redises.rpush(@key, 'bert')
|
79
|
+
@redises.rpush(@key, 'ernie')
|
80
|
+
@redises.move(@key, @destdb)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "removes key from srcdb" do
|
84
|
+
@redises.exists(@key).should be_false
|
85
|
+
end
|
86
|
+
|
87
|
+
it "copies key to destdb" do
|
88
|
+
@redises.select(@destdb)
|
89
|
+
@redises.lrange(@key, 0, -1).should == %w[bert ernie]
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context "on a hash" do
|
94
|
+
before do
|
95
|
+
@redises.hset(@key, 'a', 1)
|
96
|
+
@redises.hset(@key, 'b', 2)
|
97
|
+
|
98
|
+
@redises.move(@key, @destdb)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "removes key from srcdb" do
|
102
|
+
@redises.exists(@key).should be_false
|
103
|
+
end
|
104
|
+
|
105
|
+
it "copies key to destdb" do
|
106
|
+
@redises.select(@destdb)
|
107
|
+
@redises.hgetall(@key).should == {'a' => "1", 'b' => "2"}
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context "on a set" do
|
112
|
+
before do
|
113
|
+
@redises.sadd(@key, 'beer')
|
114
|
+
@redises.sadd(@key, 'wine')
|
115
|
+
|
116
|
+
@redises.move(@key, @destdb)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "removes key from srcdb" do
|
120
|
+
@redises.exists(@key).should be_false
|
121
|
+
end
|
122
|
+
|
123
|
+
it "copies key to destdb" do
|
124
|
+
@redises.select(@destdb)
|
125
|
+
@redises.smembers(@key).should == %w[beer wine]
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context "on a zset" do
|
130
|
+
before do
|
131
|
+
@redises.zadd(@key, 1, 'beer')
|
132
|
+
@redises.zadd(@key, 2, 'wine')
|
133
|
+
|
134
|
+
@redises.move(@key, @destdb)
|
135
|
+
end
|
136
|
+
|
137
|
+
it "removes key from srcdb" do
|
138
|
+
@redises.exists(@key).should be_false
|
139
|
+
end
|
140
|
+
|
141
|
+
it "copies key to destdb" do
|
142
|
+
@redises.select(@destdb)
|
143
|
+
@redises.zrange(@key, 0, -1, :with_scores => true).should ==
|
144
|
+
%w[beer 1 wine 2]
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#mset(key, value [, key, value, ...])' do
|
4
|
+
before do
|
5
|
+
@key1 = 'mock-redis-test:mset1'
|
6
|
+
@key2 = 'mock-redis-test:mset2'
|
7
|
+
end
|
8
|
+
|
9
|
+
it "responds with 'OK'" do
|
10
|
+
@redises.mset(@key1, 1).should == 'OK'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "sets the values" do
|
14
|
+
@redises.mset(@key1, 'value1', @key2, 'value2')
|
15
|
+
@redises.mget(@key1, @key2).should == %w[value1 value2]
|
16
|
+
end
|
17
|
+
|
18
|
+
it "raises an error if given an odd number of arguments" do
|
19
|
+
lambda do
|
20
|
+
@redises.mset(@key1, 'value1', @key2)
|
21
|
+
end.should raise_error(RuntimeError)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "raises an error if given 0 arguments" do
|
25
|
+
lambda do
|
26
|
+
@redises.mset()
|
27
|
+
end.should raise_error(RuntimeError)
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#msetnx(key, value [, key, value, ...])' do
|
4
|
+
before do
|
5
|
+
@key1 = 'mock-redis-test:msetnx1'
|
6
|
+
@key2 = 'mock-redis-test:msetnx2'
|
7
|
+
end
|
8
|
+
|
9
|
+
it "responds with 1 if any keys were set" do
|
10
|
+
@redises.msetnx(@key1, 1).should == 1
|
11
|
+
end
|
12
|
+
|
13
|
+
it "sets the values" do
|
14
|
+
@redises.msetnx(@key1, 'value1', @key2, 'value2')
|
15
|
+
@redises.mget(@key1, @key2).should == %w[value1 value2]
|
16
|
+
end
|
17
|
+
|
18
|
+
it "does nothing if any value is already set" do
|
19
|
+
@redises.set(@key1, "old1")
|
20
|
+
@redises.msetnx(@key1, 'value1', @key2, 'value2')
|
21
|
+
@redises.mget(@key1, @key2).should == ["old1", nil]
|
22
|
+
end
|
23
|
+
|
24
|
+
it "responds with 0 if any value is already set" do
|
25
|
+
@redises.set(@key1, "old1")
|
26
|
+
@redises.msetnx(@key1, 'value1', @key2, 'value2').should == 0
|
27
|
+
end
|
28
|
+
|
29
|
+
it "raises an error if given an odd number of arguments" do
|
30
|
+
lambda do
|
31
|
+
@redises.msetnx(@key1, 'value1', @key2)
|
32
|
+
end.should raise_error(RuntimeError)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "raises an error if given 0 arguments" do
|
36
|
+
lambda do
|
37
|
+
@redises.msetnx()
|
38
|
+
end.should raise_error(RuntimeError)
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#persist(key)" do
|
4
|
+
before do
|
5
|
+
@key = 'mock-redis-test:persist'
|
6
|
+
@redises.set(@key, 'spork')
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns true for a key with a timeout" do
|
10
|
+
@redises.expire(@key, 10000)
|
11
|
+
@redises.persist(@key).should be_true
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns false for a key with no timeout" do
|
15
|
+
@redises.persist(@key).should be_false
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns false for a key that does not exist" do
|
19
|
+
@redises.persist('mock-redis-test:nonesuch').should be_false
|
20
|
+
end
|
21
|
+
|
22
|
+
it "removes the timeout" do
|
23
|
+
@redises.expire(@key, 10000)
|
24
|
+
@redises.persist(@key)
|
25
|
+
@redises.persist(@key).should be_false
|
26
|
+
end
|
27
|
+
|
28
|
+
context "[mock only]" do
|
29
|
+
# These are mock-only since we can't actually manipulate time in
|
30
|
+
# the real Redis.
|
31
|
+
|
32
|
+
before(:all) do
|
33
|
+
@mock = @redises.mock
|
34
|
+
end
|
35
|
+
|
36
|
+
before do
|
37
|
+
@now = Time.now
|
38
|
+
Time.stub!(:now).and_return(@now)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "makes keys stay around" do
|
42
|
+
@mock.expire(@key, 5)
|
43
|
+
@mock.persist(@key)
|
44
|
+
Time.stub!(:now).and_return(@now + 5)
|
45
|
+
@mock.get(@key).should_not be_nil
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#randomkey [mock only]' do
|
4
|
+
before { @mock = @redises.mock }
|
5
|
+
|
6
|
+
it "finds a random key" do
|
7
|
+
@keys = ['mock-redis-test:1', 'mock-redis-test:2', 'mock-redis-test:3']
|
8
|
+
|
9
|
+
@keys.each do |k|
|
10
|
+
@mock.set(k, 1)
|
11
|
+
end
|
12
|
+
|
13
|
+
@keys.should include(@mock.randomkey)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns nil when there are no keys" do
|
17
|
+
@mock.keys('*').each {|k| @mock.del(k)}
|
18
|
+
@mock.randomkey.should be_nil
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#rename(key, newkey)' do
|
4
|
+
before do
|
5
|
+
@key = 'mock-redis-test:rename:key'
|
6
|
+
@newkey = 'mock-redis-test:rename:newkey'
|
7
|
+
|
8
|
+
@redises.set(@key, "oof")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "responds with 'OK'" do
|
12
|
+
@redises.rename(@key, @newkey).should == 'OK'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "moves the data" do
|
16
|
+
@redises.rename(@key, @newkey)
|
17
|
+
@redises.get(@newkey).should == "oof"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "raises an error when key == newkey" do
|
21
|
+
lambda do
|
22
|
+
@redises.rename(@key, @key)
|
23
|
+
end.should raise_error(RuntimeError)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "overwrites any existing value at newkey" do
|
27
|
+
@redises.set(@newkey, "rab")
|
28
|
+
@redises.rename(@key, @newkey)
|
29
|
+
@redises.get(@newkey).should == "oof"
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#renamenx(key, newkey)' do
|
4
|
+
before do
|
5
|
+
@key = 'mock-redis-test:renamenx:key'
|
6
|
+
@newkey = 'mock-redis-test:renamenx:newkey'
|
7
|
+
|
8
|
+
@redises.set(@key, "oof")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "responds with true when newkey does not exist" do
|
12
|
+
@redises.renamenx(@key, @newkey).should be_true
|
13
|
+
end
|
14
|
+
|
15
|
+
it "responds with false when newkey exists" do
|
16
|
+
@redises.set(@newkey, 'monkey')
|
17
|
+
@redises.renamenx(@key, @newkey).should be_false
|
18
|
+
end
|
19
|
+
|
20
|
+
it "moves the data" do
|
21
|
+
@redises.renamenx(@key, @newkey)
|
22
|
+
@redises.get(@newkey).should == "oof"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "raises an error when key == newkey" do
|
26
|
+
lambda do
|
27
|
+
@redises.renamenx(@key, @key)
|
28
|
+
end.should raise_error(RuntimeError)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "leaves any existing value at newkey alone" do
|
32
|
+
@redises.set(@newkey, "rab")
|
33
|
+
@redises.renamenx(@key, @newkey)
|
34
|
+
@redises.get(@newkey).should == "rab"
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#rpop(key)' do
|
4
|
+
before { @key = 'mock-redis-test:43093' }
|
5
|
+
|
6
|
+
it "returns and removes the first element of a list" do
|
7
|
+
@redises.lpush(@key, 1)
|
8
|
+
@redises.lpush(@key, 2)
|
9
|
+
|
10
|
+
@redises.rpop(@key).should == "1"
|
11
|
+
|
12
|
+
@redises.llen(@key).should == 1
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns nil if the list is empty" do
|
16
|
+
@redises.lpush(@key, 'foo')
|
17
|
+
@redises.rpop(@key)
|
18
|
+
|
19
|
+
@redises.rpop(@key).should be_nil
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns nil for nonexistent values" do
|
23
|
+
@redises.rpop(@key).should be_nil
|
24
|
+
end
|
25
|
+
|
26
|
+
it "removes empty lists" do
|
27
|
+
@redises.lpush(@key, 'foo')
|
28
|
+
@redises.rpop(@key)
|
29
|
+
|
30
|
+
@redises.get(@key).should be_nil
|
31
|
+
end
|
32
|
+
|
33
|
+
it_should_behave_like "a list-only command"
|
34
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#rpoplpush(source, destination)' do
|
4
|
+
before do
|
5
|
+
@list1 = 'mock-redis-test:rpoplpush-list1'
|
6
|
+
@list2 = 'mock-redis-test:rpoplpush-list2'
|
7
|
+
|
8
|
+
@redises.lpush(@list1, 'b')
|
9
|
+
@redises.lpush(@list1, 'a')
|
10
|
+
|
11
|
+
@redises.lpush(@list2, 'y')
|
12
|
+
@redises.lpush(@list2, 'x')
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns the value moved" do
|
16
|
+
@redises.rpoplpush(@list1, @list2).should == "b"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "takes the last element of destination and prepends it to source" do
|
20
|
+
@redises.rpoplpush(@list1, @list2)
|
21
|
+
|
22
|
+
@redises.lrange(@list1, 0, -1).should == %w[a]
|
23
|
+
@redises.lrange(@list2, 0, -1).should == %w[b x y]
|
24
|
+
end
|
25
|
+
|
26
|
+
it "rotates a list when source and destination are the same" do
|
27
|
+
@redises.rpoplpush(@list1, @list1)
|
28
|
+
@redises.lrange(@list1, 0, -1).should == %w[b a]
|
29
|
+
end
|
30
|
+
|
31
|
+
it "removes empty lists" do
|
32
|
+
@redises.llen(@list1).times { @redises.rpoplpush(@list1, @list2) }
|
33
|
+
@redises.get(@list1).should be_nil
|
34
|
+
end
|
35
|
+
|
36
|
+
it "raises an error for non-list source value" do
|
37
|
+
@redises.set(@list1, 'string value')
|
38
|
+
|
39
|
+
lambda do
|
40
|
+
@redises.rpoplpush(@list1, @list2)
|
41
|
+
end.should raise_error(RuntimeError)
|
42
|
+
end
|
43
|
+
|
44
|
+
it_should_behave_like "a list-only command"
|
45
|
+
end
|