mock_redis 0.32.0 → 0.44.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +59 -0
- data/README.md +4 -4
- data/lib/mock_redis/database.rb +42 -13
- data/lib/mock_redis/geospatial_methods.rb +2 -2
- data/lib/mock_redis/hash_methods.rb +1 -1
- data/lib/mock_redis/list_methods.rb +37 -2
- data/lib/mock_redis/memory_method.rb +11 -0
- data/lib/mock_redis/multi_db_wrapper.rb +1 -1
- data/lib/mock_redis/pipelined_wrapper.rb +12 -14
- data/lib/mock_redis/set_methods.rb +18 -2
- data/lib/mock_redis/stream.rb +3 -3
- data/lib/mock_redis/string_methods.rb +33 -6
- data/lib/mock_redis/transaction_wrapper.rb +5 -7
- data/lib/mock_redis/utility_methods.rb +4 -2
- data/lib/mock_redis/version.rb +1 -1
- data/lib/mock_redis/zset.rb +4 -2
- data/lib/mock_redis/zset_methods.rb +13 -4
- data/lib/mock_redis.rb +5 -6
- metadata +20 -352
- data/.github/workflows/lint.yml +0 -31
- data/.github/workflows/tests.yml +0 -63
- data/.gitignore +0 -5
- data/.mailmap +0 -2
- data/.overcommit.yml +0 -21
- data/.rspec +0 -1
- data/.rubocop.yml +0 -148
- data/.rubocop_todo.yml +0 -35
- data/.simplecov +0 -4
- data/Gemfile +0 -13
- data/Rakefile +0 -2
- data/mock_redis.gemspec +0 -32
- data/spec/client_spec.rb +0 -29
- data/spec/cloning_spec.rb +0 -95
- data/spec/commands/append_spec.rb +0 -24
- data/spec/commands/auth_spec.rb +0 -7
- data/spec/commands/bgrewriteaof_spec.rb +0 -7
- data/spec/commands/bgsave_spec.rb +0 -7
- data/spec/commands/bitcount_spec.rb +0 -25
- data/spec/commands/bitfield_spec.rb +0 -169
- data/spec/commands/blpop_spec.rb +0 -53
- data/spec/commands/brpop_spec.rb +0 -59
- data/spec/commands/brpoplpush_spec.rb +0 -52
- data/spec/commands/connected_spec.rb +0 -7
- data/spec/commands/connection_spec.rb +0 -15
- data/spec/commands/dbsize_spec.rb +0 -18
- data/spec/commands/decr_spec.rb +0 -34
- data/spec/commands/decrby_spec.rb +0 -34
- data/spec/commands/del_spec.rb +0 -52
- data/spec/commands/disconnect_spec.rb +0 -7
- data/spec/commands/dump_spec.rb +0 -19
- data/spec/commands/echo_spec.rb +0 -11
- data/spec/commands/eval_spec.rb +0 -7
- data/spec/commands/evalsha_spec.rb +0 -10
- data/spec/commands/exists_spec.rb +0 -43
- data/spec/commands/expire_spec.rb +0 -111
- data/spec/commands/expireat_spec.rb +0 -47
- data/spec/commands/flushall_spec.rb +0 -38
- data/spec/commands/flushdb_spec.rb +0 -38
- data/spec/commands/future_spec.rb +0 -30
- data/spec/commands/geoadd_spec.rb +0 -58
- data/spec/commands/geodist_spec.rb +0 -118
- data/spec/commands/geohash_spec.rb +0 -52
- data/spec/commands/geopos_spec.rb +0 -55
- data/spec/commands/get_spec.rb +0 -31
- data/spec/commands/getbit_spec.rb +0 -34
- data/spec/commands/getrange_spec.rb +0 -22
- data/spec/commands/getset_spec.rb +0 -23
- data/spec/commands/hdel_spec.rb +0 -77
- data/spec/commands/hexists_spec.rb +0 -27
- data/spec/commands/hget_spec.rb +0 -28
- data/spec/commands/hgetall_spec.rb +0 -32
- data/spec/commands/hincrby_spec.rb +0 -58
- data/spec/commands/hincrbyfloat_spec.rb +0 -58
- data/spec/commands/hkeys_spec.rb +0 -19
- data/spec/commands/hlen_spec.rb +0 -19
- data/spec/commands/hmget_spec.rb +0 -46
- data/spec/commands/hmset_spec.rb +0 -69
- data/spec/commands/hscan_each_spec.rb +0 -48
- data/spec/commands/hscan_spec.rb +0 -27
- data/spec/commands/hset_spec.rb +0 -42
- data/spec/commands/hsetnx_spec.rb +0 -44
- data/spec/commands/hvals_spec.rb +0 -19
- data/spec/commands/incr_spec.rb +0 -34
- data/spec/commands/incrby_spec.rb +0 -44
- data/spec/commands/incrbyfloat_spec.rb +0 -44
- data/spec/commands/info_spec.rb +0 -62
- data/spec/commands/keys_spec.rb +0 -139
- data/spec/commands/lastsave_spec.rb +0 -8
- data/spec/commands/lindex_spec.rb +0 -49
- data/spec/commands/linsert_spec.rb +0 -68
- data/spec/commands/llen_spec.rb +0 -16
- data/spec/commands/lpop_spec.rb +0 -34
- data/spec/commands/lpush_spec.rb +0 -43
- data/spec/commands/lpushx_spec.rb +0 -46
- data/spec/commands/lrange_spec.rb +0 -51
- data/spec/commands/lrem_spec.rb +0 -80
- data/spec/commands/lset_spec.rb +0 -43
- data/spec/commands/ltrim_spec.rb +0 -45
- data/spec/commands/mapped_hmget_spec.rb +0 -29
- data/spec/commands/mapped_hmset_spec.rb +0 -47
- data/spec/commands/mapped_mget_spec.rb +0 -22
- data/spec/commands/mapped_mset_spec.rb +0 -19
- data/spec/commands/mapped_msetnx_spec.rb +0 -26
- data/spec/commands/mget_spec.rb +0 -65
- data/spec/commands/move_spec.rb +0 -147
- data/spec/commands/mset_spec.rb +0 -43
- data/spec/commands/msetnx_spec.rb +0 -40
- data/spec/commands/persist_spec.rb +0 -48
- data/spec/commands/pexpire_spec.rb +0 -86
- data/spec/commands/pexpireat_spec.rb +0 -48
- data/spec/commands/ping_spec.rb +0 -11
- data/spec/commands/pipelined_spec.rb +0 -114
- data/spec/commands/psetex_spec.rb +0 -44
- data/spec/commands/pttl_spec.rb +0 -41
- data/spec/commands/quit_spec.rb +0 -7
- data/spec/commands/randomkey_spec.rb +0 -20
- data/spec/commands/rename_spec.rb +0 -42
- data/spec/commands/renamenx_spec.rb +0 -41
- data/spec/commands/restore_spec.rb +0 -47
- data/spec/commands/rpop_spec.rb +0 -34
- data/spec/commands/rpoplpush_spec.rb +0 -50
- data/spec/commands/rpush_spec.rb +0 -43
- data/spec/commands/rpushx_spec.rb +0 -46
- data/spec/commands/sadd_spec.rb +0 -45
- data/spec/commands/save_spec.rb +0 -7
- data/spec/commands/scan_each_spec.rb +0 -39
- data/spec/commands/scan_spec.rb +0 -64
- data/spec/commands/scard_spec.rb +0 -18
- data/spec/commands/script_spec.rb +0 -9
- data/spec/commands/sdiff_spec.rb +0 -47
- data/spec/commands/sdiffstore_spec.rb +0 -58
- data/spec/commands/select_spec.rb +0 -61
- data/spec/commands/set_spec.rb +0 -119
- data/spec/commands/setbit_spec.rb +0 -55
- data/spec/commands/setex_spec.rb +0 -38
- data/spec/commands/setnx_spec.rb +0 -25
- data/spec/commands/setrange_spec.rb +0 -30
- data/spec/commands/sinter_spec.rb +0 -39
- data/spec/commands/sinterstore_spec.rb +0 -53
- data/spec/commands/sismember_spec.rb +0 -29
- data/spec/commands/smembers_spec.rb +0 -28
- data/spec/commands/smove_spec.rb +0 -41
- data/spec/commands/sort_list_spec.rb +0 -21
- data/spec/commands/sort_set_spec.rb +0 -21
- data/spec/commands/sort_zset_spec.rb +0 -21
- data/spec/commands/spop_spec.rb +0 -40
- data/spec/commands/srandmember_spec.rb +0 -49
- data/spec/commands/srem_spec.rb +0 -45
- data/spec/commands/sscan_each_spec.rb +0 -48
- data/spec/commands/sscan_spec.rb +0 -39
- data/spec/commands/strlen_spec.rb +0 -18
- data/spec/commands/sunion_spec.rb +0 -42
- data/spec/commands/sunionstore_spec.rb +0 -59
- data/spec/commands/ttl_spec.rb +0 -40
- data/spec/commands/type_spec.rb +0 -36
- data/spec/commands/unwatch_spec.rb +0 -7
- data/spec/commands/watch_spec.rb +0 -21
- data/spec/commands/xadd_spec.rb +0 -122
- data/spec/commands/xlen_spec.rb +0 -22
- data/spec/commands/xrange_spec.rb +0 -164
- data/spec/commands/xread_spec.rb +0 -66
- data/spec/commands/xrevrange_spec.rb +0 -130
- data/spec/commands/xtrim_spec.rb +0 -36
- data/spec/commands/zadd_spec.rb +0 -129
- data/spec/commands/zcard_spec.rb +0 -19
- data/spec/commands/zcount_spec.rb +0 -39
- data/spec/commands/zincrby_spec.rb +0 -31
- data/spec/commands/zinterstore_spec.rb +0 -130
- data/spec/commands/zpopmax_spec.rb +0 -60
- data/spec/commands/zpopmin_spec.rb +0 -60
- data/spec/commands/zrange_spec.rb +0 -80
- data/spec/commands/zrangebyscore_spec.rb +0 -83
- data/spec/commands/zrank_spec.rb +0 -29
- data/spec/commands/zrem_spec.rb +0 -43
- data/spec/commands/zremrangebyrank_spec.rb +0 -27
- data/spec/commands/zremrangebyscore_spec.rb +0 -35
- data/spec/commands/zrevrange_spec.rb +0 -56
- data/spec/commands/zrevrangebyscore_spec.rb +0 -58
- data/spec/commands/zrevrank_spec.rb +0 -29
- data/spec/commands/zscan_each_spec.rb +0 -48
- data/spec/commands/zscan_spec.rb +0 -26
- data/spec/commands/zscore_spec.rb +0 -22
- data/spec/commands/zunionstore_spec.rb +0 -137
- data/spec/mock_redis_spec.rb +0 -93
- data/spec/spec_helper.rb +0 -71
- data/spec/support/redis_multiplexer.rb +0 -123
- data/spec/support/shared_examples/does_not_cleanup_empty_strings.rb +0 -14
- data/spec/support/shared_examples/only_operates_on_hashes.rb +0 -15
- data/spec/support/shared_examples/only_operates_on_lists.rb +0 -15
- data/spec/support/shared_examples/only_operates_on_sets.rb +0 -15
- data/spec/support/shared_examples/only_operates_on_strings.rb +0 -13
- data/spec/support/shared_examples/only_operates_on_zsets.rb +0 -59
- data/spec/support/shared_examples/sorts_enumerables.rb +0 -56
- data/spec/transactions_spec.rb +0 -163
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#sscan_each' do
|
4
|
-
subject { MockRedis::Database.new(self) }
|
5
|
-
|
6
|
-
let(:key) { 'mock-redis-test:sscan_each' }
|
7
|
-
|
8
|
-
before do
|
9
|
-
allow(subject).to receive(:smembers).and_return(collection)
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'when no keys are found' do
|
13
|
-
let(:collection) { [] }
|
14
|
-
|
15
|
-
it 'does not iterate over any elements' do
|
16
|
-
results = subject.sscan_each(key).map do |k|
|
17
|
-
k
|
18
|
-
end
|
19
|
-
expect(results).to match_array(collection)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'when keys are found' do
|
24
|
-
context 'when no match filter is supplied' do
|
25
|
-
let(:collection) { Array.new(20) { |i| "k#{i}" } }
|
26
|
-
|
27
|
-
it 'iterates over each item in the collection' do
|
28
|
-
results = subject.sscan_each(key).map do |k|
|
29
|
-
k
|
30
|
-
end
|
31
|
-
expect(results).to match_array(collection)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'when giving a custom match filter' do
|
36
|
-
let(:match) { 'k1*' }
|
37
|
-
let(:collection) { Array.new(12) { |i| "k#{i}" } }
|
38
|
-
let(:expected) { %w[k1 k10 k11] }
|
39
|
-
|
40
|
-
it 'iterates over each item in the filtered collection' do
|
41
|
-
results = subject.sscan_each(key, match: match).map do |k|
|
42
|
-
k
|
43
|
-
end
|
44
|
-
expect(results).to match_array(expected)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
data/spec/commands/sscan_spec.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#sscan' do
|
4
|
-
let(:count) { 10 }
|
5
|
-
let(:match) { '*' }
|
6
|
-
let(:key) { 'mock-redis-test:sscan' }
|
7
|
-
|
8
|
-
before do
|
9
|
-
# The return order of the members is non-deterministic, so we sort them to compare
|
10
|
-
expect_any_instance_of(Redis).to receive(:sscan).and_wrap_original do |m, *args|
|
11
|
-
result = m.call(*args)
|
12
|
-
[result[0], result[1].sort]
|
13
|
-
end
|
14
|
-
expect_any_instance_of(MockRedis).to receive(:sscan).and_wrap_original do |m, *args|
|
15
|
-
result = m.call(*args)
|
16
|
-
[result[0], result[1].sort]
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'when the set does not exist' do
|
21
|
-
it 'returns a 0 cursor and an empty collection' do
|
22
|
-
expect(@redises.sscan(key, 0, count: count, match: match)).to eq(['0', []])
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'when the set exists' do
|
27
|
-
before do
|
28
|
-
@redises.sadd(key, 'Hello')
|
29
|
-
@redises.sadd(key, 'World')
|
30
|
-
@redises.sadd(key, 'Test')
|
31
|
-
end
|
32
|
-
|
33
|
-
let(:expected) { ['0', %w[Hello Test World]] }
|
34
|
-
|
35
|
-
it 'returns a 0 cursor and the collection' do
|
36
|
-
expect(@redises.sscan(key, 0, count: count)).to eq(expected)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#strlen(key)' do
|
4
|
-
before do
|
5
|
-
@key = 'mock-redis-test:73288'
|
6
|
-
@redises.set(@key, '5 ∈ (0..10)')
|
7
|
-
end
|
8
|
-
|
9
|
-
it "returns the string's length in bytes" do
|
10
|
-
@redises.strlen(@key).should == 13
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'returns 0 for a nonexistent value' do
|
14
|
-
@redises.strlen('mock-redis-test:does-not-exist').should == 0
|
15
|
-
end
|
16
|
-
|
17
|
-
it_should_behave_like 'a string-only command'
|
18
|
-
end
|
@@ -1,42 +0,0 @@
|
|
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[2 4 6 8 10 3 5 7]
|
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 'allows Array as argument' do
|
22
|
-
@redises.sunion([@evens, @primes]).should == %w[2 4 6 8 10 3 5 7]
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'raises an error if given 0 sets' do
|
26
|
-
lambda do
|
27
|
-
@redises.sunion
|
28
|
-
end.should raise_error(Redis::CommandError)
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'raises an error if any argument is not a a set' do
|
32
|
-
@redises.set('mock-redis-test:notset', 1)
|
33
|
-
|
34
|
-
lambda do
|
35
|
-
@redises.sunion(@numbers, 'mock-redis-test:notset')
|
36
|
-
end.should raise_error(Redis::CommandError)
|
37
|
-
|
38
|
-
lambda do
|
39
|
-
@redises.sunion('mock-redis-test:notset', @numbers)
|
40
|
-
end.should raise_error(Redis::CommandError)
|
41
|
-
end
|
42
|
-
end
|
@@ -1,59 +0,0 @@
|
|
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 8 6 4 7 5 3 2]
|
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[7 5 3 2]
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'correctly unions and stores when the destination is empty and is one of the arguments' do
|
37
|
-
@redises.sunionstore(@destination, @destination, @primes)
|
38
|
-
|
39
|
-
@redises.smembers(@destination).should == %w[7 5 3 2]
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'raises an error if given 0 sets' do
|
43
|
-
lambda do
|
44
|
-
@redises.sunionstore(@destination)
|
45
|
-
end.should raise_error(Redis::CommandError)
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'raises an error if any argument is not a a set' do
|
49
|
-
@redises.set('mock-redis-test:notset', 1)
|
50
|
-
|
51
|
-
lambda do
|
52
|
-
@redises.sunionstore(@destination, @primes, 'mock-redis-test:notset')
|
53
|
-
end.should raise_error(Redis::CommandError)
|
54
|
-
|
55
|
-
lambda do
|
56
|
-
@redises.sunionstore(@destination, 'mock-redis-test:notset', @primes)
|
57
|
-
end.should raise_error(Redis::CommandError)
|
58
|
-
end
|
59
|
-
end
|
data/spec/commands/ttl_spec.rb
DELETED
@@ -1,40 +0,0 @@
|
|
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 -2 for a key that does not exist' do
|
14
|
-
@redises.ttl('mock-redis-test:nonesuch').should == -2
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'stringifies key' do
|
18
|
-
@redises.expire(@key, 9)
|
19
|
-
@redises.ttl(@key.to_sym).should > 0
|
20
|
-
end
|
21
|
-
|
22
|
-
context '[mock only]' do
|
23
|
-
# These are mock-only since we can't actually manipulate time in
|
24
|
-
# the real Redis.
|
25
|
-
|
26
|
-
before(:all) do
|
27
|
-
@mock = @redises.mock
|
28
|
-
end
|
29
|
-
|
30
|
-
before do
|
31
|
-
@now = Time.now
|
32
|
-
Time.stub(:now).and_return(@now)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "gives you the key's remaining lifespan in seconds" do
|
36
|
-
@mock.expire(@key, 5)
|
37
|
-
@mock.ttl(@key).should == 5
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
data/spec/commands/type_spec.rb
DELETED
@@ -1,36 +0,0 @@
|
|
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
|
data/spec/commands/watch_spec.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#watch(key [, key, ...)' do
|
4
|
-
before do
|
5
|
-
@key1 = 'mock-redis-test-watch1'
|
6
|
-
@key2 = 'mock-redis-test-watch2'
|
7
|
-
end
|
8
|
-
|
9
|
-
it "returns 'OK'" do
|
10
|
-
@redises.watch(@key1, @key2).should == 'OK'
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'EXECs its MULTI on successes' do
|
14
|
-
@redises.watch @key1, @key2 do
|
15
|
-
@redises.multi do |multi|
|
16
|
-
multi.set 'bar', 'baz'
|
17
|
-
end
|
18
|
-
end
|
19
|
-
@redises.get('bar').should eq('baz')
|
20
|
-
end
|
21
|
-
end
|
data/spec/commands/xadd_spec.rb
DELETED
@@ -1,122 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#xadd("mystream", { f1: "v1", f2: "v2" }, id: "0-0", maxlen: 1000, approximate: true)' do
|
4
|
-
before :all do
|
5
|
-
sleep 1 - (Time.now.to_f % 1)
|
6
|
-
@key = 'mock-redis-test:xadd'
|
7
|
-
end
|
8
|
-
|
9
|
-
before :each do
|
10
|
-
# TODO: Redis appears to be returning a timestamp a few seconds in the future
|
11
|
-
# so we're ignoring the last 5 digits (time in milliseconds)
|
12
|
-
@redises._gsub(/\d{5}-\d/, '....-.')
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'returns an id based on the timestamp' do
|
16
|
-
t = Time.now.to_i
|
17
|
-
id = @redises.xadd(@key, { key: 'value' })
|
18
|
-
expect(id).to match(/#{t}\d{3}-0/)
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'adds data with symbols' do
|
22
|
-
@redises.xadd(@key, { symbol_key: :symbol_value })
|
23
|
-
expect(@redises.xrange(@key, '-', '+').last[1])
|
24
|
-
.to eq('symbol_key' => 'symbol_value')
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'increments the sequence number with the same timestamp' do
|
28
|
-
Timecop.freeze do
|
29
|
-
@redises.xadd(@key, { key: 'value' })
|
30
|
-
expect(@redises.xadd(@key, { key: 'value' })).to match(/\d+-1/)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'sets the id if it is given' do
|
35
|
-
expect(@redises.xadd(@key, { key: 'value' }, id: '1234567891234-2'))
|
36
|
-
.to eq '1234567891234-2'
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'accepts is as an integer' do
|
40
|
-
expect(@redises.xadd(@key, { key: 'value' }, id: 1_234_567_891_234))
|
41
|
-
.to eq '1234567891234-0'
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'raises exception if id is less that stream top item' do
|
45
|
-
@redises.xadd(@key, { key: 'value' }, id: '1234567891234-0')
|
46
|
-
expect { @redises.xadd(@key, { key: 'value' }, id: '1234567891233-0') }
|
47
|
-
.to raise_error(
|
48
|
-
Redis::CommandError,
|
49
|
-
'ERR The ID specified in XADD is equal or smaller than the target ' \
|
50
|
-
'stream top item'
|
51
|
-
)
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'raises exception if id of 0 is added to an empty stream' do
|
55
|
-
expect { @redises.xadd('mock-redis-test:unknown-stream', { key: 'value' }, id: '0') }
|
56
|
-
.to raise_error(
|
57
|
-
Redis::CommandError,
|
58
|
-
'ERR The ID specified in XADD must be greater than 0-0'
|
59
|
-
)
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'does not raise exception on empty stream with id of 0 and positive sequence number' do
|
63
|
-
expect { @redises.xadd('mock-redis-test:unknown-stream', { key: 'value' }, id: '0-1') }
|
64
|
-
.to_not raise_error
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'caters for the current time being before the last time' do
|
68
|
-
t = (Time.now.to_f * 1000).to_i + 2000
|
69
|
-
@redises.xadd(@key, { key: 'value' }, id: "#{t}-0")
|
70
|
-
expect(@redises.xadd(@key, { key: 'value' })).to match(/#{t}-1/)
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'appends a sequence number if it is missing' do
|
74
|
-
expect(@redises.xadd(@key, { key: 'value' }, id: '1234567891234'))
|
75
|
-
.to eq '1234567891234-0'
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'raises an invalid stream id error' do
|
79
|
-
expect { @redises.xadd(@key, { key: 'value' }, id: 'X') }
|
80
|
-
.to raise_error(
|
81
|
-
Redis::CommandError,
|
82
|
-
'ERR Invalid stream ID specified as stream command argument'
|
83
|
-
)
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'caps the stream to 5 elements' do
|
87
|
-
@redises.xadd(@key, { key1: 'value1' }, id: '1234567891234-0')
|
88
|
-
@redises.xadd(@key, { key2: 'value2' }, id: '1234567891245-0')
|
89
|
-
@redises.xadd(@key, { key3: 'value3' }, id: '1234567891245-1')
|
90
|
-
@redises.xadd(@key, { key4: 'value4' }, id: '1234567891278-0')
|
91
|
-
@redises.xadd(@key, { key5: 'value5' }, id: '1234567891278-1')
|
92
|
-
@redises.xadd(@key, { key6: 'value6' }, id: '1234567891299-0')
|
93
|
-
@redises.xadd(@key, { key7: 'value7' }, id: '1234567891300-0', maxlen: 5)
|
94
|
-
expect(@redises.xrange(@key, '-', '+')).to eq(
|
95
|
-
[
|
96
|
-
['1234567891245-1', { 'key3' => 'value3' }],
|
97
|
-
['1234567891278-0', { 'key4' => 'value4' }],
|
98
|
-
['1234567891278-1', { 'key5' => 'value5' }],
|
99
|
-
['1234567891299-0', { 'key6' => 'value6' }],
|
100
|
-
['1234567891300-0', { 'key7' => 'value7' }]
|
101
|
-
]
|
102
|
-
)
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'supports a maxlen greater than the current size' do
|
106
|
-
@redises.xadd(@key, { key1: 'value1' }, id: '1234567891234-0')
|
107
|
-
@redises.xadd(@key, { key2: 'value2' }, id: '1234567891245-0', maxlen: 1000)
|
108
|
-
expect(@redises.xrange(@key, '-', '+')).to eq(
|
109
|
-
[
|
110
|
-
['1234567891234-0', { 'key1' => 'value1' }],
|
111
|
-
['1234567891245-0', { 'key2' => 'value2' }],
|
112
|
-
]
|
113
|
-
)
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'creates an empty stream with maxlen of 0' do
|
117
|
-
@redises.xadd(@key, { key: 'value' }, maxlen: 0)
|
118
|
-
expect(@redises.xlen(@key)).to eq 0
|
119
|
-
expect(@redises.xrange(@key, '-', '+')).to eq([])
|
120
|
-
expect(@redises.exists?(@key)).to eq true
|
121
|
-
end
|
122
|
-
end
|
data/spec/commands/xlen_spec.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#xlen(key)' do
|
4
|
-
before :all do
|
5
|
-
sleep 1 - (Time.now.to_f % 1)
|
6
|
-
@key = 'mock-redis-test:xlen'
|
7
|
-
end
|
8
|
-
|
9
|
-
before :each do
|
10
|
-
# TODO: Redis appears to be returning a timestamp a few seconds in the future
|
11
|
-
# so we're ignoring the last 5 digits (time in milliseconds)
|
12
|
-
@redises._gsub(/\d{5}-\d/, '...-.')
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'returns the number of items in the stream' do
|
16
|
-
expect(@redises.xlen(@key)).to eq 0
|
17
|
-
@redises.xadd(@key, { key: 'value' })
|
18
|
-
expect(@redises.xlen(@key)).to eq 1
|
19
|
-
3.times { @redises.xadd(@key, { key: 'value' }) }
|
20
|
-
expect(@redises.xlen(@key)).to eq 4
|
21
|
-
end
|
22
|
-
end
|
@@ -1,164 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe '#xrange("mystream", first: "0-1", last: "0-3", count: 10)' do
|
4
|
-
before { @key = 'mock-redis-test:xrange' }
|
5
|
-
|
6
|
-
it 'finds an empty range' do
|
7
|
-
expect(@redises.xrange(@key, '-', '+')).to eq []
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'finds a single entry with a full range' do
|
11
|
-
@redises.xadd(@key, { key: 'value' }, id: '1234567891234-0')
|
12
|
-
expect(@redises.xrange(@key, '-', '+'))
|
13
|
-
.to eq [['1234567891234-0', { 'key' => 'value' }]]
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'finds multiple key/value pairs with a full range' do
|
17
|
-
@redises.xadd(@key, { key1: 'value1', key2: 'value2', key3: 'value3' }, id: '1234567891234-0')
|
18
|
-
expect(@redises.xrange(@key, '-', '+'))
|
19
|
-
.to eq [['1234567891234-0', { 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' }]]
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'six items on the list' do
|
23
|
-
before :each do
|
24
|
-
@redises.xadd(@key, { key1: 'value1' }, id: '1234567891234-0')
|
25
|
-
@redises.xadd(@key, { key2: 'value2' }, id: '1234567891245-0')
|
26
|
-
@redises.xadd(@key, { key3: 'value3' }, id: '1234567891245-1')
|
27
|
-
@redises.xadd(@key, { key4: 'value4' }, id: '1234567891278-0')
|
28
|
-
@redises.xadd(@key, { key5: 'value5' }, id: '1234567891278-1')
|
29
|
-
@redises.xadd(@key, { key6: 'value6' }, id: '1234567891299-0')
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'returns entries in sequential order' do
|
33
|
-
expect(@redises.xrange(@key, '-', '+')).to eq(
|
34
|
-
[
|
35
|
-
['1234567891234-0', { 'key1' => 'value1' }],
|
36
|
-
['1234567891245-0', { 'key2' => 'value2' }],
|
37
|
-
['1234567891245-1', { 'key3' => 'value3' }],
|
38
|
-
['1234567891278-0', { 'key4' => 'value4' }],
|
39
|
-
['1234567891278-1', { 'key5' => 'value5' }],
|
40
|
-
['1234567891299-0', { 'key6' => 'value6' }]
|
41
|
-
]
|
42
|
-
)
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'returns entries with a lower limit' do
|
46
|
-
expect(@redises.xrange(@key, '1234567891239-0', '+')).to eq(
|
47
|
-
[
|
48
|
-
['1234567891245-0', { 'key2' => 'value2' }],
|
49
|
-
['1234567891245-1', { 'key3' => 'value3' }],
|
50
|
-
['1234567891278-0', { 'key4' => 'value4' }],
|
51
|
-
['1234567891278-1', { 'key5' => 'value5' }],
|
52
|
-
['1234567891299-0', { 'key6' => 'value6' }]
|
53
|
-
]
|
54
|
-
)
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'returns all entries with a lower limit of 0-0' do
|
58
|
-
expect(@redises.xrange(@key, '0-0', '+')).to eq(
|
59
|
-
[
|
60
|
-
['1234567891234-0', { 'key1' => 'value1' }],
|
61
|
-
['1234567891245-0', { 'key2' => 'value2' }],
|
62
|
-
['1234567891245-1', { 'key3' => 'value3' }],
|
63
|
-
['1234567891278-0', { 'key4' => 'value4' }],
|
64
|
-
['1234567891278-1', { 'key5' => 'value5' }],
|
65
|
-
['1234567891299-0', { 'key6' => 'value6' }]
|
66
|
-
]
|
67
|
-
)
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'returns entries with an upper limit' do
|
71
|
-
expect(@redises.xrange(@key, '-', '1234567891285-0')).to eq(
|
72
|
-
[
|
73
|
-
['1234567891234-0', { 'key1' => 'value1' }],
|
74
|
-
['1234567891245-0', { 'key2' => 'value2' }],
|
75
|
-
['1234567891245-1', { 'key3' => 'value3' }],
|
76
|
-
['1234567891278-0', { 'key4' => 'value4' }],
|
77
|
-
['1234567891278-1', { 'key5' => 'value5' }]
|
78
|
-
]
|
79
|
-
)
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'returns entries with both a lower and an upper limit inclusive' do
|
83
|
-
expect(@redises.xrange(@key, '1234567891245-0', '1234567891278-0')).to eq(
|
84
|
-
[
|
85
|
-
['1234567891245-0', { 'key2' => 'value2' }],
|
86
|
-
['1234567891245-1', { 'key3' => 'value3' }],
|
87
|
-
['1234567891278-0', { 'key4' => 'value4' }]
|
88
|
-
]
|
89
|
-
)
|
90
|
-
end
|
91
|
-
|
92
|
-
it 'returns entries with both a lower and an upper limit exclusive' do
|
93
|
-
expect(@redises.xrange(@key, '(1234567891245-0', '1234567891285-1')).to eq(
|
94
|
-
[
|
95
|
-
# We no longer get '1234567891245-0'
|
96
|
-
['1234567891245-1', { 'key3' => 'value3' }],
|
97
|
-
['1234567891278-0', { 'key4' => 'value4' }],
|
98
|
-
['1234567891278-1', { 'key5' => 'value5' }] # Note sequence -1
|
99
|
-
]
|
100
|
-
)
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'finds the list with sequence numbers' do
|
104
|
-
expect(@redises.xrange(@key, '1234567891245-1', '1234567891278-0')).to eq(
|
105
|
-
[
|
106
|
-
['1234567891245-1', { 'key3' => 'value3' }],
|
107
|
-
['1234567891278-0', { 'key4' => 'value4' }]
|
108
|
-
]
|
109
|
-
)
|
110
|
-
end
|
111
|
-
|
112
|
-
it 'finds the list with lower bound without sequence numbers' do
|
113
|
-
expect(@redises.xrange(@key, '1234567891245', '+')).to eq(
|
114
|
-
[
|
115
|
-
['1234567891245-0', { 'key2' => 'value2' }],
|
116
|
-
['1234567891245-1', { 'key3' => 'value3' }],
|
117
|
-
['1234567891278-0', { 'key4' => 'value4' }],
|
118
|
-
['1234567891278-1', { 'key5' => 'value5' }],
|
119
|
-
['1234567891299-0', { 'key6' => 'value6' }]
|
120
|
-
]
|
121
|
-
)
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'finds the list with upper bound without sequence numbers' do
|
125
|
-
expect(@redises.xrange(@key, '-', '1234567891278')).to eq(
|
126
|
-
[
|
127
|
-
['1234567891234-0', { 'key1' => 'value1' }],
|
128
|
-
['1234567891245-0', { 'key2' => 'value2' }],
|
129
|
-
['1234567891245-1', { 'key3' => 'value3' }],
|
130
|
-
['1234567891278-0', { 'key4' => 'value4' }],
|
131
|
-
['1234567891278-1', { 'key5' => 'value5' }]
|
132
|
-
]
|
133
|
-
)
|
134
|
-
end
|
135
|
-
|
136
|
-
it 'accepts limits as integers' do
|
137
|
-
expect(@redises.xrange(@key, 1_234_567_891_245, 1_234_567_891_278)).to eq(
|
138
|
-
[
|
139
|
-
['1234567891245-0', { 'key2' => 'value2' }],
|
140
|
-
['1234567891245-1', { 'key3' => 'value3' }],
|
141
|
-
['1234567891278-0', { 'key4' => 'value4' }],
|
142
|
-
['1234567891278-1', { 'key5' => 'value5' }]
|
143
|
-
]
|
144
|
-
)
|
145
|
-
end
|
146
|
-
|
147
|
-
it 'returns a limited number of items' do
|
148
|
-
expect(@redises.xrange(@key, '-', '+', count: 2)).to eq(
|
149
|
-
[
|
150
|
-
['1234567891234-0', { 'key1' => 'value1' }],
|
151
|
-
['1234567891245-0', { 'key2' => 'value2' }]
|
152
|
-
]
|
153
|
-
)
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
it 'raises an invalid stream id error' do
|
158
|
-
expect { @redises.xrange(@key, 'X', '+') }
|
159
|
-
.to raise_error(
|
160
|
-
Redis::CommandError,
|
161
|
-
'ERR Invalid stream ID specified as stream command argument'
|
162
|
-
)
|
163
|
-
end
|
164
|
-
end
|