mock_redis 0.14.1 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.overcommit.yml +1 -1
- data/.rubocop.yml +91 -0
- data/.simplecov +4 -0
- data/.travis.yml +14 -2
- data/CHANGELOG.md +4 -0
- data/Gemfile +4 -2
- data/README.md +1 -0
- data/Rakefile +2 -2
- data/lib/mock_redis.rb +25 -26
- data/lib/mock_redis/assertions.rb +0 -1
- data/lib/mock_redis/database.rb +35 -28
- data/lib/mock_redis/expire_wrapper.rb +1 -1
- data/lib/mock_redis/future.rb +1 -1
- data/lib/mock_redis/hash_methods.rb +18 -17
- data/lib/mock_redis/indifferent_hash.rb +4 -0
- data/lib/mock_redis/info_method.rb +109 -108
- data/lib/mock_redis/list_methods.rb +17 -16
- data/lib/mock_redis/multi_db_wrapper.rb +5 -4
- data/lib/mock_redis/pipelined_wrapper.rb +3 -3
- data/lib/mock_redis/set_methods.rb +10 -9
- data/lib/mock_redis/sort_method.rb +11 -12
- data/lib/mock_redis/string_methods.rb +26 -29
- data/lib/mock_redis/transaction_wrapper.rb +7 -8
- data/lib/mock_redis/utility_methods.rb +9 -12
- data/lib/mock_redis/version.rb +1 -1
- data/lib/mock_redis/zset.rb +22 -23
- data/lib/mock_redis/zset_methods.rb +25 -25
- 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 +3 -3
- data/spec/commands/blpop_spec.rb +10 -10
- data/spec/commands/brpop_spec.rb +10 -10
- data/spec/commands/brpoplpush_spec.rb +9 -9
- data/spec/commands/connected_spec.rb +2 -2
- data/spec/commands/dbsize_spec.rb +3 -3
- data/spec/commands/decr_spec.rb +7 -7
- data/spec/commands/decrby_spec.rb +7 -7
- data/spec/commands/del_spec.rb +4 -4
- data/spec/commands/disconnect_spec.rb +2 -2
- data/spec/commands/echo_spec.rb +4 -4
- data/spec/commands/exists_spec.rb +3 -3
- data/spec/commands/expire_spec.rb +13 -13
- data/spec/commands/expireat_spec.rb +6 -7
- data/spec/commands/flushall_spec.rb +5 -5
- data/spec/commands/flushdb_spec.rb +5 -5
- data/spec/commands/future_spec.rb +2 -2
- data/spec/commands/get_spec.rb +7 -7
- data/spec/commands/getbit_spec.rb +6 -6
- data/spec/commands/getrange_spec.rb +9 -9
- data/spec/commands/getset_spec.rb +7 -7
- data/spec/commands/hash_operator_spec.rb +5 -5
- data/spec/commands/hdel_spec.rb +12 -12
- data/spec/commands/hexists_spec.rb +7 -7
- data/spec/commands/hget_spec.rb +7 -7
- data/spec/commands/hgetall_spec.rb +6 -6
- data/spec/commands/hincrby_spec.rb +14 -14
- data/spec/commands/hincrbyfloat_spec.rb +14 -14
- data/spec/commands/hkeys_spec.rb +5 -5
- data/spec/commands/hlen_spec.rb +5 -5
- data/spec/commands/hmget_spec.rb +8 -8
- data/spec/commands/hmset_spec.rb +10 -10
- data/spec/commands/hset_spec.rb +11 -11
- data/spec/commands/hsetnx_spec.rb +14 -14
- data/spec/commands/hvals_spec.rb +5 -5
- data/spec/commands/incr_spec.rb +7 -7
- data/spec/commands/incrby_spec.rb +11 -11
- data/spec/commands/incrbyfloat_spec.rb +11 -11
- data/spec/commands/info_spec.rb +30 -30
- data/spec/commands/keys_spec.rb +42 -43
- data/spec/commands/lastsave_spec.rb +2 -2
- data/spec/commands/lindex_spec.rb +15 -15
- data/spec/commands/linsert_spec.rb +13 -13
- data/spec/commands/llen_spec.rb +4 -4
- data/spec/commands/lpop_spec.rb +6 -6
- data/spec/commands/lpush_spec.rb +16 -16
- data/spec/commands/lpushx_spec.rb +13 -13
- data/spec/commands/lrange_spec.rb +12 -12
- data/spec/commands/lrem_spec.rb +15 -15
- data/spec/commands/lset_spec.rb +12 -12
- data/spec/commands/ltrim_spec.rb +9 -9
- data/spec/commands/mapped_hmget_spec.rb +8 -8
- data/spec/commands/mapped_hmset_spec.rb +12 -12
- data/spec/commands/mapped_mget_spec.rb +4 -4
- data/spec/commands/mapped_mset_spec.rb +1 -1
- data/spec/commands/mget_spec.rb +11 -11
- data/spec/commands/move_spec.rb +29 -29
- data/spec/commands/mset_spec.rb +4 -4
- data/spec/commands/msetnx_spec.rb +10 -10
- data/spec/commands/persist_spec.rb +9 -10
- data/spec/commands/pexpire_spec.rb +12 -13
- data/spec/commands/pexpireat_spec.rb +6 -6
- data/spec/commands/ping_spec.rb +1 -1
- data/spec/commands/pipelined_spec.rb +5 -5
- data/spec/commands/pttl_spec.rb +5 -5
- data/spec/commands/randomkey_spec.rb +3 -3
- data/spec/commands/rename_spec.rb +9 -9
- data/spec/commands/renamenx_spec.rb +10 -10
- data/spec/commands/rpop_spec.rb +6 -6
- data/spec/commands/rpoplpush_spec.rb +7 -7
- data/spec/commands/rpush_spec.rb +16 -16
- data/spec/commands/rpushx_spec.rb +13 -13
- data/spec/commands/sadd_spec.rb +8 -9
- data/spec/commands/scan_spec.rb +6 -7
- data/spec/commands/scard_spec.rb +3 -3
- data/spec/commands/sdiff_spec.rb +10 -10
- data/spec/commands/sdiffstore_spec.rb +10 -10
- data/spec/commands/select_spec.rb +7 -7
- data/spec/commands/setbit_spec.rb +13 -13
- data/spec/commands/setex_spec.rb +4 -4
- data/spec/commands/setnx_spec.rb +4 -4
- data/spec/commands/setrange_spec.rb +12 -12
- data/spec/commands/sinter_spec.rb +8 -10
- data/spec/commands/sinterstore_spec.rb +9 -9
- data/spec/commands/sismember_spec.rb +5 -5
- data/spec/commands/smembers_spec.rb +5 -5
- data/spec/commands/smove_spec.rb +7 -7
- data/spec/commands/sort_list_spec.rb +3 -3
- data/spec/commands/sort_set_spec.rb +3 -3
- data/spec/commands/sort_zset_spec.rb +3 -3
- data/spec/commands/spop_spec.rb +4 -4
- data/spec/commands/srandmember_spec.rb +8 -8
- data/spec/commands/srem_spec.rb +9 -9
- data/spec/commands/strlen_spec.rb +4 -4
- data/spec/commands/sunion_spec.rb +7 -9
- data/spec/commands/sunionstore_spec.rb +9 -9
- data/spec/commands/ttl_spec.rb +5 -5
- data/spec/commands/type_spec.rb +1 -1
- data/spec/commands/zadd_spec.rb +10 -10
- data/spec/commands/zcard_spec.rb +4 -4
- data/spec/commands/zcount_spec.rb +14 -14
- data/spec/commands/zincrby_spec.rb +6 -6
- data/spec/commands/zinterstore_spec.rb +17 -17
- data/spec/commands/zrange_spec.rb +12 -12
- data/spec/commands/zrangebyscore_spec.rb +26 -26
- data/spec/commands/zrank_spec.rb +4 -4
- data/spec/commands/zrem_spec.rb +9 -9
- data/spec/commands/zremrangebyrank_spec.rb +5 -5
- data/spec/commands/zremrangebyscore_spec.rb +9 -7
- data/spec/commands/zrevrange_spec.rb +10 -10
- data/spec/commands/zrevrangebyscore_spec.rb +14 -14
- data/spec/commands/zrevrank_spec.rb +4 -4
- data/spec/commands/zscore_spec.rb +5 -5
- data/spec/commands/zunionstore_spec.rb +18 -18
- data/spec/mock_redis_spec.rb +11 -1
- data/spec/spec_helper.rb +13 -4
- data/spec/support/redis_multiplexer.rb +39 -31
- data/spec/support/shared_examples/only_operates_on_hashes.rb +2 -2
- data/spec/support/shared_examples/only_operates_on_lists.rb +2 -2
- data/spec/support/shared_examples/only_operates_on_sets.rb +2 -2
- data/spec/support/shared_examples/only_operates_on_strings.rb +3 -3
- data/spec/support/shared_examples/only_operates_on_zsets.rb +12 -12
- data/spec/support/shared_examples/sorts_enumerables.rb +12 -12
- data/spec/transactions_spec.rb +18 -18
- metadata +5 -3
data/lib/mock_redis/future.rb
CHANGED
@@ -11,7 +11,7 @@ class MockRedis
|
|
11
11
|
if field.is_a?(Array)
|
12
12
|
orig_size = hash.size
|
13
13
|
fields = field.map(&:to_s)
|
14
|
-
hash.delete_if { |k,
|
14
|
+
hash.delete_if { |k, _v| fields.include?(k) }
|
15
15
|
orig_size - hash.size
|
16
16
|
else
|
17
17
|
hash.delete(field.to_s) ? 1 : 0
|
@@ -20,28 +20,28 @@ class MockRedis
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def hexists(key, field)
|
23
|
-
with_hash_at(key) {|h| h.
|
23
|
+
with_hash_at(key) { |h| h.key?(field.to_s) }
|
24
24
|
end
|
25
25
|
|
26
26
|
def hget(key, field)
|
27
|
-
with_hash_at(key) {|h| h[field.to_s]}
|
27
|
+
with_hash_at(key) { |h| h[field.to_s] }
|
28
28
|
end
|
29
29
|
|
30
30
|
def hgetall(key)
|
31
|
-
with_hash_at(key) {|h| h}
|
31
|
+
with_hash_at(key) { |h| h }
|
32
32
|
end
|
33
33
|
|
34
34
|
def hincrby(key, field, increment)
|
35
35
|
with_hash_at(key) do |hash|
|
36
36
|
field = field.to_s
|
37
37
|
unless can_incr?(data[key][field])
|
38
|
-
raise Redis::CommandError,
|
38
|
+
raise Redis::CommandError, 'ERR hash value is not an integer'
|
39
39
|
end
|
40
40
|
unless looks_like_integer?(increment.to_s)
|
41
|
-
raise Redis::CommandError,
|
41
|
+
raise Redis::CommandError, 'ERR value is not an integer or out of range'
|
42
42
|
end
|
43
43
|
|
44
|
-
new_value = (hash[field] ||
|
44
|
+
new_value = (hash[field] || '0').to_i + increment.to_i
|
45
45
|
hash[field] = new_value.to_s
|
46
46
|
new_value
|
47
47
|
end
|
@@ -51,14 +51,14 @@ class MockRedis
|
|
51
51
|
with_hash_at(key) do |hash|
|
52
52
|
field = field.to_s
|
53
53
|
unless can_incr_float?(data[key][field])
|
54
|
-
raise Redis::CommandError,
|
54
|
+
raise Redis::CommandError, 'ERR hash value is not a valid float'
|
55
55
|
end
|
56
56
|
|
57
57
|
unless looks_like_float?(increment.to_s)
|
58
|
-
raise Redis::CommandError,
|
58
|
+
raise Redis::CommandError, 'ERR value is not a valid float'
|
59
59
|
end
|
60
60
|
|
61
|
-
new_value = (hash[field] ||
|
61
|
+
new_value = (hash[field] || '0').to_f + increment.to_f
|
62
62
|
new_value = new_value.to_i if new_value % 1 == 0
|
63
63
|
hash[field] = new_value.to_s
|
64
64
|
new_value
|
@@ -75,7 +75,7 @@ class MockRedis
|
|
75
75
|
|
76
76
|
def hmget(key, *fields)
|
77
77
|
assert_has_args(fields, 'hmget')
|
78
|
-
fields.map{|f| hget(key, f)}
|
78
|
+
fields.map { |f| hget(key, f) }
|
79
79
|
end
|
80
80
|
|
81
81
|
def mapped_hmget(key, *fields)
|
@@ -86,10 +86,10 @@ class MockRedis
|
|
86
86
|
def hmset(key, *kvpairs)
|
87
87
|
assert_has_args(kvpairs, 'hmset')
|
88
88
|
if kvpairs.length.odd?
|
89
|
-
raise Redis::CommandError,
|
89
|
+
raise Redis::CommandError, 'ERR wrong number of arguments for HMSET'
|
90
90
|
end
|
91
91
|
|
92
|
-
kvpairs.each_slice(2) do |(k,v)|
|
92
|
+
kvpairs.each_slice(2) do |(k, v)|
|
93
93
|
hset(key, k, v)
|
94
94
|
end
|
95
95
|
'OK'
|
@@ -106,7 +106,7 @@ class MockRedis
|
|
106
106
|
end
|
107
107
|
|
108
108
|
def hset(key, field, value)
|
109
|
-
with_hash_at(key) {|h| h[field.to_s] = value.to_s}
|
109
|
+
with_hash_at(key) { |h| h[field.to_s] = value.to_s }
|
110
110
|
true
|
111
111
|
end
|
112
112
|
|
@@ -126,16 +126,17 @@ class MockRedis
|
|
126
126
|
private
|
127
127
|
|
128
128
|
def with_hash_at(key, &blk)
|
129
|
-
with_thing_at(key, :assert_hashy, proc {{}}, &blk)
|
129
|
+
with_thing_at(key, :assert_hashy, proc { {} }, &blk)
|
130
130
|
end
|
131
131
|
|
132
132
|
def hashy?(key)
|
133
|
-
data[key].nil? || data[key].
|
133
|
+
data[key].nil? || data[key].is_a?(Hash)
|
134
134
|
end
|
135
135
|
|
136
136
|
def assert_hashy(key)
|
137
137
|
unless hashy?(key)
|
138
|
-
raise Redis::CommandError,
|
138
|
+
raise Redis::CommandError,
|
139
|
+
'WRONGTYPE Operation against a key holding the wrong kind of value'
|
139
140
|
end
|
140
141
|
end
|
141
142
|
end
|
@@ -1,127 +1,129 @@
|
|
1
1
|
class MockRedis
|
2
2
|
module InfoMethod
|
3
3
|
SERVER_INFO = {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
4
|
+
'arch_bits' => '64',
|
5
|
+
'gcc_version' => '4.2.1',
|
6
|
+
'lru_clock' => '1036434',
|
7
|
+
'multiplexing_api' => 'kqueue',
|
8
|
+
'os' => 'Darwin 12.2.1 x86_64',
|
9
|
+
'process_id' => '14508',
|
10
|
+
'redis_git_dirty' => '0',
|
11
|
+
'redis_git_sha1' => '00000000',
|
12
|
+
'redis_mode' => 'standalone',
|
13
|
+
'redis_version' => '2.6.10',
|
14
|
+
'run_id' => '1f3f7af2fc11eb68011eb43e154adce125c85e9a',
|
15
|
+
'tcp_port' => '6379',
|
16
|
+
'uptime_in_days' => '0',
|
17
|
+
'uptime_in_seconds' => '84215',
|
18
18
|
}
|
19
19
|
|
20
20
|
CLIENTS_INFO = {
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
'blocked_clients' => '0',
|
22
|
+
'client_biggest_input_buf' => '0',
|
23
|
+
'client_longest_output_list' => '0',
|
24
|
+
'connected_clients' => '1',
|
25
25
|
}
|
26
26
|
|
27
27
|
MEMORY_INFO = {
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
28
|
+
'mem_allocator' => 'libc',
|
29
|
+
'mem_fragmentation_ratio' => '2.04',
|
30
|
+
'used_memory' => '931456',
|
31
|
+
'used_memory_human' => '909.62K',
|
32
|
+
'used_memory_lua' => '31744',
|
33
|
+
'used_memory_peak' => '1005424',
|
34
|
+
'used_memory_peak_human' => '981.86K',
|
35
|
+
'used_memory_rss' => '1904640',
|
36
36
|
}
|
37
37
|
|
38
38
|
PERSISTENCE_INFO = {
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
39
|
+
'aof_current_rewrite_time_sec' => '-1',
|
40
|
+
'aof_enabled' => '0',
|
41
|
+
'aof_last_bgrewrite_status' => 'ok',
|
42
|
+
'aof_last_rewrite_time_sec' => '-1',
|
43
|
+
'aof_rewrite_in_progress' => '0',
|
44
|
+
'aof_rewrite_scheduled' => '0',
|
45
|
+
'loading' => '0',
|
46
|
+
'rdb_bgsave_in_progress' => '0',
|
47
|
+
'rdb_changes_since_last_save' => '0',
|
48
|
+
'rdb_current_bgsave_time_sec' => '-1',
|
49
|
+
'rdb_last_bgsave_status' => 'ok',
|
50
|
+
'rdb_last_bgsave_time_sec' => '-1',
|
51
|
+
'rdb_last_save_time' => '1361423635',
|
52
52
|
}
|
53
53
|
|
54
54
|
STATS_INFO = {
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
55
|
+
'evicted_keys' => '0',
|
56
|
+
'expired_keys' => '0',
|
57
|
+
'instantaneous_ops_per_sec' => '0',
|
58
|
+
'keyspace_hits' => '62645',
|
59
|
+
'keyspace_misses' => '29757',
|
60
|
+
'latest_fork_usec' => '0',
|
61
|
+
'pubsub_channels' => '0',
|
62
|
+
'pubsub_patterns' => '0',
|
63
|
+
'rejected_connections' => '0',
|
64
|
+
'total_commands_processed' => '196800',
|
65
|
+
'total_connections_received' => '4359',
|
66
66
|
}
|
67
67
|
|
68
68
|
REPLICATION_INFO = {
|
69
|
-
|
70
|
-
|
69
|
+
'role' => 'master',
|
70
|
+
'connected_slaves' => '0',
|
71
71
|
}
|
72
72
|
|
73
73
|
CPU_INFO = {
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
74
|
+
'used_cpu_sys' => '5.54',
|
75
|
+
'used_cpu_sys_childrens' => '0.00',
|
76
|
+
'used_cpu_user' => '7.65',
|
77
|
+
'used_cpu_user_childrens' => '0.02',
|
78
78
|
}
|
79
79
|
|
80
80
|
KEYSPACE_INFO = {
|
81
|
-
|
81
|
+
'db0' => 'keys=8,expires=0',
|
82
82
|
}
|
83
83
|
|
84
84
|
# The Ruby Reids client returns commandstats differently when it's called as
|
85
85
|
# "INFO commandstats".
|
86
|
+
# rubocop:disable Metrics/LineLength
|
86
87
|
COMMAND_STATS_SOLO_INFO = {
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
88
|
+
'auth' => { 'calls' => '572501', 'usec' => '2353163', 'usec_per_call' => '4.11' },
|
89
|
+
'client' => { 'calls' => '1', 'usec' => '80', 'usec_per_call' => '80.00' },
|
90
|
+
'config' => { 'calls' => '4', 'usec' => '71', 'usec_per_call' => '17.75' },
|
91
|
+
'flushall' => { 'calls' => '2097790', 'usec' => '27473940655', 'usec_per_call' => '13096.61' },
|
92
|
+
'flushdb' => { 'calls' => '692247', 'usec' => '2235143397', 'usec_per_call' => '3228.82' },
|
93
|
+
'get' => { 'calls' => '185724', 'usec' => '604479', 'usec_per_call' => '3.25' },
|
94
|
+
'info' => { 'calls' => '965566', 'usec' => '229377331', 'usec_per_call' => '237.56' },
|
95
|
+
'keys' => { 'calls' => '16591', 'usec' => '917676', 'usec_per_call' => '55.31' },
|
96
|
+
'llen' => { 'calls' => '39', 'usec' => '150', 'usec_per_call' => '3.85' },
|
97
|
+
'ping' => { 'calls' => '697509', 'usec' => '3836044', 'usec_per_call' => '5.50' },
|
98
|
+
'rpush' => { 'calls' => '2239810', 'usec' => '15013298', 'usec_per_call' => '6.70' },
|
99
|
+
'sadd' => { 'calls' => '13950129156', 'usec' => '30126628979', 'usec_per_call' => '2.16' },
|
100
|
+
'scard' => { 'calls' => '153929', 'usec' => '726596', 'usec_per_call' => '4.72' },
|
101
|
+
'set' => { 'calls' => '6975081982', 'usec' => '16453671451', 'usec_per_call' => '2.36' },
|
102
|
+
'slowlog' => { 'calls' => '136', 'usec' => '16815', 'usec_per_call' => '123.64' },
|
103
|
+
'smembers' => { 'calls' => '58', 'usec' => '231', 'usec_per_call' => '3.98' },
|
104
|
+
'sunionstore' => { 'calls' => '4185027', 'usec' => '11762454022', 'usec_per_call' => '2810.60' },
|
104
105
|
}
|
105
106
|
|
106
107
|
COMMAND_STATS_COMBINED_INFO = {
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
108
|
+
'cmdstat_auth' => 'calls=572506,usec=2353182,usec_per_call=4.11',
|
109
|
+
'cmdstat_client' => 'calls=1,usec=80,usec_per_call=80.00',
|
110
|
+
'cmdstat_config' => 'calls=4,usec=71,usec_per_call=17.75',
|
111
|
+
'cmdstat_flushall' => 'calls=2097790,usec=27473940655,usec_per_call=13096.61',
|
112
|
+
'cmdstat_flushdb' => 'calls=692247,usec=2235143397,usec_per_call=3228.82',
|
113
|
+
'cmdstat_get' => 'calls=185724,usec=604479,usec_per_call=3.25',
|
114
|
+
'cmdstat_info' => 'calls=965571,usec=229378327,usec_per_call=237.56',
|
115
|
+
'cmdstat_keys' => 'calls=16591,usec=917676,usec_per_call=55.31',
|
116
|
+
'cmdstat_llen' => 'calls=39,usec=150,usec_per_call=3.85',
|
117
|
+
'cmdstat_ping' => 'calls=697509,usec=3836044,usec_per_call=5.50',
|
118
|
+
'cmdstat_rpush' => 'calls=2239810,usec=15013298,usec_per_call=6.70',
|
119
|
+
'cmdstat_sadd' => 'calls=13950129156,usec=30126628979,usec_per_call=2.16',
|
120
|
+
'cmdstat_scard' => 'calls=153929,usec=726596,usec_per_call=4.72',
|
121
|
+
'cmdstat_set' => 'calls=6975081982,usec=16453671451,usec_per_call=2.36',
|
122
|
+
'cmdstat_slowlog' => 'calls=136,usec=16815,usec_per_call=123.64',
|
123
|
+
'cmdstat_smembers' => 'calls=58,usec=231,usec_per_call=3.98',
|
124
|
+
'cmdstat_sunionstore' => 'calls=4185027,usec=11762454022,usec_per_call=2810.60',
|
124
125
|
}
|
126
|
+
# rubocop:enable Metrics/LineLength
|
125
127
|
|
126
128
|
DEFAULT_INFO = [
|
127
129
|
SERVER_INFO,
|
@@ -131,29 +133,28 @@ class MockRedis
|
|
131
133
|
STATS_INFO,
|
132
134
|
REPLICATION_INFO,
|
133
135
|
CPU_INFO,
|
134
|
-
KEYSPACE_INFO
|
135
|
-
].inject({}){|memo,info| memo.merge(info)}
|
136
|
+
KEYSPACE_INFO,
|
137
|
+
].inject({}) { |memo, info| memo.merge(info) }
|
136
138
|
|
137
139
|
ALL_INFO = [
|
138
140
|
DEFAULT_INFO,
|
139
|
-
COMMAND_STATS_COMBINED_INFO
|
140
|
-
].inject({}){|memo,info| memo.merge(info)}
|
141
|
+
COMMAND_STATS_COMBINED_INFO,
|
142
|
+
].inject({}) { |memo, info| memo.merge(info) }
|
141
143
|
|
142
|
-
def info(
|
144
|
+
def info(section = :default)
|
143
145
|
case section
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
146
|
+
when :default; DEFAULT_INFO
|
147
|
+
when :all; ALL_INFO
|
148
|
+
when :server; SERVER_INFO
|
149
|
+
when :clients; CLIENTS_INFO
|
150
|
+
when :memory; MEMORY_INFO
|
151
|
+
when :persistence; PERSISTENCE_INFO
|
152
|
+
when :stats; STATS_INFO
|
153
|
+
when :replication; REPLICATION_INFO
|
154
|
+
when :cpu; CPU_INFO
|
155
|
+
when :keyspace; KEYSPACE_INFO
|
156
|
+
when :commandstats; COMMAND_STATS_SOLO_INFO
|
155
157
|
end
|
156
158
|
end
|
157
159
|
end
|
158
160
|
end
|
159
|
-
|
@@ -33,7 +33,7 @@ class MockRedis
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def brpoplpush(source, destination, options = {})
|
36
|
-
options = { :timeout => options } if options.
|
36
|
+
options = { :timeout => options } if options.is_a?(Integer)
|
37
37
|
timeout = options.is_a?(Hash) && options[:timeout] || 0
|
38
38
|
assert_valid_timeout(timeout)
|
39
39
|
|
@@ -47,12 +47,12 @@ class MockRedis
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def lindex(key, index)
|
50
|
-
with_list_at(key) {|l| l[index.to_i]}
|
50
|
+
with_list_at(key) { |l| l[index.to_i] }
|
51
51
|
end
|
52
52
|
|
53
53
|
def linsert(key, position, pivot, value)
|
54
54
|
unless %w[before after].include?(position.to_s)
|
55
|
-
raise Redis::CommandError,
|
55
|
+
raise Redis::CommandError, 'ERR syntax error'
|
56
56
|
end
|
57
57
|
|
58
58
|
assert_listy(key)
|
@@ -85,7 +85,7 @@ class MockRedis
|
|
85
85
|
def lpush(key, values)
|
86
86
|
values = [values] unless values.is_a?(Array)
|
87
87
|
assert_has_args(values, 'lpush')
|
88
|
-
with_list_at(key) {|l| values.each {|v| l.unshift(v.to_s)}}
|
88
|
+
with_list_at(key) { |l| values.each { |v| l.unshift(v.to_s) } }
|
89
89
|
llen(key)
|
90
90
|
end
|
91
91
|
|
@@ -101,12 +101,12 @@ class MockRedis
|
|
101
101
|
|
102
102
|
def lrange(key, start, stop)
|
103
103
|
start = start.to_i
|
104
|
-
with_list_at(key) {|l| start < l.size ? l[[start, -l.length].max..stop.to_i] : []}
|
104
|
+
with_list_at(key) { |l| start < l.size ? l[[start, -l.length].max..stop.to_i] : [] }
|
105
105
|
end
|
106
106
|
|
107
107
|
def lrem(key, count, value)
|
108
108
|
unless looks_like_integer?(count.to_s)
|
109
|
-
raise Redis::CommandError,
|
109
|
+
raise Redis::CommandError, 'ERR value is not an integer or out of range'
|
110
110
|
end
|
111
111
|
count = count.to_i
|
112
112
|
value = value.to_s
|
@@ -124,7 +124,7 @@ class MockRedis
|
|
124
124
|
indices_with_value.reverse.take(-count)
|
125
125
|
end
|
126
126
|
|
127
|
-
indices_to_delete.each {|i| list.delete_at(i)}.length
|
127
|
+
indices_to_delete.each { |i| list.delete_at(i) }.length
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
@@ -132,12 +132,12 @@ class MockRedis
|
|
132
132
|
assert_listy(key)
|
133
133
|
|
134
134
|
unless list_at?(key)
|
135
|
-
raise Redis::CommandError,
|
135
|
+
raise Redis::CommandError, 'ERR no such key'
|
136
136
|
end
|
137
137
|
|
138
138
|
index = index.to_i
|
139
139
|
unless (0...llen(key)).include?(index)
|
140
|
-
raise Redis::CommandError,
|
140
|
+
raise Redis::CommandError, 'ERR index out of range'
|
141
141
|
end
|
142
142
|
|
143
143
|
data[key][index] = value.to_s
|
@@ -152,7 +152,7 @@ class MockRedis
|
|
152
152
|
end
|
153
153
|
|
154
154
|
def rpop(key)
|
155
|
-
with_list_at(key) {|list| list.pop if list}
|
155
|
+
with_list_at(key) { |list| list.pop if list }
|
156
156
|
end
|
157
157
|
|
158
158
|
def rpoplpush(source, destination)
|
@@ -164,7 +164,7 @@ class MockRedis
|
|
164
164
|
def rpush(key, values)
|
165
165
|
values = [values] unless values.is_a?(Array)
|
166
166
|
assert_has_args(values, 'rpush')
|
167
|
-
with_list_at(key) {|l| values.each {|v| l.push(v.to_s)}}
|
167
|
+
with_list_at(key) { |l| values.each { |v| l.push(v.to_s) } }
|
168
168
|
llen(key)
|
169
169
|
end
|
170
170
|
|
@@ -179,28 +179,29 @@ class MockRedis
|
|
179
179
|
end
|
180
180
|
|
181
181
|
private
|
182
|
+
|
182
183
|
def list_at?(key)
|
183
184
|
data[key] && listy?(key)
|
184
185
|
end
|
185
186
|
|
186
187
|
def with_list_at(key, &blk)
|
187
|
-
with_thing_at(key, :assert_listy, proc {[]}, &blk)
|
188
|
+
with_thing_at(key, :assert_listy, proc { [] }, &blk)
|
188
189
|
end
|
189
190
|
|
190
191
|
def listy?(key)
|
191
|
-
data[key].nil? || data[key].
|
192
|
+
data[key].nil? || data[key].is_a?(Array)
|
192
193
|
end
|
193
194
|
|
194
195
|
def assert_listy(key)
|
195
196
|
unless listy?(key)
|
196
197
|
# Not the most helpful error, but it's what redis-rb barfs up
|
197
|
-
raise Redis::CommandError,
|
198
|
+
raise Redis::CommandError,
|
199
|
+
'WRONGTYPE Operation against a key holding the wrong kind of value'
|
198
200
|
end
|
199
201
|
end
|
200
202
|
|
201
203
|
def first_nonempty_list(keys)
|
202
|
-
keys.find{|k| llen(k) > 0}
|
204
|
+
keys.find { |k| llen(k) > 0 }
|
203
205
|
end
|
204
|
-
|
205
206
|
end
|
206
207
|
end
|