mock_redis 0.5.4 → 0.31.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/lint.yml +31 -0
- data/.github/workflows/tests.yml +63 -0
- data/.gitignore +1 -1
- data/.overcommit.yml +21 -0
- data/.rspec +1 -1
- data/.rubocop.yml +148 -0
- data/.rubocop_todo.yml +35 -0
- data/.simplecov +4 -0
- data/CHANGELOG.md +278 -0
- data/Gemfile +9 -5
- data/LICENSE.md +21 -0
- data/README.md +52 -16
- data/Rakefile +0 -8
- data/lib/mock_redis/assertions.rb +0 -1
- data/lib/mock_redis/connection_method.rb +13 -0
- data/lib/mock_redis/database.rb +193 -257
- data/lib/mock_redis/expire_wrapper.rb +2 -2
- data/lib/mock_redis/future.rb +23 -0
- data/lib/mock_redis/geospatial_methods.rb +240 -0
- data/lib/mock_redis/hash_methods.rb +83 -24
- data/lib/mock_redis/indifferent_hash.rb +11 -0
- data/lib/mock_redis/info_method.rb +160 -0
- data/lib/mock_redis/list_methods.rb +34 -19
- data/lib/mock_redis/multi_db_wrapper.rb +8 -7
- data/lib/mock_redis/pipelined_wrapper.rb +42 -16
- data/lib/mock_redis/set_methods.rb +62 -19
- data/lib/mock_redis/sort_method.rb +81 -0
- data/lib/mock_redis/stream/id.rb +58 -0
- data/lib/mock_redis/stream.rb +88 -0
- data/lib/mock_redis/stream_methods.rb +102 -0
- data/lib/mock_redis/string_methods.rb +235 -42
- data/lib/mock_redis/transaction_wrapper.rb +62 -28
- data/lib/mock_redis/utility_methods.rb +62 -11
- data/lib/mock_redis/version.rb +4 -1
- data/lib/mock_redis/zset.rb +24 -29
- data/lib/mock_redis/zset_methods.rb +187 -59
- data/lib/mock_redis.rb +77 -27
- data/mock_redis.gemspec +23 -15
- data/spec/client_spec.rb +29 -0
- 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 +25 -0
- data/spec/commands/bitfield_spec.rb +169 -0
- data/spec/commands/blpop_spec.rb +19 -21
- data/spec/commands/brpop_spec.rb +25 -20
- data/spec/commands/brpoplpush_spec.rb +16 -17
- data/spec/commands/connected_spec.rb +7 -0
- data/spec/commands/connection_spec.rb +15 -0
- data/spec/commands/dbsize_spec.rb +3 -3
- data/spec/commands/decr_spec.rb +8 -8
- data/spec/commands/decrby_spec.rb +8 -8
- data/spec/commands/del_spec.rb +35 -3
- data/spec/commands/disconnect_spec.rb +7 -0
- data/spec/commands/dump_spec.rb +19 -0
- data/spec/commands/echo_spec.rb +4 -4
- data/spec/commands/eval_spec.rb +7 -0
- data/spec/commands/evalsha_spec.rb +10 -0
- data/spec/commands/exists_spec.rb +36 -7
- data/spec/commands/expire_spec.rb +48 -20
- data/spec/commands/expireat_spec.rb +12 -13
- data/spec/commands/flushall_spec.rb +5 -5
- data/spec/commands/flushdb_spec.rb +5 -5
- data/spec/commands/future_spec.rb +30 -0
- data/spec/commands/geoadd_spec.rb +58 -0
- data/spec/commands/geodist_spec.rb +118 -0
- data/spec/commands/geohash_spec.rb +52 -0
- data/spec/commands/geopos_spec.rb +55 -0
- data/spec/commands/get_spec.rb +14 -6
- data/spec/commands/getbit_spec.rb +7 -7
- data/spec/commands/getrange_spec.rb +9 -9
- data/spec/commands/getset_spec.rb +7 -7
- data/spec/commands/hdel_spec.rb +41 -11
- data/spec/commands/hexists_spec.rb +11 -11
- data/spec/commands/hget_spec.rb +7 -7
- data/spec/commands/hgetall_spec.rb +15 -5
- data/spec/commands/hincrby_spec.rb +16 -16
- data/spec/commands/hincrbyfloat_spec.rb +58 -0
- data/spec/commands/hkeys_spec.rb +5 -5
- data/spec/commands/hlen_spec.rb +5 -5
- data/spec/commands/hmget_spec.rb +19 -9
- data/spec/commands/hmset_spec.rb +38 -12
- data/spec/commands/hscan_each_spec.rb +48 -0
- data/spec/commands/hscan_spec.rb +27 -0
- data/spec/commands/hset_spec.rb +26 -12
- data/spec/commands/hsetnx_spec.rb +16 -16
- data/spec/commands/hvals_spec.rb +5 -5
- data/spec/commands/incr_spec.rb +8 -8
- data/spec/commands/incrby_spec.rb +13 -13
- data/spec/commands/incrbyfloat_spec.rb +13 -13
- data/spec/commands/info_spec.rb +54 -5
- data/spec/commands/keys_spec.rb +83 -31
- data/spec/commands/lastsave_spec.rb +2 -2
- data/spec/commands/lindex_spec.rb +20 -10
- data/spec/commands/linsert_spec.rb +14 -14
- data/spec/commands/llen_spec.rb +4 -4
- data/spec/commands/lpop_spec.rb +6 -6
- data/spec/commands/lpush_spec.rb +21 -15
- data/spec/commands/lpushx_spec.rb +24 -11
- data/spec/commands/lrange_spec.rb +24 -8
- data/spec/commands/lrem_spec.rb +16 -16
- data/spec/commands/lset_spec.rb +17 -12
- data/spec/commands/ltrim_spec.rb +17 -7
- data/spec/commands/mapped_hmget_spec.rb +13 -9
- data/spec/commands/mapped_hmset_spec.rb +12 -12
- data/spec/commands/mapped_mget_spec.rb +22 -0
- data/spec/commands/mapped_mset_spec.rb +19 -0
- data/spec/commands/mapped_msetnx_spec.rb +26 -0
- data/spec/commands/mget_spec.rb +48 -17
- data/spec/commands/move_spec.rb +37 -37
- data/spec/commands/mset_spec.rb +20 -6
- data/spec/commands/msetnx_spec.rb +14 -14
- data/spec/commands/persist_spec.rb +15 -16
- data/spec/commands/pexpire_spec.rb +86 -0
- data/spec/commands/pexpireat_spec.rb +48 -0
- data/spec/commands/ping_spec.rb +6 -2
- data/spec/commands/pipelined_spec.rb +98 -7
- data/spec/commands/pttl_spec.rb +41 -0
- data/spec/commands/randomkey_spec.rb +3 -3
- data/spec/commands/rename_spec.rb +16 -12
- data/spec/commands/renamenx_spec.rb +13 -15
- data/spec/commands/restore_spec.rb +47 -0
- data/spec/commands/rpop_spec.rb +6 -6
- data/spec/commands/rpoplpush_spec.rb +13 -8
- data/spec/commands/rpush_spec.rb +21 -15
- data/spec/commands/rpushx_spec.rb +24 -11
- data/spec/commands/sadd_spec.rb +14 -10
- data/spec/commands/scan_each_spec.rb +39 -0
- data/spec/commands/scan_spec.rb +64 -0
- data/spec/commands/scard_spec.rb +3 -3
- data/spec/commands/script_spec.rb +9 -0
- data/spec/commands/sdiff_spec.rb +13 -13
- data/spec/commands/sdiffstore_spec.rb +13 -13
- data/spec/commands/select_spec.rb +13 -5
- data/spec/commands/set_spec.rb +112 -0
- data/spec/commands/setbit_spec.rb +25 -16
- data/spec/commands/setex_spec.rb +20 -4
- data/spec/commands/setnx_spec.rb +6 -6
- data/spec/commands/setrange_spec.rb +12 -12
- data/spec/commands/sinter_spec.rb +11 -13
- data/spec/commands/sinterstore_spec.rb +12 -12
- data/spec/commands/sismember_spec.rb +10 -10
- data/spec/commands/smembers_spec.rb +15 -5
- data/spec/commands/smove_spec.rb +13 -13
- data/spec/commands/sort_list_spec.rb +21 -0
- data/spec/commands/sort_set_spec.rb +21 -0
- data/spec/commands/sort_zset_spec.rb +21 -0
- data/spec/commands/spop_spec.rb +19 -4
- data/spec/commands/srandmember_spec.rb +28 -4
- data/spec/commands/srem_spec.rb +17 -12
- data/spec/commands/sscan_each_spec.rb +48 -0
- data/spec/commands/sscan_spec.rb +39 -0
- data/spec/commands/strlen_spec.rb +4 -5
- data/spec/commands/sunion_spec.rb +13 -11
- data/spec/commands/sunionstore_spec.rb +12 -12
- data/spec/commands/ttl_spec.rb +11 -6
- data/spec/commands/type_spec.rb +1 -1
- data/spec/commands/watch_spec.rb +9 -4
- data/spec/commands/xadd_spec.rb +122 -0
- data/spec/commands/xlen_spec.rb +22 -0
- data/spec/commands/xrange_spec.rb +164 -0
- data/spec/commands/xread_spec.rb +66 -0
- data/spec/commands/xrevrange_spec.rb +130 -0
- data/spec/commands/xtrim_spec.rb +36 -0
- data/spec/commands/zadd_spec.rb +100 -11
- data/spec/commands/zcard_spec.rb +4 -4
- data/spec/commands/zcount_spec.rb +18 -10
- data/spec/commands/zincrby_spec.rb +6 -6
- data/spec/commands/zinterstore_spec.rb +54 -20
- data/spec/commands/zpopmax_spec.rb +60 -0
- data/spec/commands/zpopmin_spec.rb +60 -0
- data/spec/commands/zrange_spec.rb +54 -13
- data/spec/commands/zrangebyscore_spec.rb +42 -27
- data/spec/commands/zrank_spec.rb +4 -4
- data/spec/commands/zrem_spec.rb +18 -12
- data/spec/commands/zremrangebyrank_spec.rb +5 -5
- data/spec/commands/zremrangebyscore_spec.rb +12 -5
- data/spec/commands/zrevrange_spec.rb +35 -10
- data/spec/commands/zrevrangebyscore_spec.rb +26 -15
- data/spec/commands/zrevrank_spec.rb +4 -4
- data/spec/commands/zscan_each_spec.rb +48 -0
- data/spec/commands/zscan_spec.rb +26 -0
- data/spec/commands/zscore_spec.rb +7 -7
- data/spec/commands/zunionstore_spec.rb +54 -21
- data/spec/mock_redis_spec.rb +61 -0
- data/spec/spec_helper.rb +35 -8
- data/spec/support/redis_multiplexer.rb +62 -37
- data/spec/support/shared_examples/does_not_cleanup_empty_strings.rb +14 -0
- data/spec/support/shared_examples/only_operates_on_hashes.rb +5 -3
- data/spec/support/shared_examples/only_operates_on_lists.rb +5 -3
- data/spec/support/shared_examples/only_operates_on_sets.rb +5 -3
- data/spec/support/shared_examples/only_operates_on_strings.rb +4 -4
- data/spec/support/shared_examples/only_operates_on_zsets.rb +18 -16
- data/spec/support/shared_examples/sorts_enumerables.rb +56 -0
- data/spec/transactions_spec.rb +79 -29
- metadata +162 -42
- data/LICENSE +0 -19
- data/spec/commands/hash_operator_spec.rb +0 -21
@@ -0,0 +1,164 @@
|
|
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
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#xread(keys, ids)' do
|
4
|
+
before :all do
|
5
|
+
sleep 1 - (Time.now.to_f % 1)
|
6
|
+
@key = 'mock-redis-test:xread'
|
7
|
+
@key1 = 'mock-redis-test:xread1'
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'reads a single entry' do
|
11
|
+
@redises.xadd(@key, { key: 'value' }, id: '1234567891234-0')
|
12
|
+
expect(@redises.xread(@key, '0-0'))
|
13
|
+
.to eq({ @key => [['1234567891234-0', { 'key' => 'value' }]] })
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'reads multiple entries from the beginning of the stream' do
|
17
|
+
@redises.xadd(@key, { key0: 'value0' }, id: '1234567891234-0')
|
18
|
+
@redises.xadd(@key, { key1: 'value1' }, id: '1234567891234-1')
|
19
|
+
expect(@redises.xread(@key, '0-0'))
|
20
|
+
.to eq({ @key => [['1234567891234-0', { 'key0' => 'value0' }],
|
21
|
+
['1234567891234-1', { 'key1' => 'value1' }]] })
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'reads entries greater than the ID passed' do
|
25
|
+
@redises.xadd(@key, { key0: 'value0' }, id: '1234567891234-0')
|
26
|
+
@redises.xadd(@key, { key1: 'value1' }, id: '1234567891234-1')
|
27
|
+
expect(@redises.xread(@key, '1234567891234-0'))
|
28
|
+
.to eq({ @key => [['1234567891234-1', { 'key1' => 'value1' }]] })
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'reads from multiple streams' do
|
32
|
+
@redises.xadd(@key, { key: 'value' }, id: '1234567891234-0')
|
33
|
+
@redises.xadd(@key1, { key1: 'value1' }, id: '1234567891234-0')
|
34
|
+
expect(@redises.xread([@key, @key1], %w[0-0 0-0]))
|
35
|
+
.to eq({ @key => [['1234567891234-0', { 'key' => 'value' }]],
|
36
|
+
@key1 => [['1234567891234-0', { 'key1' => 'value1' }]] })
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'reads from multiple streams at the given IDs' do
|
40
|
+
@redises.xadd(@key, { key: 'value0' }, id: '1234567891234-0')
|
41
|
+
@redises.xadd(@key, { key: 'value1' }, id: '1234567891234-1')
|
42
|
+
@redises.xadd(@key, { key: 'value2' }, id: '1234567891234-2')
|
43
|
+
@redises.xadd(@key1, { key1: 'value0' }, id: '1234567891234-0')
|
44
|
+
@redises.xadd(@key1, { key1: 'value1' }, id: '1234567891234-1')
|
45
|
+
@redises.xadd(@key1, { key1: 'value2' }, id: '1234567891234-2')
|
46
|
+
# The first stream won't return anything since we specify the last ID
|
47
|
+
expect(@redises.xread([@key, @key1], %w[1234567891234-2 1234567891234-1]))
|
48
|
+
.to eq({ @key1 => [['1234567891234-2', { 'key1' => 'value2' }]] })
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'supports the block parameter' do
|
52
|
+
@redises.xadd(@key, { key: 'value' }, id: '1234567891234-0')
|
53
|
+
expect(@redises.xread(@key, '0-0', block: 1000))
|
54
|
+
.to eq({ @key => [['1234567891234-0', { 'key' => 'value' }]] })
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'limits results with count' do
|
58
|
+
@redises.xadd(@key, { key: 'value' }, id: '1234567891234-0')
|
59
|
+
@redises.xadd(@key, { key: 'value' }, id: '1234567891234-1')
|
60
|
+
@redises.xadd(@key, { key: 'value' }, id: '1234567891234-2')
|
61
|
+
expect(@redises.xread(@key, '0-0', count: 1))
|
62
|
+
.to eq({ @key => [['1234567891234-0', { 'key' => 'value' }]] })
|
63
|
+
expect(@redises.xread(@key, '1234567891234-0', count: 1))
|
64
|
+
.to eq({ @key => [['1234567891234-1', { 'key' => 'value' }]] })
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#xrevrange(key, start, end)' do
|
4
|
+
before { @key = 'mock-redis-test:xrevrange' }
|
5
|
+
|
6
|
+
it 'finds an empty range' do
|
7
|
+
expect(@redises.xrevrange(@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.xrevrange(@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.xrevrange(@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.xrevrange(@key, '+', '-')).to eq(
|
34
|
+
[
|
35
|
+
['1234567891299-0', { 'key6' => 'value6' }],
|
36
|
+
['1234567891278-1', { 'key5' => 'value5' }],
|
37
|
+
['1234567891278-0', { 'key4' => 'value4' }],
|
38
|
+
['1234567891245-1', { 'key3' => 'value3' }],
|
39
|
+
['1234567891245-0', { 'key2' => 'value2' }],
|
40
|
+
['1234567891234-0', { 'key1' => 'value1' }],
|
41
|
+
]
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'returns entries with a lower limit' do
|
46
|
+
expect(@redises.xrevrange(@key, '+', '1234567891239-0')).to eq(
|
47
|
+
[
|
48
|
+
['1234567891299-0', { 'key6' => 'value6' }],
|
49
|
+
['1234567891278-1', { 'key5' => 'value5' }],
|
50
|
+
['1234567891278-0', { 'key4' => 'value4' }],
|
51
|
+
['1234567891245-1', { 'key3' => 'value3' }],
|
52
|
+
['1234567891245-0', { 'key2' => 'value2' }],
|
53
|
+
]
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'returns entries with an upper limit' do
|
58
|
+
expect(@redises.xrevrange(@key, '1234567891285-0', '-')).to eq(
|
59
|
+
[
|
60
|
+
['1234567891278-1', { 'key5' => 'value5' }],
|
61
|
+
['1234567891278-0', { 'key4' => 'value4' }],
|
62
|
+
['1234567891245-1', { 'key3' => 'value3' }],
|
63
|
+
['1234567891245-0', { 'key2' => 'value2' }],
|
64
|
+
['1234567891234-0', { 'key1' => 'value1' }],
|
65
|
+
]
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'returns entries with both a lower and an upper limit' do
|
70
|
+
expect(@redises.xrevrange(@key, '1234567891285-0', '1234567891239-0')).to eq(
|
71
|
+
[
|
72
|
+
['1234567891278-1', { 'key5' => 'value5' }],
|
73
|
+
['1234567891278-0', { 'key4' => 'value4' }],
|
74
|
+
['1234567891245-1', { 'key3' => 'value3' }],
|
75
|
+
['1234567891245-0', { 'key2' => 'value2' }],
|
76
|
+
]
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'finds the list with sequence numbers' do
|
81
|
+
expect(@redises.xrevrange(@key, '1234567891278-0', '1234567891245-1')).to eq(
|
82
|
+
[
|
83
|
+
['1234567891278-0', { 'key4' => 'value4' }],
|
84
|
+
['1234567891245-1', { 'key3' => 'value3' }],
|
85
|
+
]
|
86
|
+
)
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'finds the list with lower bound without sequence numbers' do
|
90
|
+
expect(@redises.xrevrange(@key, '+', '1234567891245')).to eq(
|
91
|
+
[
|
92
|
+
['1234567891299-0', { 'key6' => 'value6' }],
|
93
|
+
['1234567891278-1', { 'key5' => 'value5' }],
|
94
|
+
['1234567891278-0', { 'key4' => 'value4' }],
|
95
|
+
['1234567891245-1', { 'key3' => 'value3' }],
|
96
|
+
['1234567891245-0', { 'key2' => 'value2' }],
|
97
|
+
]
|
98
|
+
)
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'finds the list with upper bound without sequence numbers' do
|
102
|
+
expect(@redises.xrevrange(@key, '1234567891278', '-')).to eq(
|
103
|
+
[
|
104
|
+
['1234567891278-1', { 'key5' => 'value5' }],
|
105
|
+
['1234567891278-0', { 'key4' => 'value4' }],
|
106
|
+
['1234567891245-1', { 'key3' => 'value3' }],
|
107
|
+
['1234567891245-0', { 'key2' => 'value2' }],
|
108
|
+
['1234567891234-0', { 'key1' => 'value1' }],
|
109
|
+
]
|
110
|
+
)
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'returns a limited number of items' do
|
114
|
+
expect(@redises.xrevrange(@key, count: 2)).to eq(
|
115
|
+
[
|
116
|
+
['1234567891299-0', { 'key6' => 'value6' }],
|
117
|
+
['1234567891278-1', { 'key5' => 'value5' }],
|
118
|
+
]
|
119
|
+
)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'raises an invalid stream id error' do
|
124
|
+
expect { @redises.xrevrange(@key, 'X', '-') }
|
125
|
+
.to raise_error(
|
126
|
+
Redis::CommandError,
|
127
|
+
'ERR Invalid stream ID specified as stream command argument'
|
128
|
+
)
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#xtrim("mystream", 1000, approximate: true)' do
|
4
|
+
before { @key = 'mock-redis-test:xtrim' }
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
@redises.xadd(@key, { key1: 'value1' }, id: '1234567891234-0')
|
8
|
+
@redises.xadd(@key, { key2: 'value2' }, id: '1234567891245-0')
|
9
|
+
@redises.xadd(@key, { key3: 'value3' }, id: '1234567891245-1')
|
10
|
+
@redises.xadd(@key, { key4: 'value4' }, id: '1234567891278-0')
|
11
|
+
@redises.xadd(@key, { key5: 'value5' }, id: '1234567891278-1')
|
12
|
+
@redises.xadd(@key, { key6: 'value6' }, id: '1234567891299-0')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'returns the number of elements deleted' do
|
16
|
+
expect(@redises.xtrim(@key, 4)).to eq 2
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'returns 0 if count is greater than size' do
|
20
|
+
initial = @redises.xrange(@key, '-', '+')
|
21
|
+
expect(@redises.xtrim(@key, 1000)).to eq 0
|
22
|
+
expect(@redises.xrange(@key, '-', '+')).to eql(initial)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'deletes the oldes elements' do
|
26
|
+
@redises.xtrim(@key, 4)
|
27
|
+
expect(@redises.xrange(@key, '-', '+')).to eq(
|
28
|
+
[
|
29
|
+
['1234567891245-1', { 'key3' => 'value3' }],
|
30
|
+
['1234567891278-0', { 'key4' => 'value4' }],
|
31
|
+
['1234567891278-1', { 'key5' => 'value5' }],
|
32
|
+
['1234567891299-0', { 'key6' => 'value6' }]
|
33
|
+
]
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
data/spec/commands/zadd_spec.rb
CHANGED
@@ -1,40 +1,129 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#zadd(key, score, member)' do
|
4
4
|
before { @key = 'mock-redis-test:zadd' }
|
5
5
|
|
6
6
|
it "returns true if member wasn't present in the set" do
|
7
|
-
@redises.zadd(@key, 1, 'foo').should
|
7
|
+
@redises.zadd(@key, 1, 'foo').should == true
|
8
8
|
end
|
9
9
|
|
10
|
-
it
|
10
|
+
it 'returns false if member was present in the set' do
|
11
11
|
@redises.zadd(@key, 1, 'foo')
|
12
|
-
@redises.zadd(@key, 1, 'foo').should
|
12
|
+
@redises.zadd(@key, 1, 'foo').should == false
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
15
|
+
it 'adds member to the set' do
|
16
16
|
@redises.zadd(@key, 1, 'foo')
|
17
17
|
@redises.zrange(@key, 0, -1).should == ['foo']
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
20
|
+
it 'treats integer members as strings' do
|
21
21
|
member = 11
|
22
22
|
@redises.zadd(@key, 1, member)
|
23
23
|
@redises.zrange(@key, 0, -1).should == [member.to_s]
|
24
24
|
end
|
25
25
|
|
26
|
-
it
|
26
|
+
it 'allows scores to be set to Float::INFINITY' do
|
27
|
+
member = '1'
|
28
|
+
@redises.zadd(@key, Float::INFINITY, member)
|
29
|
+
@redises.zrange(@key, 0, -1).should == [member]
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'updates the score' do
|
27
33
|
@redises.zadd(@key, 1, 'foo')
|
28
34
|
@redises.zadd(@key, 2, 'foo')
|
29
35
|
|
30
36
|
@redises.zscore(@key, 'foo').should == 2.0
|
31
37
|
end
|
32
38
|
|
33
|
-
it
|
39
|
+
it 'with XX option command do nothing if element not exist' do
|
40
|
+
@redises.zadd(@key, 1, 'foo')
|
41
|
+
@redises.zadd(@key, 2, 'bar', xx: true)
|
42
|
+
@redises.zrange(@key, 0, -1).should_not include 'bar'
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'with XX option command update index on exist element' do
|
46
|
+
@redises.zadd(@key, 1, 'foo')
|
47
|
+
@redises.zadd(@key, 2, 'foo', xx: true)
|
48
|
+
@redises.zscore(@key, 'foo').should == 2.0
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'with XX option and multiple elements command update index on exist element' do
|
52
|
+
@redises.zadd(@key, 1, 'foo')
|
53
|
+
added_count = @redises.zadd(@key, [[2, 'foo'], [2, 'bar']], xx: true)
|
54
|
+
added_count.should == 0
|
55
|
+
|
56
|
+
@redises.zscore(@key, 'foo').should == 2.0
|
57
|
+
@redises.zrange(@key, 0, -1).should_not include 'bar'
|
58
|
+
end
|
59
|
+
|
60
|
+
it "with NX option don't update current element" do
|
61
|
+
@redises.zadd(@key, 1, 'foo')
|
62
|
+
@redises.zadd(@key, 2, 'foo', nx: true)
|
63
|
+
@redises.zscore(@key, 'foo').should == 1.0
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'with NX option create new element' do
|
67
|
+
@redises.zadd(@key, 1, 'foo')
|
68
|
+
@redises.zadd(@key, 2, 'bar', nx: true)
|
69
|
+
@redises.zrange(@key, 0, -1).should include 'bar'
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'with NX option and multiple elements command only create element' do
|
73
|
+
@redises.zadd(@key, 1, 'foo')
|
74
|
+
added_count = @redises.zadd(@key, [[2, 'foo'], [2, 'bar']], nx: true)
|
75
|
+
added_count.should == 1
|
76
|
+
@redises.zscore(@key, 'bar').should == 2.0
|
77
|
+
@redises.zrange(@key, 0, -1).should eq %w[foo bar]
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'XX and NX options in same time raise error' do
|
81
|
+
lambda do
|
82
|
+
@redises.zadd(@key, 1, 'foo', nx: true, xx: true)
|
83
|
+
end.should raise_error(Redis::CommandError)
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'with INCR is act like zincrby' do
|
87
|
+
@redises.zadd(@key, 10, 'bert', incr: true).should == 10.0
|
88
|
+
@redises.zadd(@key, 3, 'bert', incr: true).should == 13.0
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'with INCR and XX not create element' do
|
92
|
+
@redises.zadd(@key, 10, 'bert', xx: true, incr: true).should be_nil
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'with INCR and XX increase score for exist element' do
|
96
|
+
@redises.zadd(@key, 2, 'bert')
|
97
|
+
@redises.zadd(@key, 10, 'bert', xx: true, incr: true).should == 12.0
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'with INCR and NX create element with score' do
|
101
|
+
@redises.zadd(@key, 11, 'bert', nx: true, incr: true).should == 11.0
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'with INCR and NX not update element' do
|
105
|
+
@redises.zadd(@key, 1, 'bert')
|
106
|
+
@redises.zadd(@key, 10, 'bert', nx: true, incr: true).should be_nil
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'with INCR with variable number of arguments raise error' do
|
110
|
+
lambda do
|
111
|
+
@redises.zadd(@key, [[1, 'one'], [2, 'two']], incr: true)
|
112
|
+
end.should raise_error(Redis::CommandError)
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'supports a variable number of arguments' do
|
34
116
|
@redises.zadd(@key, [[1, 'one'], [2, 'two']])
|
35
|
-
@redises.
|
117
|
+
@redises.zadd(@key, [[3, 'three']])
|
118
|
+
@redises.zrange(@key, 0, -1).should == %w[one two three]
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'raises an error if an empty array is given' do
|
122
|
+
lambda do
|
123
|
+
@redises.zadd(@key, [])
|
124
|
+
end.should raise_error(Redis::CommandError)
|
36
125
|
end
|
37
126
|
|
38
|
-
it_should_behave_like
|
39
|
-
it_should_behave_like
|
127
|
+
it_should_behave_like 'arg 1 is a score'
|
128
|
+
it_should_behave_like 'a zset-only command'
|
40
129
|
end
|
data/spec/commands/zcard_spec.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#zcard(key)' do
|
4
4
|
before do
|
5
5
|
@key = 'mock-redis-test:zcard'
|
6
6
|
end
|
7
7
|
|
8
|
-
it
|
8
|
+
it 'returns the number of elements in the zset' do
|
9
9
|
@redises.zadd(@key, 1, 'Washington')
|
10
10
|
@redises.zadd(@key, 2, 'Adams')
|
11
11
|
@redises.zcard(@key).should == 2
|
12
12
|
end
|
13
13
|
|
14
|
-
it
|
14
|
+
it 'returns 0 for nonexistent sets' do
|
15
15
|
@redises.zcard(@key).should == 0
|
16
16
|
end
|
17
17
|
|
18
|
-
it_should_behave_like
|
18
|
+
it_should_behave_like 'a zset-only command'
|
19
19
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#zcount(key, min, max)' do
|
4
4
|
before do
|
5
5
|
@key = 'mock-redis-test:zcount'
|
6
6
|
@redises.zadd(@key, 1, 'Washington')
|
@@ -9,23 +9,31 @@ describe "#zcount(key, min, max)" do
|
|
9
9
|
@redises.zadd(@key, 4, 'Madison')
|
10
10
|
end
|
11
11
|
|
12
|
-
it
|
12
|
+
it 'returns the number of members in the zset with scores in (min..max)' do
|
13
13
|
@redises.zcount(@key, 3, 10).should == 2
|
14
14
|
end
|
15
15
|
|
16
|
-
it
|
16
|
+
it 'returns 0 if there are no such members' do
|
17
17
|
@redises.zcount(@key, 100, 200).should == 0
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
21
|
-
@redises.zcount(@key,
|
20
|
+
it 'returns count of all elements when -inf to +inf' do
|
21
|
+
@redises.zcount(@key, '-inf', '+inf').should == 4
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
25
|
-
@redises.zcount(@key, 3,
|
24
|
+
it 'returns a proper count of elements using +inf upper bound' do
|
25
|
+
@redises.zcount(@key, 3, '+inf').should == 2
|
26
26
|
end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
it 'returns a proper count of elements using exclusive lower bound' do
|
29
|
+
@redises.zcount(@key, '(3', '+inf').should == 1
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'returns a proper count of elements using exclusive upper bound' do
|
33
|
+
@redises.zcount(@key, '-inf', '(3').should == 2
|
34
|
+
end
|
35
|
+
|
36
|
+
it_should_behave_like 'arg 1 is a score'
|
37
|
+
it_should_behave_like 'arg 2 is a score'
|
38
|
+
it_should_behave_like 'a zset-only command'
|
31
39
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe '#zincrby(key, increment, member)' do
|
4
4
|
before do
|
5
5
|
@key = 'mock-redis-test:zincrby'
|
6
6
|
@redises.zadd(@key, 1, 'bert')
|
7
7
|
end
|
8
8
|
|
9
|
-
it
|
9
|
+
it 'returns the new score as a string' do
|
10
10
|
@redises.zincrby(@key, 10, 'bert').should == 11.0
|
11
11
|
end
|
12
12
|
|
@@ -15,17 +15,17 @@ describe "#zincrby(key, increment, member)" do
|
|
15
15
|
@redises.zscore(@key, 'bert').should == 11.0
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
18
|
+
it 'handles integer members correctly' do
|
19
19
|
member = 11
|
20
20
|
@redises.zadd(@key, 1, member)
|
21
21
|
@redises.zincrby(@key, 1, member)
|
22
22
|
@redises.zscore(@key, member).should == 2.0
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
25
|
+
it 'adds missing members with score increment' do
|
26
26
|
@redises.zincrby(@key, 5.5, 'bigbird').should == 5.5
|
27
27
|
end
|
28
28
|
|
29
|
-
it_should_behave_like
|
30
|
-
it_should_behave_like
|
29
|
+
it_should_behave_like 'arg 1 is a score'
|
30
|
+
it_should_behave_like 'a zset-only command'
|
31
31
|
end
|