mock_redis 0.19.0 → 0.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +161 -0
- data/LICENSE.md +21 -0
- data/README.md +41 -17
- data/lib/mock_redis/connection_method.rb +13 -0
- data/lib/mock_redis/database.rb +116 -41
- data/lib/mock_redis/expire_wrapper.rb +1 -1
- data/lib/mock_redis/future.rb +1 -1
- data/lib/mock_redis/geospatial_methods.rb +13 -21
- data/lib/mock_redis/hash_methods.rb +34 -15
- data/lib/mock_redis/indifferent_hash.rb +0 -8
- data/lib/mock_redis/info_method.rb +2 -2
- data/lib/mock_redis/list_methods.rb +39 -4
- data/lib/mock_redis/memory_method.rb +11 -0
- data/lib/mock_redis/multi_db_wrapper.rb +4 -4
- data/lib/mock_redis/pipelined_wrapper.rb +32 -15
- data/lib/mock_redis/set_methods.rb +34 -6
- 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 +81 -30
- data/lib/mock_redis/transaction_wrapper.rb +32 -21
- data/lib/mock_redis/utility_methods.rb +9 -4
- data/lib/mock_redis/version.rb +1 -1
- data/lib/mock_redis/zset.rb +5 -8
- data/lib/mock_redis/zset_methods.rb +64 -12
- data/lib/mock_redis.rb +38 -10
- metadata +40 -336
- data/.gitignore +0 -5
- data/.mailmap +0 -2
- data/.overcommit.yml +0 -21
- data/.rspec +0 -1
- data/.rubocop.yml +0 -121
- data/.rubocop_todo.yml +0 -35
- data/.simplecov +0 -4
- data/.travis.yml +0 -33
- data/Gemfile +0 -12
- data/LICENSE +0 -19
- data/Rakefile +0 -2
- data/mock_redis.gemspec +0 -30
- data/spec/client_spec.rb +0 -17
- 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 -59
- data/spec/commands/brpop_spec.rb +0 -58
- data/spec/commands/brpoplpush_spec.rb +0 -52
- data/spec/commands/connected_spec.rb +0 -7
- 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 -35
- data/spec/commands/disconnect_spec.rb +0 -7
- 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 -14
- 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 -20
- data/spec/commands/geoadd_spec.rb +0 -58
- data/spec/commands/geodist_spec.rb +0 -114
- data/spec/commands/geohash_spec.rb +0 -52
- data/spec/commands/geopos_spec.rb +0 -55
- data/spec/commands/get_spec.rb +0 -30
- 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/hash_operator_spec.rb +0 -21
- data/spec/commands/hdel_spec.rb +0 -54
- 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 -40
- data/spec/commands/hmset_spec.rb +0 -43
- data/spec/commands/hscan_each_spec.rb +0 -48
- data/spec/commands/hscan_spec.rb +0 -27
- data/spec/commands/hset_spec.rb +0 -38
- 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 -122
- 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 -34
- data/spec/commands/move_spec.rb +0 -147
- data/spec/commands/mset_spec.rb +0 -29
- 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 -7
- data/spec/commands/pipelined_spec.rb +0 -42
- 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/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 -55
- 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 -63
- data/spec/commands/setbit_spec.rb +0 -54
- data/spec/commands/setex_spec.rb +0 -22
- 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 -25
- data/spec/commands/srandmember_spec.rb +0 -49
- data/spec/commands/srem_spec.rb +0 -40
- 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 -16
- data/spec/commands/zadd_spec.rb +0 -123
- 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 -96
- 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 -104
- data/spec/mock_redis_spec.rb +0 -86
- data/spec/spec_helper.rb +0 -63
- data/spec/support/redis_multiplexer.rb +0 -106
- data/spec/support/shared_examples/only_operates_on_hashes.rb +0 -13
- data/spec/support/shared_examples/only_operates_on_lists.rb +0 -13
- data/spec/support/shared_examples/only_operates_on_sets.rb +0 -13
- data/spec/support/shared_examples/only_operates_on_strings.rb +0 -13
- data/spec/support/shared_examples/only_operates_on_zsets.rb +0 -57
- data/spec/support/shared_examples/sorts_enumerables.rb +0 -56
- data/spec/transactions_spec.rb +0 -159
@@ -1,56 +0,0 @@
|
|
1
|
-
shared_examples_for 'a sortable' do
|
2
|
-
it 'returns empty array on nil' do
|
3
|
-
@redises.sort(nil).should == []
|
4
|
-
end
|
5
|
-
|
6
|
-
context 'ordering' do
|
7
|
-
it 'orders ascending by default' do
|
8
|
-
@redises.sort(@key).should == %w[1 2]
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'orders by descending when specified' do
|
12
|
-
@redises.sort(@key, :order => 'DESC').should == %w[2 1]
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
context 'projections' do
|
17
|
-
it 'projects element when :get is "#"' do
|
18
|
-
@redises.sort(@key, :get => '#').should == %w[1 2]
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'projects through a key pattern' do
|
22
|
-
@redises.sort(@key, :get => 'mock-redis-test:values_*').should == %w[a b]
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'projects through a key pattern and reflects element' do
|
26
|
-
@redises.sort(@key, :get => ['#', 'mock-redis-test:values_*']).should == [%w[1 a], %w[2 b]]
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'projects through a hash key pattern' do
|
30
|
-
@redises.sort(@key, :get => 'mock-redis-test:hash_*->key').should == %w[x y]
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'weights' do
|
35
|
-
it 'weights by projecting through a key pattern' do
|
36
|
-
@redises.sort(@key, :by => 'mock-redis-test:weight_*').should == %w[2 1]
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'weights by projecting through a key pattern and a specific order' do
|
40
|
-
@redises.sort(@key, :order => 'DESC', :by => 'mock-redis-test:weight_*').should == %w[1 2]
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'limit' do
|
45
|
-
it 'only returns requested window in the enumerable' do
|
46
|
-
@redises.sort(@key, :limit => [0, 1]).should == ['1']
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context 'store' do
|
51
|
-
it 'stores into another key' do
|
52
|
-
@redises.sort(@key, :store => 'mock-redis-test:some_bucket').should == 2
|
53
|
-
@redises.lrange('mock-redis-test:some_bucket', 0, -1).should == %w[1 2]
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
data/spec/transactions_spec.rb
DELETED
@@ -1,159 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'transactions (multi/exec/discard)' do
|
4
|
-
before(:each) do
|
5
|
-
@redises.discard rescue nil
|
6
|
-
end
|
7
|
-
|
8
|
-
context '#multi' do
|
9
|
-
it "responds with 'OK'" do
|
10
|
-
@redises.multi.should == 'OK'
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'forbids nesting' do
|
14
|
-
@redises.multi
|
15
|
-
lambda do
|
16
|
-
@redises.multi
|
17
|
-
end.should raise_error(Redis::CommandError)
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'cleans state of transaction wrapper if exception occurs during transaction' do
|
21
|
-
lambda do
|
22
|
-
@redises.mock.multi do |_r|
|
23
|
-
raise "i'm a command that fails"
|
24
|
-
end
|
25
|
-
end.should raise_error(RuntimeError)
|
26
|
-
|
27
|
-
# before the fix this used to raised a #<RuntimeError: ERR MULTI calls can not be nested>
|
28
|
-
lambda do
|
29
|
-
@redises.mock.multi do |r|
|
30
|
-
# do stuff that succeed
|
31
|
-
r.set(nil, 'string')
|
32
|
-
end
|
33
|
-
end.should_not raise_error
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context '#blocks' do
|
38
|
-
it 'implicitly runs exec when finished' do
|
39
|
-
@redises.set('counter', 5)
|
40
|
-
@redises.multi do |r|
|
41
|
-
r.set('test', 1)
|
42
|
-
r.incr('counter')
|
43
|
-
end
|
44
|
-
@redises.get('counter').should == '6'
|
45
|
-
@redises.get('test').should == '1'
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'forbids nesting via blocks' do
|
49
|
-
# Have to use only the mock here. redis-rb has a bug in it where
|
50
|
-
# nested #multi calls raise NoMethodError because it gets a nil
|
51
|
-
# where it's not expecting one.
|
52
|
-
@redises.mock.multi do |r|
|
53
|
-
lambda do
|
54
|
-
r.multi {}
|
55
|
-
end.should raise_error(Redis::CommandError)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'allows pipelined calls within multi blocks' do
|
60
|
-
@redises.set('counter', 5)
|
61
|
-
@redises.multi do |r|
|
62
|
-
r.pipelined do |pr|
|
63
|
-
pr.set('test', 1)
|
64
|
-
pr.incr('counter')
|
65
|
-
end
|
66
|
-
end
|
67
|
-
@redises.get('counter').should == '6'
|
68
|
-
@redises.get('test').should == '1'
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'allows multi blocks within pipelined blocks' do
|
72
|
-
@redises.set('counter', 5)
|
73
|
-
@redises.pipelined do |pr|
|
74
|
-
pr.multi do |r|
|
75
|
-
r.set('test', 1)
|
76
|
-
r.incr('counter')
|
77
|
-
end
|
78
|
-
end
|
79
|
-
@redises.get('counter').should == '6'
|
80
|
-
@redises.get('test').should == '1'
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
context '#discard' do
|
85
|
-
it "responds with 'OK' after #multi" do
|
86
|
-
@redises.multi
|
87
|
-
@redises.discard.should == 'OK'
|
88
|
-
end
|
89
|
-
|
90
|
-
it "can't be run outside of #multi/#exec" do
|
91
|
-
lambda do
|
92
|
-
@redises.discard
|
93
|
-
end.should raise_error(Redis::CommandError)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
context '#exec' do
|
98
|
-
it 'raises an error outside of #multi' do
|
99
|
-
lambda do
|
100
|
-
@redises.exec.should raise_error
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
context 'saving up commands for later' do
|
106
|
-
before(:each) do
|
107
|
-
@redises.multi
|
108
|
-
@string = 'mock-redis-test:string'
|
109
|
-
@list = 'mock-redis-test:list'
|
110
|
-
end
|
111
|
-
|
112
|
-
it "makes commands respond with 'QUEUED'" do
|
113
|
-
@redises.set(@string, 'string').should == 'QUEUED'
|
114
|
-
@redises.lpush(@list, 'list').should == 'QUEUED'
|
115
|
-
end
|
116
|
-
|
117
|
-
it "gives you the commands' responses when you call #exec" do
|
118
|
-
@redises.set(@string, 'string')
|
119
|
-
@redises.lpush(@list, 'list')
|
120
|
-
@redises.lpush(@list, 'list')
|
121
|
-
|
122
|
-
@redises.exec.should == ['OK', 1, 2]
|
123
|
-
end
|
124
|
-
|
125
|
-
it "does not raise exceptions, but rather puts them in #exec's response" do
|
126
|
-
@redises.set(@string, 'string')
|
127
|
-
@redises.lpush(@string, 'oops!')
|
128
|
-
@redises.lpush(@list, 'list')
|
129
|
-
|
130
|
-
responses = @redises.exec
|
131
|
-
responses[0].should == 'OK'
|
132
|
-
responses[1].should be_a(Redis::CommandError)
|
133
|
-
responses[2].should == 1
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
context 'saving commands with multi block' do
|
138
|
-
before(:each) do
|
139
|
-
@string = 'mock-redis-test:string'
|
140
|
-
@list = 'mock-redis-test:list'
|
141
|
-
end
|
142
|
-
|
143
|
-
it 'commands return response after exec is called' do
|
144
|
-
set_response = nil
|
145
|
-
lpush_response = nil
|
146
|
-
second_lpush_response = nil
|
147
|
-
|
148
|
-
@redises.multi do |mult|
|
149
|
-
set_response = mult.set(@string, 'string')
|
150
|
-
lpush_response = mult.lpush(@list, 'list')
|
151
|
-
second_lpush_response = mult.lpush(@list, 'list')
|
152
|
-
end
|
153
|
-
|
154
|
-
set_response.value.should == 'OK'
|
155
|
-
lpush_response.value.should == 1
|
156
|
-
second_lpush_response.value.should == 2
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|