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,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#rpush(key)" do
|
4
|
+
before { @key = "mock-redis-test:#{__FILE__}" }
|
5
|
+
|
6
|
+
it "returns the new size of the list" do
|
7
|
+
@redises.rpush(@key, 'X').should == 1
|
8
|
+
@redises.rpush(@key, 'X').should == 2
|
9
|
+
end
|
10
|
+
|
11
|
+
it "creates a new list when run against a nonexistent key" do
|
12
|
+
@redises.rpush(@key, 'value')
|
13
|
+
@redises.llen(@key).should == 1
|
14
|
+
end
|
15
|
+
|
16
|
+
it "appends items to the list" do
|
17
|
+
@redises.rpush(@key, "bert")
|
18
|
+
@redises.rpush(@key, "ernie")
|
19
|
+
|
20
|
+
@redises.lindex(@key, 0).should == "bert"
|
21
|
+
@redises.lindex(@key, 1).should == "ernie"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "stores values as strings" do
|
25
|
+
@redises.rpush(@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 "#rpushx(key, value)" do
|
4
|
+
before { @key = 'mock-redis-test:92925' }
|
5
|
+
|
6
|
+
it "returns the new size of the list" do
|
7
|
+
@redises.lpush(@key, 'X')
|
8
|
+
|
9
|
+
@redises.rpushx(@key, 'X').should == 2
|
10
|
+
@redises.rpushx(@key, 'X').should == 3
|
11
|
+
end
|
12
|
+
|
13
|
+
it "does nothing when run against a nonexistent key" do
|
14
|
+
@redises.rpushx(@key, 'value')
|
15
|
+
@redises.get(@key).should be_nil
|
16
|
+
end
|
17
|
+
|
18
|
+
it "appends items to the list" do
|
19
|
+
@redises.lpush(@key, "bert")
|
20
|
+
@redises.rpushx(@key, "ernie")
|
21
|
+
|
22
|
+
@redises.lindex(@key, 0).should == "bert"
|
23
|
+
@redises.lindex(@key, 1).should == "ernie"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "stores values as strings" do
|
27
|
+
@redises.rpush(@key, 1)
|
28
|
+
@redises.rpushx(@key, 2)
|
29
|
+
@redises.lindex(@key, 1).should == "2"
|
30
|
+
end
|
31
|
+
|
32
|
+
it_should_behave_like "a list-only command"
|
33
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#sadd(key, member)' do
|
4
|
+
before { @key = 'mock-redis-test:sadd' }
|
5
|
+
|
6
|
+
it "returns true if the set did not already contain member" do
|
7
|
+
@redises.sadd(@key, 1).should be_true
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns false if the set did already contain member" do
|
11
|
+
@redises.sadd(@key, 1)
|
12
|
+
@redises.sadd(@key, 1).should be_false
|
13
|
+
end
|
14
|
+
|
15
|
+
it "adds member to the set" do
|
16
|
+
@redises.sadd(@key, 1)
|
17
|
+
@redises.sadd(@key, 2)
|
18
|
+
@redises.smembers(@key).should == %w[1 2]
|
19
|
+
end
|
20
|
+
|
21
|
+
it_should_behave_like "a set-only command"
|
22
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#scard(key)' do
|
4
|
+
before { @key = 'mock-redis-test:scard' }
|
5
|
+
|
6
|
+
it "returns 0 for an empty set" do
|
7
|
+
@redises.scard(@key).should == 0
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns the number of elements in the set" do
|
11
|
+
@redises.sadd(@key, 'one')
|
12
|
+
@redises.sadd(@key, 'two')
|
13
|
+
@redises.sadd(@key, 'three')
|
14
|
+
@redises.scard(@key).should == 3
|
15
|
+
end
|
16
|
+
|
17
|
+
it_should_behave_like "a set-only command"
|
18
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#sdiff(key [, key, ...])' do
|
4
|
+
before do
|
5
|
+
@numbers = 'mock-redis-test:sdiff:numbers'
|
6
|
+
@evens = 'mock-redis-test:sdiff:odds'
|
7
|
+
@primes = 'mock-redis-test:sdiff:primes'
|
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) }
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns the first set minus the second set" do
|
15
|
+
@redises.sdiff(@numbers, @evens).should == %w[1 3 5 7 9]
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns the first set minus all the other sets" do
|
19
|
+
@redises.sdiff(@numbers, @evens, @primes).should == %w[1 9]
|
20
|
+
end
|
21
|
+
|
22
|
+
it "treats missing keys as empty sets" do
|
23
|
+
@redises.sdiff(@evens, 'mock-redis-test:nonesuch').should == %w[10 2 4 6 8]
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns the first set when called with a single argument" do
|
27
|
+
@redises.sdiff(@primes).should == %w[2 3 5 7]
|
28
|
+
end
|
29
|
+
|
30
|
+
it "raises an error if given 0 arguments" do
|
31
|
+
lambda do
|
32
|
+
@redises.sdiff()
|
33
|
+
end.should raise_error(RuntimeError)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "raises an error if any argument is not a a set" do
|
37
|
+
@redises.set('foo', 1)
|
38
|
+
|
39
|
+
lambda do
|
40
|
+
@redises.sdiff(@numbers, 'foo')
|
41
|
+
end.should raise_error(RuntimeError)
|
42
|
+
|
43
|
+
lambda do
|
44
|
+
@redises.sdiff('foo', @numbers)
|
45
|
+
end.should raise_error(RuntimeError)
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#sdiffstore(destination, key [, key, ...])' do
|
4
|
+
before do
|
5
|
+
@numbers = 'mock-redis-test:sdiffstore:numbers'
|
6
|
+
@evens = 'mock-redis-test:sdiffstore:evens'
|
7
|
+
@primes = 'mock-redis-test:sdiffstore:primes'
|
8
|
+
@destination = 'mock-redis-test:sdiffstore: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.sdiffstore(@destination, @numbers, @evens).should == 5
|
17
|
+
end
|
18
|
+
|
19
|
+
it "stores the resulting set" do
|
20
|
+
@redises.sdiffstore(@destination, @numbers, @evens)
|
21
|
+
@redises.smembers(@destination).should == %w[1 3 5 7 9]
|
22
|
+
end
|
23
|
+
|
24
|
+
it "does not store empty sets" do
|
25
|
+
@redises.sdiffstore(@destination, @numbers, @numbers).should == 0
|
26
|
+
@redises.get(@destination).should be_nil
|
27
|
+
end
|
28
|
+
|
29
|
+
it "treats missing keys as empty sets" do
|
30
|
+
@redises.sdiffstore(@destination, @evens, 'mock-redis-test:nonesuch')
|
31
|
+
@redises.smembers(@destination).should == %w[10 2 4 6 8]
|
32
|
+
end
|
33
|
+
|
34
|
+
it "removes existing elements in destination" do
|
35
|
+
@redises.sadd(@destination, 42)
|
36
|
+
|
37
|
+
@redises.sdiffstore(@destination, @primes)
|
38
|
+
@redises.smembers(@destination).should == %w[2 3 5 7]
|
39
|
+
end
|
40
|
+
|
41
|
+
it "raises an error if given 0 sets" do
|
42
|
+
lambda do
|
43
|
+
@redises.sdiffstore(@destination)
|
44
|
+
end.should raise_error(RuntimeError)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "raises an error if any argument is not a a set" do
|
48
|
+
@redises.set('mock-redis-test:notset', 1)
|
49
|
+
|
50
|
+
lambda do
|
51
|
+
@redises.sdiffstore(@destination, @numbers, 'mock-redis-test:notset')
|
52
|
+
end.should raise_error(RuntimeError)
|
53
|
+
|
54
|
+
lambda do
|
55
|
+
@redises.sdiffstore(@destination, 'mock-redis-test:notset', @numbers)
|
56
|
+
end.should raise_error(RuntimeError)
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#select(db)" do
|
4
|
+
before { @key = 'mock-redis-test:select' }
|
5
|
+
|
6
|
+
it "returns 'OK'" do
|
7
|
+
@redises.select(0).should == 'OK'
|
8
|
+
end
|
9
|
+
|
10
|
+
it "treats '0' and 0 the same" do
|
11
|
+
@redises.select('0')
|
12
|
+
@redises.set(@key, 'foo')
|
13
|
+
@redises.select(0)
|
14
|
+
@redises.get(@key).should == 'foo'
|
15
|
+
end
|
16
|
+
|
17
|
+
it "switches databases" do
|
18
|
+
@redises.select(0)
|
19
|
+
@redises.set(@key, 'foo')
|
20
|
+
|
21
|
+
@redises.select(1)
|
22
|
+
@redises.get(@key).should be_nil
|
23
|
+
|
24
|
+
@redises.select(0)
|
25
|
+
@redises.get(@key).should == 'foo'
|
26
|
+
end
|
27
|
+
|
28
|
+
context "[mock only]" do
|
29
|
+
# Time dependence introduces a bit of nondeterminism here
|
30
|
+
before do
|
31
|
+
@now = Time.now
|
32
|
+
Time.stub!(:now).and_return(@now)
|
33
|
+
|
34
|
+
@mock = @redises.mock
|
35
|
+
|
36
|
+
@mock.select(0)
|
37
|
+
@mock.set(@key, 1)
|
38
|
+
@mock.expire(@key, 101)
|
39
|
+
|
40
|
+
@mock.select(1)
|
41
|
+
@mock.set(@key, 2)
|
42
|
+
@mock.expire(@key, 201)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "keeps expire times per-db" do
|
46
|
+
@mock.select(0)
|
47
|
+
@mock.ttl(@key).should == 100
|
48
|
+
|
49
|
+
@mock.select(1)
|
50
|
+
@mock.ttl(@key).should == 200
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "#setbit(key, offset)" do
|
5
|
+
before do
|
6
|
+
@key = 'mock-redis-test:setbit'
|
7
|
+
@redises.set(@key, 'h') # ASCII 0x68
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns the original stored bit's value" do
|
11
|
+
@redises.setbit(@key, 0, 1).should == 0
|
12
|
+
@redises.setbit(@key, 1, 1).should == 1
|
13
|
+
end
|
14
|
+
|
15
|
+
it "sets the bit within the string" do
|
16
|
+
$debug = true
|
17
|
+
@redises.setbit(@key, 7, 1)
|
18
|
+
$debug = false
|
19
|
+
@redises.get(@key).should == 'i' # ASCII 0x69
|
20
|
+
end
|
21
|
+
|
22
|
+
it "does the right thing with multibyte characters" do
|
23
|
+
@redises.set(@key, "€99.94") # the euro sign is 3 bytes wide in UTF-8
|
24
|
+
@redises.setbit(@key, 63, 1).should == 0
|
25
|
+
@redises.get(@key).should == "€99.95"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "expands the string if necessary" do
|
29
|
+
@redises.setbit(@key, 9, 1)
|
30
|
+
@redises.get(@key).should == "h@"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "sets added bits to 0" do
|
34
|
+
@redises.setbit(@key, 17, 1)
|
35
|
+
@redises.get(@key).should == "h\000@"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "treats missing keys as empty strings" do
|
39
|
+
@redises.del(@key)
|
40
|
+
@redises.setbit(@key, 1, 1)
|
41
|
+
@redises.get(@key).should == "@"
|
42
|
+
end
|
43
|
+
|
44
|
+
it_should_behave_like "a string-only command"
|
45
|
+
end
|
46
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#setex(key, seconds, value)' do
|
4
|
+
before { @key = 'mock-redis-test:setex' }
|
5
|
+
|
6
|
+
it "responds with 'OK'" do
|
7
|
+
@redises.setex(@key, 10, 'value').should == 'OK'
|
8
|
+
end
|
9
|
+
|
10
|
+
it "sets the value" do
|
11
|
+
@redises.setex(@key, 10000, 'value')
|
12
|
+
@redises.get(@key).should == 'value'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "sets the expiration time" do
|
16
|
+
@redises.setex(@key, 10000, 'value')
|
17
|
+
|
18
|
+
# no guarantee these are the same
|
19
|
+
@redises.real.ttl(@key).should > 0
|
20
|
+
@redises.mock.ttl(@key).should > 0
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#setnx(key, value)' do
|
4
|
+
before { @key = 'mock-redis-test:setnx' }
|
5
|
+
|
6
|
+
it "returns true if the key was absent" do
|
7
|
+
@redises.setnx(@key, 1).should be_true
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns false if the key was present" do
|
11
|
+
@redises.set(@key, 2)
|
12
|
+
@redises.setnx(@key, 1).should be_false
|
13
|
+
end
|
14
|
+
|
15
|
+
it "sets the value if missing" do
|
16
|
+
@redises.setnx(@key, 'value')
|
17
|
+
@redises.get(@key).should == 'value'
|
18
|
+
end
|
19
|
+
|
20
|
+
it "does nothing if the value is present" do
|
21
|
+
@redises.set(@key, 'old')
|
22
|
+
@redises.setnx(@key, 'new')
|
23
|
+
@redises.get(@key).should == 'old'
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#setrange(key, offset, value)" do
|
4
|
+
before do
|
5
|
+
@key = 'mock-redis-test:setrange'
|
6
|
+
@redises.set(@key, "This is a string")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns the string's new length" do
|
10
|
+
@redises.setrange(@key, 0, "That").should == 16
|
11
|
+
end
|
12
|
+
|
13
|
+
it "updates part of the string" do
|
14
|
+
@redises.setrange(@key, 0, "That")
|
15
|
+
@redises.get(@key).should == "That is a string"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "zero-pads the string if necessary" do
|
19
|
+
@redises.setrange(@key, 20, "X")
|
20
|
+
@redises.get(@key).should == "This is a string\000\000\000\000X"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "stores things as strings" do
|
24
|
+
other_key = "mock-redis-test:setrange-other-key"
|
25
|
+
@redises.setrange(other_key, 0, 1)
|
26
|
+
@redises.get(other_key).should == "1"
|
27
|
+
end
|
28
|
+
|
29
|
+
it_should_behave_like "a string-only command"
|
30
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#sinter(key [, key, ...])' do
|
4
|
+
before do
|
5
|
+
@numbers = 'mock-redis-test:sinter:numbers'
|
6
|
+
@evens = 'mock-redis-test:sinter:evens'
|
7
|
+
@primes = 'mock-redis-test:sinter:primes'
|
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) }
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns the elements in the resulting set" do
|
15
|
+
@redises.sinter(@evens, @primes).should == ["2"]
|
16
|
+
end
|
17
|
+
|
18
|
+
it "treats missing keys as empty sets" do
|
19
|
+
@redises.sinter(@destination, 'mock-redis-test:nonesuch').should == []
|
20
|
+
end
|
21
|
+
|
22
|
+
it "raises an error if given 0 sets" do
|
23
|
+
lambda do
|
24
|
+
@redises.sinter
|
25
|
+
end.should raise_error(RuntimeError)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "raises an error if any argument is not a a set" do
|
29
|
+
@redises.set('mock-redis-test:notset', 1)
|
30
|
+
|
31
|
+
lambda do
|
32
|
+
@redises.sinter(@numbers, 'mock-redis-test:notset')
|
33
|
+
end.should raise_error(RuntimeError)
|
34
|
+
|
35
|
+
lambda do
|
36
|
+
@redises.sinter('mock-redis-test:notset', @numbers)
|
37
|
+
end.should raise_error(RuntimeError)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|