mock_redis 0.14.1 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.overcommit.yml +1 -1
- data/.rubocop.yml +91 -0
- data/.simplecov +4 -0
- data/.travis.yml +14 -2
- data/CHANGELOG.md +4 -0
- data/Gemfile +4 -2
- data/README.md +1 -0
- data/Rakefile +2 -2
- data/lib/mock_redis.rb +25 -26
- data/lib/mock_redis/assertions.rb +0 -1
- data/lib/mock_redis/database.rb +35 -28
- data/lib/mock_redis/expire_wrapper.rb +1 -1
- data/lib/mock_redis/future.rb +1 -1
- data/lib/mock_redis/hash_methods.rb +18 -17
- data/lib/mock_redis/indifferent_hash.rb +4 -0
- data/lib/mock_redis/info_method.rb +109 -108
- data/lib/mock_redis/list_methods.rb +17 -16
- data/lib/mock_redis/multi_db_wrapper.rb +5 -4
- data/lib/mock_redis/pipelined_wrapper.rb +3 -3
- data/lib/mock_redis/set_methods.rb +10 -9
- data/lib/mock_redis/sort_method.rb +11 -12
- data/lib/mock_redis/string_methods.rb +26 -29
- data/lib/mock_redis/transaction_wrapper.rb +7 -8
- data/lib/mock_redis/utility_methods.rb +9 -12
- data/lib/mock_redis/version.rb +1 -1
- data/lib/mock_redis/zset.rb +22 -23
- data/lib/mock_redis/zset_methods.rb +25 -25
- data/spec/cloning_spec.rb +17 -18
- data/spec/commands/append_spec.rb +4 -4
- data/spec/commands/auth_spec.rb +1 -1
- data/spec/commands/bgrewriteaof_spec.rb +2 -2
- data/spec/commands/bgsave_spec.rb +2 -2
- data/spec/commands/bitcount_spec.rb +3 -3
- data/spec/commands/blpop_spec.rb +10 -10
- data/spec/commands/brpop_spec.rb +10 -10
- data/spec/commands/brpoplpush_spec.rb +9 -9
- data/spec/commands/connected_spec.rb +2 -2
- data/spec/commands/dbsize_spec.rb +3 -3
- data/spec/commands/decr_spec.rb +7 -7
- data/spec/commands/decrby_spec.rb +7 -7
- data/spec/commands/del_spec.rb +4 -4
- data/spec/commands/disconnect_spec.rb +2 -2
- data/spec/commands/echo_spec.rb +4 -4
- data/spec/commands/exists_spec.rb +3 -3
- data/spec/commands/expire_spec.rb +13 -13
- data/spec/commands/expireat_spec.rb +6 -7
- data/spec/commands/flushall_spec.rb +5 -5
- data/spec/commands/flushdb_spec.rb +5 -5
- data/spec/commands/future_spec.rb +2 -2
- data/spec/commands/get_spec.rb +7 -7
- data/spec/commands/getbit_spec.rb +6 -6
- data/spec/commands/getrange_spec.rb +9 -9
- data/spec/commands/getset_spec.rb +7 -7
- data/spec/commands/hash_operator_spec.rb +5 -5
- data/spec/commands/hdel_spec.rb +12 -12
- data/spec/commands/hexists_spec.rb +7 -7
- data/spec/commands/hget_spec.rb +7 -7
- data/spec/commands/hgetall_spec.rb +6 -6
- data/spec/commands/hincrby_spec.rb +14 -14
- data/spec/commands/hincrbyfloat_spec.rb +14 -14
- data/spec/commands/hkeys_spec.rb +5 -5
- data/spec/commands/hlen_spec.rb +5 -5
- data/spec/commands/hmget_spec.rb +8 -8
- data/spec/commands/hmset_spec.rb +10 -10
- data/spec/commands/hset_spec.rb +11 -11
- data/spec/commands/hsetnx_spec.rb +14 -14
- data/spec/commands/hvals_spec.rb +5 -5
- data/spec/commands/incr_spec.rb +7 -7
- data/spec/commands/incrby_spec.rb +11 -11
- data/spec/commands/incrbyfloat_spec.rb +11 -11
- data/spec/commands/info_spec.rb +30 -30
- data/spec/commands/keys_spec.rb +42 -43
- data/spec/commands/lastsave_spec.rb +2 -2
- data/spec/commands/lindex_spec.rb +15 -15
- data/spec/commands/linsert_spec.rb +13 -13
- data/spec/commands/llen_spec.rb +4 -4
- data/spec/commands/lpop_spec.rb +6 -6
- data/spec/commands/lpush_spec.rb +16 -16
- data/spec/commands/lpushx_spec.rb +13 -13
- data/spec/commands/lrange_spec.rb +12 -12
- data/spec/commands/lrem_spec.rb +15 -15
- data/spec/commands/lset_spec.rb +12 -12
- data/spec/commands/ltrim_spec.rb +9 -9
- data/spec/commands/mapped_hmget_spec.rb +8 -8
- data/spec/commands/mapped_hmset_spec.rb +12 -12
- data/spec/commands/mapped_mget_spec.rb +4 -4
- data/spec/commands/mapped_mset_spec.rb +1 -1
- data/spec/commands/mget_spec.rb +11 -11
- data/spec/commands/move_spec.rb +29 -29
- data/spec/commands/mset_spec.rb +4 -4
- data/spec/commands/msetnx_spec.rb +10 -10
- data/spec/commands/persist_spec.rb +9 -10
- data/spec/commands/pexpire_spec.rb +12 -13
- data/spec/commands/pexpireat_spec.rb +6 -6
- data/spec/commands/ping_spec.rb +1 -1
- data/spec/commands/pipelined_spec.rb +5 -5
- data/spec/commands/pttl_spec.rb +5 -5
- data/spec/commands/randomkey_spec.rb +3 -3
- data/spec/commands/rename_spec.rb +9 -9
- data/spec/commands/renamenx_spec.rb +10 -10
- data/spec/commands/rpop_spec.rb +6 -6
- data/spec/commands/rpoplpush_spec.rb +7 -7
- data/spec/commands/rpush_spec.rb +16 -16
- data/spec/commands/rpushx_spec.rb +13 -13
- data/spec/commands/sadd_spec.rb +8 -9
- data/spec/commands/scan_spec.rb +6 -7
- data/spec/commands/scard_spec.rb +3 -3
- data/spec/commands/sdiff_spec.rb +10 -10
- data/spec/commands/sdiffstore_spec.rb +10 -10
- data/spec/commands/select_spec.rb +7 -7
- data/spec/commands/setbit_spec.rb +13 -13
- data/spec/commands/setex_spec.rb +4 -4
- data/spec/commands/setnx_spec.rb +4 -4
- data/spec/commands/setrange_spec.rb +12 -12
- data/spec/commands/sinter_spec.rb +8 -10
- data/spec/commands/sinterstore_spec.rb +9 -9
- data/spec/commands/sismember_spec.rb +5 -5
- data/spec/commands/smembers_spec.rb +5 -5
- data/spec/commands/smove_spec.rb +7 -7
- data/spec/commands/sort_list_spec.rb +3 -3
- data/spec/commands/sort_set_spec.rb +3 -3
- data/spec/commands/sort_zset_spec.rb +3 -3
- data/spec/commands/spop_spec.rb +4 -4
- data/spec/commands/srandmember_spec.rb +8 -8
- data/spec/commands/srem_spec.rb +9 -9
- data/spec/commands/strlen_spec.rb +4 -4
- data/spec/commands/sunion_spec.rb +7 -9
- data/spec/commands/sunionstore_spec.rb +9 -9
- data/spec/commands/ttl_spec.rb +5 -5
- data/spec/commands/type_spec.rb +1 -1
- data/spec/commands/zadd_spec.rb +10 -10
- data/spec/commands/zcard_spec.rb +4 -4
- data/spec/commands/zcount_spec.rb +14 -14
- data/spec/commands/zincrby_spec.rb +6 -6
- data/spec/commands/zinterstore_spec.rb +17 -17
- data/spec/commands/zrange_spec.rb +12 -12
- data/spec/commands/zrangebyscore_spec.rb +26 -26
- data/spec/commands/zrank_spec.rb +4 -4
- data/spec/commands/zrem_spec.rb +9 -9
- data/spec/commands/zremrangebyrank_spec.rb +5 -5
- data/spec/commands/zremrangebyscore_spec.rb +9 -7
- data/spec/commands/zrevrange_spec.rb +10 -10
- data/spec/commands/zrevrangebyscore_spec.rb +14 -14
- data/spec/commands/zrevrank_spec.rb +4 -4
- data/spec/commands/zscore_spec.rb +5 -5
- data/spec/commands/zunionstore_spec.rb +18 -18
- data/spec/mock_redis_spec.rb +11 -1
- data/spec/spec_helper.rb +13 -4
- data/spec/support/redis_multiplexer.rb +39 -31
- data/spec/support/shared_examples/only_operates_on_hashes.rb +2 -2
- data/spec/support/shared_examples/only_operates_on_lists.rb +2 -2
- data/spec/support/shared_examples/only_operates_on_sets.rb +2 -2
- data/spec/support/shared_examples/only_operates_on_strings.rb +3 -3
- data/spec/support/shared_examples/only_operates_on_zsets.rb +12 -12
- data/spec/support/shared_examples/sorts_enumerables.rb +12 -12
- data/spec/transactions_spec.rb +18 -18
- metadata +5 -3
data/spec/commands/scan_spec.rb
CHANGED
@@ -20,8 +20,8 @@ describe '#scan' do
|
|
20
20
|
|
21
21
|
context 'when keys are found' do
|
22
22
|
context 'when count is lower than collection size' do
|
23
|
-
let(:collection) { (count+1).times.map {|i| "mock:key#{
|
24
|
-
let(:expected) { [count.to_s, collection]}
|
23
|
+
let(:collection) { (count + 1).times.map { |i| "mock:key#{i}" } }
|
24
|
+
let(:expected) { [count.to_s, collection] }
|
25
25
|
|
26
26
|
it 'returns a the next cursor and the collection' do
|
27
27
|
expect(subject.scan(0, count: count, match: match)).to eq(expected)
|
@@ -29,8 +29,8 @@ describe '#scan' do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
context 'when count is greater or equal than collection size' do
|
32
|
-
let(:collection) { count.times.map {|i| "mock:key#{
|
33
|
-
let(:expected) { ['0', collection]}
|
32
|
+
let(:collection) { count.times.map { |i| "mock:key#{i}" } }
|
33
|
+
let(:expected) { ['0', collection] }
|
34
34
|
|
35
35
|
it 'returns a 0 cursor and the collection' do
|
36
36
|
expect(subject.scan(0, count: count, match: match)).to eq(expected)
|
@@ -39,8 +39,8 @@ describe '#scan' do
|
|
39
39
|
|
40
40
|
context 'when giving a custom match filter' do
|
41
41
|
let(:match) { 'mock:key*' }
|
42
|
-
let(:collection) { %w
|
43
|
-
let(:expected) { ['0', %w
|
42
|
+
let(:collection) { %w[mock:key mock:key2 mock:otherkey] }
|
43
|
+
let(:expected) { ['0', %w[mock:key mock:key2]] }
|
44
44
|
|
45
45
|
it 'returns a 0 cursor and the filtered collection' do
|
46
46
|
expect(subject.scan(0, count: count, match: match)).to eq(expected)
|
@@ -48,4 +48,3 @@ describe '#scan' do
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
51
|
-
|
data/spec/commands/scard_spec.rb
CHANGED
@@ -3,16 +3,16 @@ require 'spec_helper'
|
|
3
3
|
describe '#scard(key)' do
|
4
4
|
before { @key = 'mock-redis-test:scard' }
|
5
5
|
|
6
|
-
it
|
6
|
+
it 'returns 0 for an empty set' do
|
7
7
|
@redises.scard(@key).should == 0
|
8
8
|
end
|
9
9
|
|
10
|
-
it
|
10
|
+
it 'returns the number of elements in the set' do
|
11
11
|
@redises.sadd(@key, 'one')
|
12
12
|
@redises.sadd(@key, 'two')
|
13
13
|
@redises.sadd(@key, 'three')
|
14
14
|
@redises.scard(@key).should == 3
|
15
15
|
end
|
16
16
|
|
17
|
-
it_should_behave_like
|
17
|
+
it_should_behave_like 'a set-only command'
|
18
18
|
end
|
data/spec/commands/sdiff_spec.rb
CHANGED
@@ -6,34 +6,34 @@ describe '#sdiff(key [, key, ...])' do
|
|
6
6
|
@evens = 'mock-redis-test:sdiff:odds'
|
7
7
|
@primes = 'mock-redis-test:sdiff:primes'
|
8
8
|
|
9
|
-
(1..10).each {|i| @redises.sadd(@numbers, i) }
|
10
|
-
[2, 4, 6, 8, 10].each {|i| @redises.sadd(@evens, i) }
|
11
|
-
[2, 3, 5, 7].each {|i| @redises.sadd(@primes, i) }
|
9
|
+
(1..10).each { |i| @redises.sadd(@numbers, i) }
|
10
|
+
[2, 4, 6, 8, 10].each { |i| @redises.sadd(@evens, i) }
|
11
|
+
[2, 3, 5, 7].each { |i| @redises.sadd(@primes, i) }
|
12
12
|
end
|
13
13
|
|
14
|
-
it
|
14
|
+
it 'returns the first set minus the second set' do
|
15
15
|
@redises.sdiff(@numbers, @evens).should == %w[1 3 5 7 9]
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
18
|
+
it 'returns the first set minus all the other sets' do
|
19
19
|
@redises.sdiff(@numbers, @evens, @primes).should == %w[1 9]
|
20
20
|
end
|
21
21
|
|
22
|
-
it
|
22
|
+
it 'treats missing keys as empty sets' do
|
23
23
|
@redises.sdiff(@evens, 'mock-redis-test:nonesuch').should == %w[2 4 6 8 10]
|
24
24
|
end
|
25
25
|
|
26
|
-
it
|
26
|
+
it 'returns the first set when called with a single argument' do
|
27
27
|
@redises.sdiff(@primes).should == %w[2 3 5 7]
|
28
28
|
end
|
29
29
|
|
30
|
-
it
|
30
|
+
it 'raises an error if given 0 arguments' do
|
31
31
|
lambda do
|
32
|
-
@redises.sdiff
|
32
|
+
@redises.sdiff
|
33
33
|
end.should raise_error(RuntimeError)
|
34
34
|
end
|
35
35
|
|
36
|
-
it
|
36
|
+
it 'raises an error if any argument is not a a set' do
|
37
37
|
@redises.set('foo', 1)
|
38
38
|
|
39
39
|
lambda do
|
@@ -7,44 +7,44 @@ describe '#sdiffstore(destination, key [, key, ...])' do
|
|
7
7
|
@primes = 'mock-redis-test:sdiffstore:primes'
|
8
8
|
@destination = 'mock-redis-test:sdiffstore:destination'
|
9
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) }
|
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
13
|
end
|
14
14
|
|
15
|
-
it
|
15
|
+
it 'returns the number of elements in the resulting set' do
|
16
16
|
@redises.sdiffstore(@destination, @numbers, @evens).should == 5
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
19
|
+
it 'stores the resulting set' do
|
20
20
|
@redises.sdiffstore(@destination, @numbers, @evens)
|
21
21
|
@redises.smembers(@destination).should == %w[9 7 5 3 1]
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
24
|
+
it 'does not store empty sets' do
|
25
25
|
@redises.sdiffstore(@destination, @numbers, @numbers).should == 0
|
26
26
|
@redises.get(@destination).should be_nil
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
29
|
+
it 'treats missing keys as empty sets' do
|
30
30
|
@redises.sdiffstore(@destination, @evens, 'mock-redis-test:nonesuch')
|
31
31
|
@redises.smembers(@destination).should == %w[10 8 6 4 2]
|
32
32
|
end
|
33
33
|
|
34
|
-
it
|
34
|
+
it 'removes existing elements in destination' do
|
35
35
|
@redises.sadd(@destination, 42)
|
36
36
|
|
37
37
|
@redises.sdiffstore(@destination, @primes)
|
38
38
|
@redises.smembers(@destination).should == %w[7 5 3 2]
|
39
39
|
end
|
40
40
|
|
41
|
-
it
|
41
|
+
it 'raises an error if given 0 sets' do
|
42
42
|
lambda do
|
43
43
|
@redises.sdiffstore(@destination)
|
44
44
|
end.should raise_error(RuntimeError)
|
45
45
|
end
|
46
46
|
|
47
|
-
it
|
47
|
+
it 'raises an error if any argument is not a a set' do
|
48
48
|
@redises.set('mock-redis-test:notset', 1)
|
49
49
|
|
50
50
|
lambda do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#select(db)' do
|
4
4
|
before { @key = 'mock-redis-test:select' }
|
5
5
|
|
6
6
|
it "returns 'OK'" do
|
@@ -14,7 +14,7 @@ describe "#select(db)" do
|
|
14
14
|
@redises.get(@key).should == 'foo'
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
17
|
+
it 'switches databases' do
|
18
18
|
@redises.select(0)
|
19
19
|
@redises.set(@key, 'foo')
|
20
20
|
|
@@ -25,7 +25,7 @@ describe "#select(db)" do
|
|
25
25
|
@redises.get(@key).should == 'foo'
|
26
26
|
end
|
27
27
|
|
28
|
-
context
|
28
|
+
context '[mock only]' do
|
29
29
|
# Time dependence introduces a bit of nondeterminism here
|
30
30
|
before do
|
31
31
|
@now = Time.now
|
@@ -42,7 +42,7 @@ describe "#select(db)" do
|
|
42
42
|
@mock.expire(@key, 200)
|
43
43
|
end
|
44
44
|
|
45
|
-
it
|
45
|
+
it 'keeps expire times per-db' do
|
46
46
|
@mock.select(0)
|
47
47
|
@mock.ttl(@key).should == 100
|
48
48
|
|
@@ -50,12 +50,12 @@ describe "#select(db)" do
|
|
50
50
|
@mock.ttl(@key).should == 200
|
51
51
|
end
|
52
52
|
|
53
|
-
it
|
53
|
+
it 'keeps expire times in miliseconds per-db' do
|
54
54
|
@mock.select(0)
|
55
|
-
(
|
55
|
+
(100_000 - 1000..100_000 + 1000).should cover(@mock.pttl(@key))
|
56
56
|
|
57
57
|
@mock.select(1)
|
58
|
-
(
|
58
|
+
(200_000 - 1000..200_000 + 1000).should cover(@mock.pttl(@key))
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe '#setbit(key, offset)' do
|
5
5
|
before do
|
6
6
|
@key = 'mock-redis-test:setbit'
|
7
7
|
@redises.set(@key, 'h') # ASCII 0x68
|
@@ -12,44 +12,44 @@ describe "#setbit(key, offset)" do
|
|
12
12
|
@redises.setbit(@key, 1, 1).should == 1
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
15
|
+
it 'sets the bit within the string' do
|
16
16
|
@redises.setbit(@key, 7, 1)
|
17
17
|
@redises.get(@key).should == 'i' # ASCII 0x69
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
20
|
+
it 'unsets the bit within the string' do
|
21
21
|
@redises.setbit(@key, 1, 0)
|
22
22
|
@redises.get(@key).should == '(' # ASCII 0x28
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
26
|
-
@redises.set(@key,
|
25
|
+
it 'does the right thing with multibyte characters' do
|
26
|
+
@redises.set(@key, '€99.94') # the euro sign is 3 bytes wide in UTF-8
|
27
27
|
@redises.setbit(@key, 63, 1).should == 0
|
28
|
-
@redises.get(@key).should ==
|
28
|
+
@redises.get(@key).should == '€99.95'
|
29
29
|
end
|
30
30
|
|
31
|
-
it
|
31
|
+
it 'expands the string if necessary' do
|
32
32
|
@redises.setbit(@key, 9, 1)
|
33
|
-
@redises.get(@key).should ==
|
33
|
+
@redises.get(@key).should == 'h@'
|
34
34
|
end
|
35
35
|
|
36
|
-
it
|
36
|
+
it 'sets added bits to 0' do
|
37
37
|
@redises.setbit(@key, 17, 1)
|
38
38
|
@redises.get(@key).should == "h\000@"
|
39
39
|
end
|
40
40
|
|
41
|
-
it
|
41
|
+
it 'treats missing keys as empty strings' do
|
42
42
|
@redises.del(@key)
|
43
43
|
@redises.setbit(@key, 1, 1)
|
44
|
-
@redises.get(@key).should ==
|
44
|
+
@redises.get(@key).should == '@'
|
45
45
|
end
|
46
46
|
|
47
|
-
it
|
47
|
+
it 'sets and retrieves bits' do
|
48
48
|
@redises.setbit(@key, 22, 1)
|
49
49
|
@redises.getbit(@key, 22).should == 1
|
50
50
|
@redises.setbit(@key, 23, 0)
|
51
51
|
@redises.getbit(@key, 23).should == 0
|
52
52
|
end
|
53
53
|
|
54
|
-
it_should_behave_like
|
54
|
+
it_should_behave_like 'a string-only command'
|
55
55
|
end
|
data/spec/commands/setex_spec.rb
CHANGED
@@ -7,13 +7,13 @@ describe '#setex(key, seconds, value)' do
|
|
7
7
|
@redises.setex(@key, 10, 'value').should == 'OK'
|
8
8
|
end
|
9
9
|
|
10
|
-
it
|
11
|
-
@redises.setex(@key,
|
10
|
+
it 'sets the value' do
|
11
|
+
@redises.setex(@key, 10_000, 'value')
|
12
12
|
@redises.get(@key).should == 'value'
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
16
|
-
@redises.setex(@key,
|
15
|
+
it 'sets the expiration time' do
|
16
|
+
@redises.setex(@key, 10_000, 'value')
|
17
17
|
|
18
18
|
# no guarantee these are the same
|
19
19
|
@redises.real.ttl(@key).should > 0
|
data/spec/commands/setnx_spec.rb
CHANGED
@@ -3,21 +3,21 @@ require 'spec_helper'
|
|
3
3
|
describe '#setnx(key, value)' do
|
4
4
|
before { @key = 'mock-redis-test:setnx' }
|
5
5
|
|
6
|
-
it
|
6
|
+
it 'returns true if the key was absent' do
|
7
7
|
@redises.setnx(@key, 1).should == true
|
8
8
|
end
|
9
9
|
|
10
|
-
it
|
10
|
+
it 'returns false if the key was present' do
|
11
11
|
@redises.set(@key, 2)
|
12
12
|
@redises.setnx(@key, 1).should == false
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
15
|
+
it 'sets the value if missing' do
|
16
16
|
@redises.setnx(@key, 'value')
|
17
17
|
@redises.get(@key).should == 'value'
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
20
|
+
it 'does nothing if the value is present' do
|
21
21
|
@redises.set(@key, 'old')
|
22
22
|
@redises.setnx(@key, 'new')
|
23
23
|
@redises.get(@key).should == 'old'
|
@@ -1,30 +1,30 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#setrange(key, offset, value)' do
|
4
4
|
before do
|
5
5
|
@key = 'mock-redis-test:setrange'
|
6
|
-
@redises.set(@key,
|
6
|
+
@redises.set(@key, 'This is a string')
|
7
7
|
end
|
8
8
|
|
9
9
|
it "returns the string's new length" do
|
10
|
-
@redises.setrange(@key, 0,
|
10
|
+
@redises.setrange(@key, 0, 'That').should == 16
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
14
|
-
@redises.setrange(@key, 0,
|
15
|
-
@redises.get(@key).should ==
|
13
|
+
it 'updates part of the string' do
|
14
|
+
@redises.setrange(@key, 0, 'That')
|
15
|
+
@redises.get(@key).should == 'That is a string'
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
19
|
-
@redises.setrange(@key, 20,
|
18
|
+
it 'zero-pads the string if necessary' do
|
19
|
+
@redises.setrange(@key, 20, 'X')
|
20
20
|
@redises.get(@key).should == "This is a string\000\000\000\000X"
|
21
21
|
end
|
22
22
|
|
23
|
-
it
|
24
|
-
other_key =
|
23
|
+
it 'stores things as strings' do
|
24
|
+
other_key = 'mock-redis-test:setrange-other-key'
|
25
25
|
@redises.setrange(other_key, 0, 1)
|
26
|
-
@redises.get(other_key).should ==
|
26
|
+
@redises.get(other_key).should == '1'
|
27
27
|
end
|
28
28
|
|
29
|
-
it_should_behave_like
|
29
|
+
it_should_behave_like 'a string-only command'
|
30
30
|
end
|
@@ -6,26 +6,26 @@ describe '#sinter(key [, key, ...])' do
|
|
6
6
|
@evens = 'mock-redis-test:sinter:evens'
|
7
7
|
@primes = 'mock-redis-test:sinter:primes'
|
8
8
|
|
9
|
-
(1..10).each {|i| @redises.sadd(@numbers, i) }
|
10
|
-
[2, 4, 6, 8, 10].each {|i| @redises.sadd(@evens, i) }
|
11
|
-
[2, 3, 5, 7].each {|i| @redises.sadd(@primes, i) }
|
9
|
+
(1..10).each { |i| @redises.sadd(@numbers, i) }
|
10
|
+
[2, 4, 6, 8, 10].each { |i| @redises.sadd(@evens, i) }
|
11
|
+
[2, 3, 5, 7].each { |i| @redises.sadd(@primes, i) }
|
12
12
|
end
|
13
13
|
|
14
|
-
it
|
15
|
-
@redises.sinter(@evens, @primes).should == [
|
14
|
+
it 'returns the elements in the resulting set' do
|
15
|
+
@redises.sinter(@evens, @primes).should == ['2']
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
18
|
+
it 'treats missing keys as empty sets' do
|
19
19
|
@redises.sinter(@destination, 'mock-redis-test:nonesuch').should == []
|
20
20
|
end
|
21
21
|
|
22
|
-
it
|
22
|
+
it 'raises an error if given 0 sets' do
|
23
23
|
lambda do
|
24
24
|
@redises.sinter
|
25
25
|
end.should raise_error(RuntimeError)
|
26
26
|
end
|
27
27
|
|
28
|
-
it
|
28
|
+
it 'raises an error if any argument is not a a set' do
|
29
29
|
@redises.set('mock-redis-test:notset', 1)
|
30
30
|
|
31
31
|
lambda do
|
@@ -37,5 +37,3 @@ describe '#sinter(key [, key, ...])' do
|
|
37
37
|
end.should raise_error(RuntimeError)
|
38
38
|
end
|
39
39
|
end
|
40
|
-
|
41
|
-
|
@@ -7,39 +7,39 @@ describe '#sinterstore(destination, key [, key, ...])' do
|
|
7
7
|
@primes = 'mock-redis-test:sinterstore:primes'
|
8
8
|
@destination = 'mock-redis-test:sinterstore:destination'
|
9
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) }
|
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
13
|
end
|
14
14
|
|
15
|
-
it
|
15
|
+
it 'returns the number of elements in the resulting set' do
|
16
16
|
@redises.sinterstore(@destination, @numbers, @evens).should == 5
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
19
|
+
it 'stores the resulting set' do
|
20
20
|
@redises.sinterstore(@destination, @numbers, @evens)
|
21
21
|
@redises.smembers(@destination).should == %w[10 8 6 4 2]
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
24
|
+
it 'does not store empty sets' do
|
25
25
|
@redises.sinterstore(@destination, 'mock-redis-test:nonesuch', @numbers).should == 0
|
26
26
|
@redises.get(@destination).should be_nil
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
29
|
+
it 'removes existing elements in destination' do
|
30
30
|
@redises.sadd(@destination, 42)
|
31
31
|
|
32
32
|
@redises.sinterstore(@destination, @primes)
|
33
33
|
@redises.smembers(@destination).should == %w[7 5 3 2]
|
34
34
|
end
|
35
35
|
|
36
|
-
it
|
36
|
+
it 'raises an error if given 0 sets' do
|
37
37
|
lambda do
|
38
38
|
@redises.sinterstore(@destination)
|
39
39
|
end.should raise_error(RuntimeError)
|
40
40
|
end
|
41
41
|
|
42
|
-
it
|
42
|
+
it 'raises an error if any argument is not a a set' do
|
43
43
|
@redises.set('mock-redis-test:notset', 1)
|
44
44
|
|
45
45
|
lambda do
|