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,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#exists(key)" do
|
4
|
+
before { @key = 'mock-redis-test:45794' }
|
5
|
+
|
6
|
+
it "returns false for keys that do not exist" do
|
7
|
+
@redises.exists(@key).should be_false
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns true for keys that do exist" do
|
11
|
+
@redises.set(@key, 1)
|
12
|
+
@redises.exists(@key).should be_true
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#expire(key, seconds)" do
|
4
|
+
before do
|
5
|
+
@key = 'mock-redis-test:expire'
|
6
|
+
@redises.set(@key, 'spork')
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns true for a key that exists" do
|
10
|
+
@redises.expire(@key, 1).should be_true
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns false for a key that does not exist" do
|
14
|
+
@redises.expire('mock-redis-test:nonesuch', 1).should be_false
|
15
|
+
end
|
16
|
+
|
17
|
+
it "removes a key immediately when seconds==0" do
|
18
|
+
@redises.expire(@key, 0)
|
19
|
+
@redises.get(@key).should be_nil
|
20
|
+
end
|
21
|
+
|
22
|
+
it "raises an error if seconds is bogus" do
|
23
|
+
lambda do
|
24
|
+
@redises.expireat(@key, 'a couple minutes or so')
|
25
|
+
end.should raise_error(RuntimeError)
|
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 "removes keys after enough time has passed" do
|
42
|
+
@mock.expire(@key, 5)
|
43
|
+
Time.stub!(:now).and_return(@now + 5)
|
44
|
+
@mock.get(@key).should be_nil
|
45
|
+
end
|
46
|
+
|
47
|
+
it "updates an existing expire time" do
|
48
|
+
@mock.expire(@key, 5)
|
49
|
+
@mock.expire(@key, 6)
|
50
|
+
|
51
|
+
Time.stub!(:now).and_return(@now + 5)
|
52
|
+
@mock.get(@key).should_not be_nil
|
53
|
+
end
|
54
|
+
|
55
|
+
context "expirations on a deleted key" do
|
56
|
+
before { @mock.del(@key) }
|
57
|
+
|
58
|
+
it "cleans up the expiration once the key is gone (string)" do
|
59
|
+
@mock.set(@key, 'string')
|
60
|
+
@mock.expire(@key, 2)
|
61
|
+
@mock.del(@key)
|
62
|
+
@mock.set(@key, 'string')
|
63
|
+
|
64
|
+
Time.stub!(:now).and_return(@now + 2)
|
65
|
+
|
66
|
+
@mock.get(@key).should_not be_nil
|
67
|
+
end
|
68
|
+
|
69
|
+
it "cleans up the expiration once the key is gone (list)" do
|
70
|
+
@mock.rpush(@key, 'coconuts')
|
71
|
+
@mock.expire(@key, 2)
|
72
|
+
@mock.rpop(@key)
|
73
|
+
|
74
|
+
@mock.rpush(@key, 'coconuts')
|
75
|
+
|
76
|
+
Time.stub!(:now).and_return(@now + 2)
|
77
|
+
|
78
|
+
@mock.lindex(@key, 0).should_not be_nil
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#expireat(key, timestamp)" do
|
4
|
+
before do
|
5
|
+
@key = 'mock-redis-test:expireat'
|
6
|
+
@redises.set(@key, 'spork')
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns true for a key that exists" do
|
10
|
+
@redises.expireat(@key, Time.now.to_i + 1).should be_true
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns false for a key that does not exist" do
|
14
|
+
@redises.expireat('mock-redis-test:nonesuch', Time.now.to_i + 1).should be_false
|
15
|
+
end
|
16
|
+
|
17
|
+
it "removes a key immediately when timestamp is now" do
|
18
|
+
@redises.expireat(@key, Time.now.to_i)
|
19
|
+
@redises.get(@key).should be_nil
|
20
|
+
end
|
21
|
+
|
22
|
+
it "raises an error if you don't give it a Unix timestamp" do
|
23
|
+
lambda do
|
24
|
+
@redises.expireat(@key, Time.now) # oops, forgot .to_i
|
25
|
+
end.should raise_error(RuntimeError)
|
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 "removes keys after enough time has passed" do
|
42
|
+
@mock.expireat(@key, @now.to_i + 5)
|
43
|
+
Time.stub!(:now).and_return(@now + 5)
|
44
|
+
@mock.get(@key).should be_nil
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#flushall [mock only]" do
|
4
|
+
# don't want to hurt things in the real redis that are outside our
|
5
|
+
# namespace.
|
6
|
+
before { @mock = @redises.mock }
|
7
|
+
before { @key = 'mock-redis-test:select' }
|
8
|
+
|
9
|
+
it "returns 'OK'" do
|
10
|
+
@mock.flushall.should == 'OK'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "removes all keys in the current DB" do
|
14
|
+
@mock.set('k1', 'v1')
|
15
|
+
@mock.lpush('k2', 'v2')
|
16
|
+
|
17
|
+
@mock.flushall
|
18
|
+
@mock.keys('*').should == []
|
19
|
+
end
|
20
|
+
|
21
|
+
it "removes all keys in other DBs, too" do
|
22
|
+
@mock.set('k1', 'v1')
|
23
|
+
|
24
|
+
@mock.select(1)
|
25
|
+
@mock.flushall
|
26
|
+
@mock.select(0)
|
27
|
+
|
28
|
+
@mock.get('k1').should be_nil
|
29
|
+
end
|
30
|
+
|
31
|
+
it "removes expiration times" do
|
32
|
+
@mock.set('k1', 'v1')
|
33
|
+
@mock.expire('k1', 360000)
|
34
|
+
@mock.flushall
|
35
|
+
@mock.set('k1', 'v1')
|
36
|
+
@mock.ttl('k1').should == -1
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#flushdb [mock only]" do
|
4
|
+
# don't want to hurt things in the real redis that are outside our
|
5
|
+
# namespace.
|
6
|
+
before { @mock = @redises.mock }
|
7
|
+
before { @key = 'mock-redis-test:select' }
|
8
|
+
|
9
|
+
it "returns 'OK'" do
|
10
|
+
@mock.flushdb.should == 'OK'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "removes all keys in the current DB" do
|
14
|
+
@mock.set('k1', 'v1')
|
15
|
+
@mock.lpush('k2', 'v2')
|
16
|
+
|
17
|
+
@mock.flushdb
|
18
|
+
@mock.keys('*').should == []
|
19
|
+
end
|
20
|
+
|
21
|
+
it "leaves other databases alone" do
|
22
|
+
@mock.set('k1', 'v1')
|
23
|
+
|
24
|
+
@mock.select(1)
|
25
|
+
@mock.flushdb
|
26
|
+
@mock.select(0)
|
27
|
+
|
28
|
+
@mock.get('k1').should == 'v1'
|
29
|
+
end
|
30
|
+
|
31
|
+
it "removes expiration times" do
|
32
|
+
@mock.set('k1', 'v1')
|
33
|
+
@mock.expire('k1', 360000)
|
34
|
+
@mock.flushdb
|
35
|
+
@mock.set('k1', 'v1')
|
36
|
+
@mock.ttl('k1').should == -1
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#get(key)" do
|
4
|
+
before do
|
5
|
+
@key = 'mock-redis-test:73288'
|
6
|
+
end
|
7
|
+
|
8
|
+
it "returns nil for a nonexistent value" do
|
9
|
+
@redises.get('mock-redis-test:does-not-exist').should be_nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns a stored string value" do
|
13
|
+
@redises.set(@key, 'forsooth')
|
14
|
+
@redises.get(@key).should == 'forsooth'
|
15
|
+
end
|
16
|
+
|
17
|
+
it "treats integers as strings" do
|
18
|
+
@redises.set(@key, 100)
|
19
|
+
@redises.get(@key).should == "100"
|
20
|
+
end
|
21
|
+
|
22
|
+
it_should_behave_like "a string-only command"
|
23
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#getbit(key, offset)" do
|
4
|
+
before do
|
5
|
+
@key = 'mock-redis-test:getbit'
|
6
|
+
@redises.set(@key, 'h') # ASCII 0x68
|
7
|
+
end
|
8
|
+
|
9
|
+
it "gets the bits from the key" do
|
10
|
+
@redises.getbit(@key, 0).should == 0
|
11
|
+
@redises.getbit(@key, 1).should == 1
|
12
|
+
@redises.getbit(@key, 2).should == 1
|
13
|
+
@redises.getbit(@key, 3).should == 0
|
14
|
+
@redises.getbit(@key, 4).should == 1
|
15
|
+
@redises.getbit(@key, 5).should == 0
|
16
|
+
@redises.getbit(@key, 6).should == 0
|
17
|
+
@redises.getbit(@key, 7).should == 0
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns 0 for out-of-range bits" do
|
21
|
+
@redises.getbit(@key, 100).should == 0
|
22
|
+
end
|
23
|
+
|
24
|
+
it "does not modify the stored value for out-of-range bits" do
|
25
|
+
@redises.getbit(@key, 100)
|
26
|
+
@redises.get(@key).should == 'h'
|
27
|
+
end
|
28
|
+
|
29
|
+
it "treats nonexistent keys as empty strings" do
|
30
|
+
@redises.getbit('mock-redis-test:not-found', 0).should == 0
|
31
|
+
end
|
32
|
+
|
33
|
+
it_should_behave_like "a string-only command"
|
34
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#getrange(key, start, stop)" do
|
4
|
+
before do
|
5
|
+
@key = 'mock-redis-test:getrange'
|
6
|
+
@redises.set(@key, "This is a string")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns a substring" do
|
10
|
+
@redises.getrange(@key, 0, 3).should == "This"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "works with negative indices" do
|
14
|
+
@redises.getrange(@key, -3, -1).should == "ing"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "limits the result to the actual length of the string" do
|
18
|
+
@redises.getrange(@key, 10, 100).should == "string"
|
19
|
+
end
|
20
|
+
|
21
|
+
it_should_behave_like "a string-only command"
|
22
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#getrange(key, value)" do
|
4
|
+
before do
|
5
|
+
@key = 'mock-redis-test:getset'
|
6
|
+
@redises.set(@key, "oldvalue")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns the old value" do
|
10
|
+
@redises.getset(@key, 'newvalue').should == "oldvalue"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "sets the value to the new value" do
|
14
|
+
@redises.getset(@key, 'newvalue')
|
15
|
+
@redises.get(@key).should == 'newvalue'
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns nil for nonexistent keys" do
|
19
|
+
@redises.getset('mock-redis-test:not-found', 1).should be_nil
|
20
|
+
end
|
21
|
+
|
22
|
+
it_should_behave_like "a string-only command"
|
23
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#hdel(key, field)" do
|
4
|
+
before do
|
5
|
+
@key = "mock-redis-test:hdel"
|
6
|
+
@redises.hset(@key, 'k1', 'v1')
|
7
|
+
@redises.hset(@key, 'k2', 'v2')
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns 1 when it removes a field" do
|
11
|
+
@redises.hdel(@key, 'k1').should == 1
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns 0 when it does not remove a field" do
|
15
|
+
@redises.hdel(@key, 'nonesuch').should == 0
|
16
|
+
end
|
17
|
+
|
18
|
+
it "actually removes the field" do
|
19
|
+
@redises.hdel(@key, 'k1')
|
20
|
+
@redises.hget(@key, 'k1').should be_nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it "removes only the field specified" do
|
24
|
+
@redises.hdel(@key, 'k1')
|
25
|
+
@redises.hget(@key, 'k2').should == 'v2'
|
26
|
+
end
|
27
|
+
|
28
|
+
it "cleans up empty hashes" do
|
29
|
+
@redises.hdel(@key, 'k1')
|
30
|
+
@redises.hdel(@key, 'k2')
|
31
|
+
@redises.get(@key).should be_nil
|
32
|
+
end
|
33
|
+
|
34
|
+
it_should_behave_like "a hash-only command"
|
35
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#hexists(key, field)" do
|
4
|
+
before do
|
5
|
+
@key = "mock-redis-test:hexists"
|
6
|
+
@redises.hset(@key, 'field', 'value')
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns true if the hash has that field" do
|
10
|
+
@redises.hexists(@key, 'field').should be_true
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns false if the hash lacks that field" do
|
14
|
+
@redises.hexists(@key, 'nonesuch').should be_false
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns nil when there is no such key" do
|
18
|
+
@redises.hexists('mock-redis-test:nonesuch', 'key').should be_false
|
19
|
+
end
|
20
|
+
|
21
|
+
it_should_behave_like "a hash-only command"
|
22
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#hget(key, field)" do
|
4
|
+
before do
|
5
|
+
@key = "mock-redis-test:hget"
|
6
|
+
@redises.hset(@key, 'k1', 'v1')
|
7
|
+
@redises.hset(@key, 'k2', 'v2')
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns the value stored at field" do
|
11
|
+
@redises.hget(@key, 'k1').should == 'v1'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns nil when there is no such field" do
|
15
|
+
@redises.hget(@key, 'nonesuch').should be_nil
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns nil when there is no such key" do
|
19
|
+
@redises.hget('mock-redis-test:nonesuch', 'k1').should be_nil
|
20
|
+
end
|
21
|
+
|
22
|
+
it_should_behave_like "a hash-only command"
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#hgetall(key)" do
|
4
|
+
before do
|
5
|
+
@key = "mock-redis-test:hgetall"
|
6
|
+
@redises.hset(@key, 'k1', 'v1')
|
7
|
+
@redises.hset(@key, 'k2', 'v2')
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns the (key, value) pairs stored in the hash" do
|
11
|
+
@redises.hgetall(@key).should == {
|
12
|
+
'k1' => 'v1',
|
13
|
+
'k2' => 'v2',
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns [] when there is no such key" do
|
18
|
+
@redises.hgetall('mock-redis-test:nonesuch').should == {}
|
19
|
+
end
|
20
|
+
|
21
|
+
it_should_behave_like "a hash-only command"
|
22
|
+
end
|