ryansch-mock_redis 0.2.0.1
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.
- 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,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#lindex(key, index)' do
|
4
|
+
before { @key = 'mock-redis-test:69312' }
|
5
|
+
|
6
|
+
it "gets an element from the list by its index" do
|
7
|
+
@redises.lpush(@key, 20)
|
8
|
+
@redises.lpush(@key, 10)
|
9
|
+
|
10
|
+
@redises.lindex(@key, 0).should == "10"
|
11
|
+
@redises.lindex(@key, 1).should == "20"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "treats negative indices as coming from the right" do
|
15
|
+
@redises.lpush(@key, 20)
|
16
|
+
@redises.lpush(@key, 10)
|
17
|
+
|
18
|
+
@redises.lindex(@key, -1).should == "20"
|
19
|
+
@redises.lindex(@key, -2).should == "10"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns nil if the index is too large (and positive)" do
|
23
|
+
@redises.lpush(@key, 20)
|
24
|
+
|
25
|
+
@redises.lindex(@key, 100).should be_nil
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns nil if the index is too large (and negative)" do
|
29
|
+
@redises.lpush(@key, 20)
|
30
|
+
|
31
|
+
@redises.lindex(@key, -100).should be_nil
|
32
|
+
end
|
33
|
+
|
34
|
+
it "returns nil for nonexistent values" do
|
35
|
+
@redises.lindex(@key, 0).should be_nil
|
36
|
+
end
|
37
|
+
|
38
|
+
it_should_behave_like "a list-only command"
|
39
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#linsert(key, :before|:after, pivot, value)" do
|
4
|
+
before { @key = 'mock-redis-test:48733' }
|
5
|
+
|
6
|
+
it "returns the new size of the list when the pivot is found" do
|
7
|
+
@redises.lpush(@key, 'X')
|
8
|
+
|
9
|
+
@redises.linsert(@key, :before, 'X', 'Y').should == 2
|
10
|
+
@redises.lpushx(@key, 'X').should == 3
|
11
|
+
end
|
12
|
+
|
13
|
+
it "does nothing when run against a nonexistent key" do
|
14
|
+
@redises.linsert(@key, :before, 1, 2).should == 0
|
15
|
+
@redises.get(@key).should be_nil
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns -1 if the pivot is not found" do
|
19
|
+
@redises.lpush(@key, 1)
|
20
|
+
@redises.linsert(@key, :after, 'X', 'Y').should == -1
|
21
|
+
end
|
22
|
+
|
23
|
+
it "inserts elements before the pivot when given :before as position" do
|
24
|
+
@redises.lpush(@key, 'bert')
|
25
|
+
@redises.linsert(@key, :before, 'bert', 'ernie')
|
26
|
+
|
27
|
+
@redises.lindex(@key, 0).should == 'ernie'
|
28
|
+
@redises.lindex(@key, 1).should == 'bert'
|
29
|
+
end
|
30
|
+
|
31
|
+
it "inserts elements before the pivot when given 'before' as position" do
|
32
|
+
@redises.lpush(@key, 'bert')
|
33
|
+
@redises.linsert(@key, 'before', 'bert', 'ernie')
|
34
|
+
|
35
|
+
@redises.lindex(@key, 0).should == 'ernie'
|
36
|
+
@redises.lindex(@key, 1).should == 'bert'
|
37
|
+
end
|
38
|
+
|
39
|
+
it "inserts elements after the pivot when given :after as position" do
|
40
|
+
@redises.lpush(@key, 'bert')
|
41
|
+
@redises.linsert(@key, :after, 'bert', 'ernie')
|
42
|
+
|
43
|
+
@redises.lindex(@key, 0).should == 'bert'
|
44
|
+
@redises.lindex(@key, 1).should == 'ernie'
|
45
|
+
end
|
46
|
+
|
47
|
+
it "inserts elements after the pivot when given 'after' as position" do
|
48
|
+
@redises.lpush(@key, 'bert')
|
49
|
+
@redises.linsert(@key, 'after', 'bert', 'ernie')
|
50
|
+
|
51
|
+
@redises.lindex(@key, 0).should == 'bert'
|
52
|
+
@redises.lindex(@key, 1).should == 'ernie'
|
53
|
+
end
|
54
|
+
|
55
|
+
it "raises an error when given a position that is neither before nor after" do
|
56
|
+
lambda do
|
57
|
+
@redises.linsert(@key, :near, 1, 2)
|
58
|
+
end.should raise_error(RuntimeError)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "stores values as strings" do
|
62
|
+
@redises.lpush(@key, 1)
|
63
|
+
@redises.linsert(@key, :before, 1, 2)
|
64
|
+
@redises.lindex(@key, 0).should == "2"
|
65
|
+
end
|
66
|
+
|
67
|
+
it_should_behave_like "a list-only command"
|
68
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#llen(key)" do
|
4
|
+
before { @key = 'mock-redis-test:78407' }
|
5
|
+
|
6
|
+
it "returns 0 for a nonexistent key" do
|
7
|
+
@redises.llen(@key).should == 0
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns the length of the list" do
|
11
|
+
5.times { @redises.lpush(@key, 'X') }
|
12
|
+
@redises.llen(@key).should == 5
|
13
|
+
end
|
14
|
+
|
15
|
+
it_should_behave_like "a list-only command"
|
16
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#lpop(key)' do
|
4
|
+
before { @key = 'mock-redis-test:65374' }
|
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.lpop(@key).should == "2"
|
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.lpop(@key)
|
18
|
+
|
19
|
+
@redises.lpop(@key).should be_nil
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns nil for nonexistent values" do
|
23
|
+
@redises.lpop(@key).should be_nil
|
24
|
+
end
|
25
|
+
|
26
|
+
it "removes empty lists" do
|
27
|
+
@redises.lpush(@key, 'foo')
|
28
|
+
@redises.lpop(@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,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#lpush(key, value)" do
|
4
|
+
before { @key = 'mock-redis-test:57367' }
|
5
|
+
|
6
|
+
it "returns the new size of the list" do
|
7
|
+
@redises.lpush(@key, 'X').should == 1
|
8
|
+
@redises.lpush(@key, 'X').should == 2
|
9
|
+
end
|
10
|
+
|
11
|
+
it "creates a new list when run against a nonexistent key" do
|
12
|
+
@redises.lpush(@key, 'value')
|
13
|
+
@redises.llen(@key).should == 1
|
14
|
+
end
|
15
|
+
|
16
|
+
it "prepends items to the list" do
|
17
|
+
@redises.lpush(@key, "bert")
|
18
|
+
@redises.lpush(@key, "ernie")
|
19
|
+
|
20
|
+
@redises.lindex(@key, 0).should == "ernie"
|
21
|
+
@redises.lindex(@key, 1).should == "bert"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "stores values as strings" do
|
25
|
+
@redises.lpush(@key, 1)
|
26
|
+
@redises.lindex(@key, 0).should == "1"
|
27
|
+
end
|
28
|
+
|
29
|
+
it_should_behave_like "a list-only command"
|
30
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#lpushx(key, value)" do
|
4
|
+
before { @key = 'mock-redis-test:81267' }
|
5
|
+
|
6
|
+
it "returns the new size of the list" do
|
7
|
+
@redises.lpush(@key, 'X')
|
8
|
+
|
9
|
+
@redises.lpushx(@key, 'X').should == 2
|
10
|
+
@redises.lpushx(@key, 'X').should == 3
|
11
|
+
end
|
12
|
+
|
13
|
+
it "does nothing when run against a nonexistent key" do
|
14
|
+
@redises.lpushx(@key, 'value')
|
15
|
+
@redises.get(@key).should be_nil
|
16
|
+
end
|
17
|
+
|
18
|
+
it "prepends items to the list" do
|
19
|
+
@redises.lpush(@key, "bert")
|
20
|
+
@redises.lpushx(@key, "ernie")
|
21
|
+
|
22
|
+
@redises.lindex(@key, 0).should == "ernie"
|
23
|
+
@redises.lindex(@key, 1).should == "bert"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "stores values as strings" do
|
27
|
+
@redises.lpush(@key, 1)
|
28
|
+
@redises.lpushx(@key, 2)
|
29
|
+
@redises.lindex(@key, 0).should == "2"
|
30
|
+
end
|
31
|
+
|
32
|
+
it_should_behave_like "a list-only command"
|
33
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#lrange(key, start, stop)" do
|
4
|
+
before do
|
5
|
+
@key = 'mock-redis-test:68036'
|
6
|
+
|
7
|
+
@redises.lpush(@key, 'v4')
|
8
|
+
@redises.lpush(@key, 'v3')
|
9
|
+
@redises.lpush(@key, 'v2')
|
10
|
+
@redises.lpush(@key, 'v1')
|
11
|
+
@redises.lpush(@key, 'v0')
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns a subset of the list inclusive of the right end" do
|
15
|
+
@redises.lrange(@key, 0, 2).should == %w[v0 v1 v2]
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns an empty list when start > end" do
|
19
|
+
@redises.lrange(@key, 3, 2).should == []
|
20
|
+
end
|
21
|
+
|
22
|
+
it "works with negative indices" do
|
23
|
+
@redises.lrange(@key, 2, -1).should == %w[v2 v3 v4]
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns [] when run against a nonexistent value" do
|
27
|
+
@redises.lrange("mock-redis-test:bogus-key", 0, 1).should == []
|
28
|
+
end
|
29
|
+
|
30
|
+
it "finds the end of the list correctly when end is too large" do
|
31
|
+
@redises.lrange(@key, 4, 10).should == %w[v4]
|
32
|
+
end
|
33
|
+
|
34
|
+
it_should_behave_like "a list-only command"
|
35
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#lrem(key, count, value)" do
|
4
|
+
before do
|
5
|
+
@key = 'mock-redis-test:66767'
|
6
|
+
|
7
|
+
%w[99 bottles of beer on the wall
|
8
|
+
99 bottles of beer
|
9
|
+
take one down
|
10
|
+
pass it around
|
11
|
+
98 bottles of beer on the wall].reverse.each do |x|
|
12
|
+
@redises.lpush(@key, x)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it "deletes the first count instances of key when count > 0" do
|
17
|
+
@redises.lrem(@key, 2, 'bottles')
|
18
|
+
|
19
|
+
@redises.lrange(@key, 0, 8).should == %w[
|
20
|
+
99 of beer on the wall
|
21
|
+
99 of beer
|
22
|
+
]
|
23
|
+
|
24
|
+
@redises.lrange(@key, -7, -1).should == %w[98 bottles of beer on the wall]
|
25
|
+
end
|
26
|
+
|
27
|
+
it "deletes the last count instances of key when count < 0" do
|
28
|
+
@redises.lrem(@key, -2, 'bottles')
|
29
|
+
|
30
|
+
@redises.lrange(@key, 0, 9).should == %w[
|
31
|
+
99 bottles of beer on the wall
|
32
|
+
99 of beer
|
33
|
+
]
|
34
|
+
|
35
|
+
@redises.lrange(@key, -6, -1).should == %w[98 of beer on the wall]
|
36
|
+
end
|
37
|
+
|
38
|
+
it "deletes all instances of key when count == 0" do
|
39
|
+
@redises.lrem(@key, 0, 'bottles')
|
40
|
+
@redises.lrange(@key, 0, -1).grep(/bottles/).should be_empty
|
41
|
+
end
|
42
|
+
|
43
|
+
it "returns the number of elements deleted" do
|
44
|
+
@redises.lrem(@key, 2, 'bottles').should == 2
|
45
|
+
end
|
46
|
+
|
47
|
+
it "returns the number of elements deleted even if you ask for more" do
|
48
|
+
@redises.lrem(@key, 10, 'bottles').should == 3
|
49
|
+
end
|
50
|
+
|
51
|
+
it "stringifies value" do
|
52
|
+
@redises.lrem(@key, 0, 99).should == 2
|
53
|
+
end
|
54
|
+
|
55
|
+
it "returns 0 when run against a nonexistent value" do
|
56
|
+
@redises.lrem("mock-redis-test:bogus-key", 0, 1).should == 0
|
57
|
+
end
|
58
|
+
|
59
|
+
it "returns 0 when run against an empty list" do
|
60
|
+
@redises.llen(@key).times { @redises.lpop(@key) } # empty the list
|
61
|
+
@redises.lrem(@key, 0, "beer").should == 0
|
62
|
+
end
|
63
|
+
|
64
|
+
it "treats non-integer count as 0" do
|
65
|
+
@redises.lrem(@key, 'foo', 'bottles').should == 3
|
66
|
+
@redises.lrange(@key, 0, -1).grep(/bottles/).should be_empty
|
67
|
+
end
|
68
|
+
|
69
|
+
it "removes empty lists" do
|
70
|
+
other_key = "mock-redis-test:lrem-#{__LINE__}"
|
71
|
+
|
72
|
+
@redises.lpush(other_key, 'foo')
|
73
|
+
@redises.lrem(other_key, 0, 'foo')
|
74
|
+
|
75
|
+
@redises.get(other_key).should be_nil
|
76
|
+
end
|
77
|
+
|
78
|
+
it_should_behave_like "a list-only command"
|
79
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#lset(key, index, value)" do
|
4
|
+
before do
|
5
|
+
@key = 'mock-redis-test:21522'
|
6
|
+
|
7
|
+
@redises.lpush(@key, 'v1')
|
8
|
+
@redises.lpush(@key, 'v0')
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns 'OK'" do
|
12
|
+
@redises.lset(@key, 0, "newthing").should == 'OK'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "sets the list's value at index to value" do
|
16
|
+
@redises.lset(@key, 0, "newthing")
|
17
|
+
@redises.lindex(@key, 0).should == "newthing"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "stringifies value" do
|
21
|
+
@redises.lset(@key, 0, 12345)
|
22
|
+
@redises.lindex(@key, 0).should == "12345"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "raises an exception for nonexistent keys" do
|
26
|
+
lambda do
|
27
|
+
@redises.lset('mock-redis-test:bogus-key', 100, 'value')
|
28
|
+
end.should raise_error(RuntimeError)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "raises an exception for out-of-range indices" do
|
32
|
+
lambda do
|
33
|
+
@redises.lset(@key, 100, 'value')
|
34
|
+
end.should raise_error(RuntimeError)
|
35
|
+
end
|
36
|
+
|
37
|
+
it_should_behave_like "a list-only command"
|
38
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#ltrim(key, start, stop)" do
|
4
|
+
before do
|
5
|
+
@key = 'mock-redis-test:22310'
|
6
|
+
|
7
|
+
%w[v0 v1 v2 v3 v4].reverse.each{|v| @redises.lpush(@key, v)}
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns 'OK'" do
|
11
|
+
@redises.ltrim(@key, 1, 3).should == 'OK'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "trims the list to include only the specified elements" do
|
15
|
+
@redises.ltrim(@key, 1, 3)
|
16
|
+
@redises.lrange(@key, 0, -1).should == %w[v1 v2 v3]
|
17
|
+
end
|
18
|
+
|
19
|
+
it "trims the list to include only the specified elements (negative indices)" do
|
20
|
+
@redises.ltrim(@key, -2, -1)
|
21
|
+
@redises.lrange(@key, 0, -1).should == %w[v3 v4]
|
22
|
+
end
|
23
|
+
|
24
|
+
it "does not crash on overly-large indices" do
|
25
|
+
@redises.ltrim(@key, 100, 200)
|
26
|
+
@redises.lrange(@key, 0, -1).should == %w[]
|
27
|
+
end
|
28
|
+
|
29
|
+
it "removes empty lists" do
|
30
|
+
@redises.ltrim(@key, 1, 0)
|
31
|
+
@redises.get(@key).should be_nil
|
32
|
+
end
|
33
|
+
|
34
|
+
it_should_behave_like "a list-only command"
|
35
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#mget(key [, key, ...])" do
|
4
|
+
before do
|
5
|
+
@key1 = "mock-redis-test:mget1"
|
6
|
+
@key2 = "mock-redis-test:mget2"
|
7
|
+
|
8
|
+
@redises.set(@key1, 1)
|
9
|
+
@redises.set(@key2, 2)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns an array of values" do
|
13
|
+
@redises.mget(@key1, @key2).should == %w[1 2]
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns nil for missing keys" do
|
17
|
+
@redises.mget(@key1, 'mock-redis-test:not-found', @key2).
|
18
|
+
should == ["1", nil, "2"]
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns nil for non-string keys" do
|
22
|
+
list = "mock-redis-test:mget-list"
|
23
|
+
|
24
|
+
@redises.lpush(list, 'bork bork bork')
|
25
|
+
|
26
|
+
@redises.mget(@key1, @key2, list).should == ["1", "2", nil]
|
27
|
+
end
|
28
|
+
|
29
|
+
it "raises an error if you pass it 0 arguments" do
|
30
|
+
lambda do
|
31
|
+
@redises.mget()
|
32
|
+
end.should raise_error(RuntimeError)
|
33
|
+
end
|
34
|
+
end
|