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,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#sinterstore(destination, key [, key, ...])' do
|
4
|
+
before do
|
5
|
+
@numbers = 'mock-redis-test:sinterstore:numbers'
|
6
|
+
@evens = 'mock-redis-test:sinterstore:evens'
|
7
|
+
@primes = 'mock-redis-test:sinterstore:primes'
|
8
|
+
@destination = 'mock-redis-test:sinterstore:destination'
|
9
|
+
|
10
|
+
(1..10).each {|i| @redises.sadd(@numbers, i) }
|
11
|
+
[2, 4, 6, 8, 10].each {|i| @redises.sadd(@evens, i) }
|
12
|
+
[2, 3, 5, 7].each {|i| @redises.sadd(@primes, i) }
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns the number of elements in the resulting set" do
|
16
|
+
@redises.sinterstore(@destination, @numbers, @evens).should == 5
|
17
|
+
end
|
18
|
+
|
19
|
+
it "stores the resulting set" do
|
20
|
+
@redises.sinterstore(@destination, @numbers, @evens)
|
21
|
+
@redises.smembers(@destination).should == %w[10 2 4 6 8]
|
22
|
+
end
|
23
|
+
|
24
|
+
it "does not store empty sets" do
|
25
|
+
@redises.sinterstore(@destination, 'mock-redis-test:nonesuch', @numbers).should == 0
|
26
|
+
@redises.get(@destination).should be_nil
|
27
|
+
end
|
28
|
+
|
29
|
+
it "removes existing elements in destination" do
|
30
|
+
@redises.sadd(@destination, 42)
|
31
|
+
|
32
|
+
@redises.sinterstore(@destination, @primes)
|
33
|
+
@redises.smembers(@destination).should == %w[2 3 5 7]
|
34
|
+
end
|
35
|
+
|
36
|
+
it "raises an error if given 0 sets" do
|
37
|
+
lambda do
|
38
|
+
@redises.sinterstore(@destination)
|
39
|
+
end.should raise_error(RuntimeError)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "raises an error if any argument is not a a set" do
|
43
|
+
@redises.set('mock-redis-test:notset', 1)
|
44
|
+
|
45
|
+
lambda do
|
46
|
+
@redises.sinterstore(@destination, @numbers, 'mock-redis-test:notset')
|
47
|
+
end.should raise_error(RuntimeError)
|
48
|
+
|
49
|
+
lambda do
|
50
|
+
@redises.sinterstore(@destination, 'mock-redis-test:notset', @numbers)
|
51
|
+
end.should raise_error(RuntimeError)
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#sismember(key, member)' do
|
4
|
+
before do
|
5
|
+
@key = 'mock-redis-test:sismember'
|
6
|
+
@redises.sadd(@key, 'whiskey')
|
7
|
+
@redises.sadd(@key, 'beer')
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns true if member is in set" do
|
11
|
+
@redises.sismember(@key, 'whiskey').should be_true
|
12
|
+
@redises.sismember(@key, 'beer').should be_true
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns false if member is not in set" do
|
16
|
+
@redises.sismember(@key, 'cola').should be_false
|
17
|
+
end
|
18
|
+
|
19
|
+
it "stringifies member" do
|
20
|
+
@redises.sadd(@key, '1')
|
21
|
+
@redises.sismember(@key, 1).should be_true
|
22
|
+
end
|
23
|
+
|
24
|
+
it "treats a nonexistent value as an empty set" do
|
25
|
+
@redises.sismember('mock-redis-test:nonesuch', 'beer').should be_false
|
26
|
+
end
|
27
|
+
|
28
|
+
it_should_behave_like "a set-only command"
|
29
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#smembers(key)' do
|
4
|
+
before { @key = 'mock-redis-test:smembers' }
|
5
|
+
|
6
|
+
it "returns [] for an empty set" do
|
7
|
+
@redises.smembers(@key).should == []
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns the set's members" do
|
11
|
+
@redises.sadd(@key, 1)
|
12
|
+
@redises.sadd(@key, 2)
|
13
|
+
@redises.sadd(@key, 3)
|
14
|
+
@redises.smembers(@key).should == %w[1 2 3]
|
15
|
+
end
|
16
|
+
|
17
|
+
it_should_behave_like "a set-only command"
|
18
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#smove(source, destination, member)' do
|
4
|
+
before do
|
5
|
+
@src = 'mock-redis-test:smove-source'
|
6
|
+
@dest = 'mock-redis-test:smove-destination'
|
7
|
+
|
8
|
+
@redises.sadd(@src, 1)
|
9
|
+
@redises.sadd(@dest, 2)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns true if the member exists in src" do
|
13
|
+
@redises.smove(@src, @dest, 1).should be_true
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns false if the member exists in src" do
|
17
|
+
@redises.smove(@src, @dest, 'nope').should be_false
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns true if the member exists in src and dest" do
|
21
|
+
@redises.sadd(@dest, 1)
|
22
|
+
@redises.smove(@src, @dest, 1).should be_true
|
23
|
+
end
|
24
|
+
|
25
|
+
it "moves member from source to destination" do
|
26
|
+
@redises.smove(@src, @dest, 1)
|
27
|
+
@redises.sismember(@dest, 1).should be_true
|
28
|
+
@redises.sismember(@src, 1).should be_false
|
29
|
+
end
|
30
|
+
|
31
|
+
it "cleans up empty sets" do
|
32
|
+
@redises.smove(@src, @dest, 1)
|
33
|
+
@redises.get(@src).should be_nil
|
34
|
+
end
|
35
|
+
|
36
|
+
it "treats a nonexistent value as an empty set" do
|
37
|
+
@redises.smove('mock-redis-test:nonesuch', @dest, 1).should be_false
|
38
|
+
end
|
39
|
+
|
40
|
+
it_should_behave_like "a set-only command"
|
41
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#spop(key)' do
|
4
|
+
before do
|
5
|
+
@key = 'mock-redis-test:spop'
|
6
|
+
|
7
|
+
@redises.sadd(@key, 'value')
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns a member of the set" do
|
11
|
+
@redises.spop(@key).should == 'value'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "removes a member of the set" do
|
15
|
+
@redises.spop(@key)
|
16
|
+
@redises.smembers(@key).should == []
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns nil if the set is empty" do
|
20
|
+
@redises.spop(@key)
|
21
|
+
@redises.spop(@key).should be_nil
|
22
|
+
end
|
23
|
+
|
24
|
+
it_should_behave_like "a set-only command"
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#srandmember(key)' do
|
4
|
+
before do
|
5
|
+
@key = 'mock-redis-test:srandmember'
|
6
|
+
|
7
|
+
@redises.sadd(@key, 'value')
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns a member of the set" do
|
11
|
+
@redises.srandmember(@key).should == 'value'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "does not modify the set" do
|
15
|
+
@redises.srandmember(@key)
|
16
|
+
@redises.smembers(@key).should == ['value']
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns nil if the set is empty" do
|
20
|
+
@redises.spop(@key)
|
21
|
+
@redises.srandmember(@key).should be_nil
|
22
|
+
end
|
23
|
+
|
24
|
+
it_should_behave_like "a set-only command"
|
25
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#srem(key, member)' do
|
4
|
+
before do
|
5
|
+
@key = 'mock-redis-test:srem'
|
6
|
+
|
7
|
+
@redises.sadd(@key, 'bert')
|
8
|
+
@redises.sadd(@key, 'ernie')
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns true if member is in the set" do
|
12
|
+
@redises.srem(@key, 'bert').should be_true
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns false if member is not in the set" do
|
16
|
+
@redises.srem(@key, 'cookiemonster').should be_false
|
17
|
+
end
|
18
|
+
|
19
|
+
it "removes member from the set" do
|
20
|
+
@redises.srem(@key, 'ernie')
|
21
|
+
@redises.smembers(@key).should == ['bert']
|
22
|
+
end
|
23
|
+
|
24
|
+
it "stringifies member" do
|
25
|
+
@redises.sadd(@key, '1')
|
26
|
+
@redises.srem(@key, 1).should be_true
|
27
|
+
end
|
28
|
+
|
29
|
+
it "cleans up empty sets" do
|
30
|
+
@redises.smembers(@key).each {|m| @redises.srem(@key, m)}
|
31
|
+
@redises.get(@key).should be_nil
|
32
|
+
end
|
33
|
+
|
34
|
+
it_should_behave_like "a set-only command"
|
35
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "#strlen(key)" do
|
5
|
+
before do
|
6
|
+
@key = 'mock-redis-test:73288'
|
7
|
+
@redises.set(@key, "5 ∈ (0..10)")
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns the string's length in bytes" do
|
11
|
+
@redises.strlen(@key).should == 13
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns 0 for a nonexistent value" do
|
15
|
+
@redises.strlen('mock-redis-test:does-not-exist').should == 0
|
16
|
+
end
|
17
|
+
|
18
|
+
it_should_behave_like "a string-only command"
|
19
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#sunion(key [, key, ...])' do
|
4
|
+
before do
|
5
|
+
@evens = 'mock-redis-test:sunion:evens'
|
6
|
+
@primes = 'mock-redis-test:sunion:primes'
|
7
|
+
|
8
|
+
[2, 4, 6, 8, 10].each {|i| @redises.sadd(@evens, i) }
|
9
|
+
[2, 3, 5, 7].each {|i| @redises.sadd(@primes, i) }
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns the elements in the resulting set" do
|
13
|
+
@redises.sunion(@evens, @primes).should == %w[10 2 3 4 5 6 7 8]
|
14
|
+
end
|
15
|
+
|
16
|
+
it "treats missing keys as empty sets" do
|
17
|
+
@redises.sunion(@primes, 'mock-redis-test:nonesuch').
|
18
|
+
should == %w[2 3 5 7]
|
19
|
+
end
|
20
|
+
|
21
|
+
it "raises an error if given 0 sets" do
|
22
|
+
lambda do
|
23
|
+
@redises.sunion
|
24
|
+
end.should raise_error(RuntimeError)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "raises an error if any argument is not a a set" do
|
28
|
+
@redises.set('mock-redis-test:notset', 1)
|
29
|
+
|
30
|
+
lambda do
|
31
|
+
@redises.sunion(@numbers, 'mock-redis-test:notset')
|
32
|
+
end.should raise_error(RuntimeError)
|
33
|
+
|
34
|
+
lambda do
|
35
|
+
@redises.sunion('mock-redis-test:notset', @numbers)
|
36
|
+
end.should raise_error(RuntimeError)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#sunionstore(destination, key [, key, ...])' do
|
4
|
+
before do
|
5
|
+
@evens = 'mock-redis-test:sunionstore:evens'
|
6
|
+
@primes = 'mock-redis-test:sunionstore:primes'
|
7
|
+
@destination = 'mock-redis-test:sunionstore:destination'
|
8
|
+
|
9
|
+
[2, 4, 6, 8, 10].each {|i| @redises.sadd(@evens, i) }
|
10
|
+
[2, 3, 5, 7].each {|i| @redises.sadd(@primes, i) }
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns the number of elements in the resulting set" do
|
14
|
+
@redises.sunionstore(@destination, @primes, @evens).should == 8
|
15
|
+
end
|
16
|
+
|
17
|
+
it "stores the resulting set" do
|
18
|
+
@redises.sunionstore(@destination, @primes, @evens)
|
19
|
+
@redises.smembers(@destination).should == %w[10 2 3 4 5 6 7 8]
|
20
|
+
end
|
21
|
+
|
22
|
+
it "does not store empty sets" do
|
23
|
+
@redises.sunionstore(@destination,
|
24
|
+
'mock-redis-test:nonesuch',
|
25
|
+
'mock-redis-test:nonesuch2').should == 0
|
26
|
+
@redises.get(@destination).should be_nil
|
27
|
+
end
|
28
|
+
|
29
|
+
it "removes existing elements in destination" do
|
30
|
+
@redises.sadd(@destination, 42)
|
31
|
+
|
32
|
+
@redises.sunionstore(@destination, @primes)
|
33
|
+
@redises.smembers(@destination).should == %w[2 3 5 7]
|
34
|
+
end
|
35
|
+
|
36
|
+
it "raises an error if given 0 sets" do
|
37
|
+
lambda do
|
38
|
+
@redises.sunionstore(@destination)
|
39
|
+
end.should raise_error(RuntimeError)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "raises an error if any argument is not a a set" do
|
43
|
+
@redises.set('mock-redis-test:notset', 1)
|
44
|
+
|
45
|
+
lambda do
|
46
|
+
@redises.sunionstore(@destination, @primes, 'mock-redis-test:notset')
|
47
|
+
end.should raise_error(RuntimeError)
|
48
|
+
|
49
|
+
lambda do
|
50
|
+
@redises.sunionstore(@destination, 'mock-redis-test:notset', @primes)
|
51
|
+
end.should raise_error(RuntimeError)
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#ttl(key)" do
|
4
|
+
before do
|
5
|
+
@key = 'mock-redis-test:persist'
|
6
|
+
@redises.set(@key, 'spork')
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns -1 for a key with no expiration" do
|
10
|
+
@redises.ttl(@key).should == -1
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns -1 for a key that does not exist" do
|
14
|
+
@redises.ttl('mock-redis-test:nonesuch').should == -1
|
15
|
+
end
|
16
|
+
|
17
|
+
context "[mock only]" do
|
18
|
+
# These are mock-only since we can't actually manipulate time in
|
19
|
+
# the real Redis.
|
20
|
+
|
21
|
+
before(:all) do
|
22
|
+
@mock = @redises.mock
|
23
|
+
end
|
24
|
+
|
25
|
+
before do
|
26
|
+
@now = Time.now
|
27
|
+
Time.stub!(:now).and_return(@now)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "gives you the key's remaining lifespan in seconds" do
|
31
|
+
@mock.expire(@key, 5)
|
32
|
+
@mock.ttl(@key).should == 4
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#type(key)" do
|
4
|
+
before do
|
5
|
+
@key = 'mock-redis-test:type'
|
6
|
+
end
|
7
|
+
|
8
|
+
it "returns 'none' for no key" do
|
9
|
+
@redises.type(@key).should == 'none'
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns 'string' for a string" do
|
13
|
+
@redises.set(@key, 'stringlish')
|
14
|
+
@redises.type(@key).should == 'string'
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns 'list' for a list" do
|
18
|
+
@redises.lpush(@key, 100)
|
19
|
+
@redises.type(@key).should == 'list'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns 'hash' for a hash" do
|
23
|
+
@redises.hset(@key, 100, 200)
|
24
|
+
@redises.type(@key).should == 'hash'
|
25
|
+
end
|
26
|
+
|
27
|
+
it "returns 'set' for a set" do
|
28
|
+
@redises.sadd(@key, 100)
|
29
|
+
@redises.type(@key).should == 'set'
|
30
|
+
end
|
31
|
+
|
32
|
+
it "returns 'zset' for a zset" do
|
33
|
+
@redises.zadd(@key, 1, 2)
|
34
|
+
@redises.type(@key).should == 'zset'
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#zadd(key, score, member)" do
|
4
|
+
before { @key = 'mock-redis-test:zadd' }
|
5
|
+
|
6
|
+
it "returns true if member wasn't present in the set" do
|
7
|
+
@redises.zadd(@key, 1, 'foo').should be_true
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns false if member was present in the set" do
|
11
|
+
@redises.zadd(@key, 1, 'foo')
|
12
|
+
@redises.zadd(@key, 1, 'foo').should be_false
|
13
|
+
end
|
14
|
+
|
15
|
+
it "adds member to the set" do
|
16
|
+
@redises.zadd(@key, 1, 'foo')
|
17
|
+
@redises.zrange(@key, 0, -1).should == ['foo']
|
18
|
+
end
|
19
|
+
|
20
|
+
it "updates the score" do
|
21
|
+
@redises.zadd(@key, 1, 'foo')
|
22
|
+
@redises.zadd(@key, 2, 'foo')
|
23
|
+
|
24
|
+
@redises.zscore(@key, 'foo').should == "2"
|
25
|
+
end
|
26
|
+
|
27
|
+
it_should_behave_like "arg 1 is a score"
|
28
|
+
it_should_behave_like "a zset-only command"
|
29
|
+
end
|