mock_redis 0.14.1 → 0.15.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.
Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.overcommit.yml +1 -1
  4. data/.rubocop.yml +91 -0
  5. data/.simplecov +4 -0
  6. data/.travis.yml +14 -2
  7. data/CHANGELOG.md +4 -0
  8. data/Gemfile +4 -2
  9. data/README.md +1 -0
  10. data/Rakefile +2 -2
  11. data/lib/mock_redis.rb +25 -26
  12. data/lib/mock_redis/assertions.rb +0 -1
  13. data/lib/mock_redis/database.rb +35 -28
  14. data/lib/mock_redis/expire_wrapper.rb +1 -1
  15. data/lib/mock_redis/future.rb +1 -1
  16. data/lib/mock_redis/hash_methods.rb +18 -17
  17. data/lib/mock_redis/indifferent_hash.rb +4 -0
  18. data/lib/mock_redis/info_method.rb +109 -108
  19. data/lib/mock_redis/list_methods.rb +17 -16
  20. data/lib/mock_redis/multi_db_wrapper.rb +5 -4
  21. data/lib/mock_redis/pipelined_wrapper.rb +3 -3
  22. data/lib/mock_redis/set_methods.rb +10 -9
  23. data/lib/mock_redis/sort_method.rb +11 -12
  24. data/lib/mock_redis/string_methods.rb +26 -29
  25. data/lib/mock_redis/transaction_wrapper.rb +7 -8
  26. data/lib/mock_redis/utility_methods.rb +9 -12
  27. data/lib/mock_redis/version.rb +1 -1
  28. data/lib/mock_redis/zset.rb +22 -23
  29. data/lib/mock_redis/zset_methods.rb +25 -25
  30. data/spec/cloning_spec.rb +17 -18
  31. data/spec/commands/append_spec.rb +4 -4
  32. data/spec/commands/auth_spec.rb +1 -1
  33. data/spec/commands/bgrewriteaof_spec.rb +2 -2
  34. data/spec/commands/bgsave_spec.rb +2 -2
  35. data/spec/commands/bitcount_spec.rb +3 -3
  36. data/spec/commands/blpop_spec.rb +10 -10
  37. data/spec/commands/brpop_spec.rb +10 -10
  38. data/spec/commands/brpoplpush_spec.rb +9 -9
  39. data/spec/commands/connected_spec.rb +2 -2
  40. data/spec/commands/dbsize_spec.rb +3 -3
  41. data/spec/commands/decr_spec.rb +7 -7
  42. data/spec/commands/decrby_spec.rb +7 -7
  43. data/spec/commands/del_spec.rb +4 -4
  44. data/spec/commands/disconnect_spec.rb +2 -2
  45. data/spec/commands/echo_spec.rb +4 -4
  46. data/spec/commands/exists_spec.rb +3 -3
  47. data/spec/commands/expire_spec.rb +13 -13
  48. data/spec/commands/expireat_spec.rb +6 -7
  49. data/spec/commands/flushall_spec.rb +5 -5
  50. data/spec/commands/flushdb_spec.rb +5 -5
  51. data/spec/commands/future_spec.rb +2 -2
  52. data/spec/commands/get_spec.rb +7 -7
  53. data/spec/commands/getbit_spec.rb +6 -6
  54. data/spec/commands/getrange_spec.rb +9 -9
  55. data/spec/commands/getset_spec.rb +7 -7
  56. data/spec/commands/hash_operator_spec.rb +5 -5
  57. data/spec/commands/hdel_spec.rb +12 -12
  58. data/spec/commands/hexists_spec.rb +7 -7
  59. data/spec/commands/hget_spec.rb +7 -7
  60. data/spec/commands/hgetall_spec.rb +6 -6
  61. data/spec/commands/hincrby_spec.rb +14 -14
  62. data/spec/commands/hincrbyfloat_spec.rb +14 -14
  63. data/spec/commands/hkeys_spec.rb +5 -5
  64. data/spec/commands/hlen_spec.rb +5 -5
  65. data/spec/commands/hmget_spec.rb +8 -8
  66. data/spec/commands/hmset_spec.rb +10 -10
  67. data/spec/commands/hset_spec.rb +11 -11
  68. data/spec/commands/hsetnx_spec.rb +14 -14
  69. data/spec/commands/hvals_spec.rb +5 -5
  70. data/spec/commands/incr_spec.rb +7 -7
  71. data/spec/commands/incrby_spec.rb +11 -11
  72. data/spec/commands/incrbyfloat_spec.rb +11 -11
  73. data/spec/commands/info_spec.rb +30 -30
  74. data/spec/commands/keys_spec.rb +42 -43
  75. data/spec/commands/lastsave_spec.rb +2 -2
  76. data/spec/commands/lindex_spec.rb +15 -15
  77. data/spec/commands/linsert_spec.rb +13 -13
  78. data/spec/commands/llen_spec.rb +4 -4
  79. data/spec/commands/lpop_spec.rb +6 -6
  80. data/spec/commands/lpush_spec.rb +16 -16
  81. data/spec/commands/lpushx_spec.rb +13 -13
  82. data/spec/commands/lrange_spec.rb +12 -12
  83. data/spec/commands/lrem_spec.rb +15 -15
  84. data/spec/commands/lset_spec.rb +12 -12
  85. data/spec/commands/ltrim_spec.rb +9 -9
  86. data/spec/commands/mapped_hmget_spec.rb +8 -8
  87. data/spec/commands/mapped_hmset_spec.rb +12 -12
  88. data/spec/commands/mapped_mget_spec.rb +4 -4
  89. data/spec/commands/mapped_mset_spec.rb +1 -1
  90. data/spec/commands/mget_spec.rb +11 -11
  91. data/spec/commands/move_spec.rb +29 -29
  92. data/spec/commands/mset_spec.rb +4 -4
  93. data/spec/commands/msetnx_spec.rb +10 -10
  94. data/spec/commands/persist_spec.rb +9 -10
  95. data/spec/commands/pexpire_spec.rb +12 -13
  96. data/spec/commands/pexpireat_spec.rb +6 -6
  97. data/spec/commands/ping_spec.rb +1 -1
  98. data/spec/commands/pipelined_spec.rb +5 -5
  99. data/spec/commands/pttl_spec.rb +5 -5
  100. data/spec/commands/randomkey_spec.rb +3 -3
  101. data/spec/commands/rename_spec.rb +9 -9
  102. data/spec/commands/renamenx_spec.rb +10 -10
  103. data/spec/commands/rpop_spec.rb +6 -6
  104. data/spec/commands/rpoplpush_spec.rb +7 -7
  105. data/spec/commands/rpush_spec.rb +16 -16
  106. data/spec/commands/rpushx_spec.rb +13 -13
  107. data/spec/commands/sadd_spec.rb +8 -9
  108. data/spec/commands/scan_spec.rb +6 -7
  109. data/spec/commands/scard_spec.rb +3 -3
  110. data/spec/commands/sdiff_spec.rb +10 -10
  111. data/spec/commands/sdiffstore_spec.rb +10 -10
  112. data/spec/commands/select_spec.rb +7 -7
  113. data/spec/commands/setbit_spec.rb +13 -13
  114. data/spec/commands/setex_spec.rb +4 -4
  115. data/spec/commands/setnx_spec.rb +4 -4
  116. data/spec/commands/setrange_spec.rb +12 -12
  117. data/spec/commands/sinter_spec.rb +8 -10
  118. data/spec/commands/sinterstore_spec.rb +9 -9
  119. data/spec/commands/sismember_spec.rb +5 -5
  120. data/spec/commands/smembers_spec.rb +5 -5
  121. data/spec/commands/smove_spec.rb +7 -7
  122. data/spec/commands/sort_list_spec.rb +3 -3
  123. data/spec/commands/sort_set_spec.rb +3 -3
  124. data/spec/commands/sort_zset_spec.rb +3 -3
  125. data/spec/commands/spop_spec.rb +4 -4
  126. data/spec/commands/srandmember_spec.rb +8 -8
  127. data/spec/commands/srem_spec.rb +9 -9
  128. data/spec/commands/strlen_spec.rb +4 -4
  129. data/spec/commands/sunion_spec.rb +7 -9
  130. data/spec/commands/sunionstore_spec.rb +9 -9
  131. data/spec/commands/ttl_spec.rb +5 -5
  132. data/spec/commands/type_spec.rb +1 -1
  133. data/spec/commands/zadd_spec.rb +10 -10
  134. data/spec/commands/zcard_spec.rb +4 -4
  135. data/spec/commands/zcount_spec.rb +14 -14
  136. data/spec/commands/zincrby_spec.rb +6 -6
  137. data/spec/commands/zinterstore_spec.rb +17 -17
  138. data/spec/commands/zrange_spec.rb +12 -12
  139. data/spec/commands/zrangebyscore_spec.rb +26 -26
  140. data/spec/commands/zrank_spec.rb +4 -4
  141. data/spec/commands/zrem_spec.rb +9 -9
  142. data/spec/commands/zremrangebyrank_spec.rb +5 -5
  143. data/spec/commands/zremrangebyscore_spec.rb +9 -7
  144. data/spec/commands/zrevrange_spec.rb +10 -10
  145. data/spec/commands/zrevrangebyscore_spec.rb +14 -14
  146. data/spec/commands/zrevrank_spec.rb +4 -4
  147. data/spec/commands/zscore_spec.rb +5 -5
  148. data/spec/commands/zunionstore_spec.rb +18 -18
  149. data/spec/mock_redis_spec.rb +11 -1
  150. data/spec/spec_helper.rb +13 -4
  151. data/spec/support/redis_multiplexer.rb +39 -31
  152. data/spec/support/shared_examples/only_operates_on_hashes.rb +2 -2
  153. data/spec/support/shared_examples/only_operates_on_lists.rb +2 -2
  154. data/spec/support/shared_examples/only_operates_on_sets.rb +2 -2
  155. data/spec/support/shared_examples/only_operates_on_strings.rb +3 -3
  156. data/spec/support/shared_examples/only_operates_on_zsets.rb +12 -12
  157. data/spec/support/shared_examples/sorts_enumerables.rb +12 -12
  158. data/spec/transactions_spec.rb +18 -18
  159. metadata +5 -3
@@ -4,7 +4,7 @@ class MockRedis
4
4
  class ExpireWrapper
5
5
  include UndefRedisMethods
6
6
 
7
- def respond_to?(method, include_private=false)
7
+ def respond_to?(method, include_private = false)
8
8
  super || @db.respond_to?(method)
9
9
  end
10
10
 
@@ -14,7 +14,7 @@ class MockRedis
14
14
  @result
15
15
  end
16
16
 
17
- def set_result(result)
17
+ def store_result(result)
18
18
  @result_set = true
19
19
  @result = result
20
20
  end
@@ -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,v| fields.include?(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.has_key?(field.to_s)}
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, "ERR hash value is not an integer"
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, "ERR value is not an integer or out of range"
41
+ raise Redis::CommandError, 'ERR value is not an integer or out of range'
42
42
  end
43
43
 
44
- new_value = (hash[field] || "0").to_i + increment.to_i
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, "ERR hash value is not a valid float"
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, "ERR value is not a valid float"
58
+ raise Redis::CommandError, 'ERR value is not a valid float'
59
59
  end
60
60
 
61
- new_value = (hash[field] || "0").to_f + increment.to_f
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, "ERR wrong number of arguments for HMSET"
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].kind_of?(Hash)
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, "WRONGTYPE Operation against a key holding the wrong kind of value"
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
@@ -11,5 +11,9 @@ class MockRedis
11
11
  def has_key?(key)
12
12
  super(key.to_s)
13
13
  end
14
+
15
+ def key?(key)
16
+ super(key.to_s)
17
+ end
14
18
  end
15
19
  end
@@ -1,127 +1,129 @@
1
1
  class MockRedis
2
2
  module InfoMethod
3
3
  SERVER_INFO = {
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"
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
- "blocked_clients" => "0",
22
- "client_biggest_input_buf" => "0",
23
- "client_longest_output_list" => "0",
24
- "connected_clients" => "1"
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
- "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"
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
- "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"
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
- "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"
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
- "role" => "master",
70
- "connected_slaves" => "0"
69
+ 'role' => 'master',
70
+ 'connected_slaves' => '0',
71
71
  }
72
72
 
73
73
  CPU_INFO = {
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"
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
- "db0" => "keys=8,expires=0"
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
- "auth"=>{"calls"=>"572501", "usec"=>"2353163", "usec_per_call"=>"4.11"},
88
- "client"=>{"calls"=>"1", "usec"=>"80", "usec_per_call"=>"80.00"},
89
- "config"=>{"calls"=>"4", "usec"=>"71", "usec_per_call"=>"17.75"},
90
- "flushall"=>{"calls"=>"2097790", "usec"=>"27473940655", "usec_per_call"=>"13096.61"},
91
- "flushdb"=>{"calls"=>"692247", "usec"=>"2235143397", "usec_per_call"=>"3228.82"},
92
- "get"=>{"calls"=>"185724", "usec"=>"604479", "usec_per_call"=>"3.25"},
93
- "info"=>{"calls"=>"965566", "usec"=>"229377331", "usec_per_call"=>"237.56"},
94
- "keys"=>{"calls"=>"16591", "usec"=>"917676", "usec_per_call"=>"55.31"},
95
- "llen"=>{"calls"=>"39", "usec"=>"150", "usec_per_call"=>"3.85"},
96
- "ping"=>{"calls"=>"697509", "usec"=>"3836044", "usec_per_call"=>"5.50"},
97
- "rpush"=>{"calls"=>"2239810", "usec"=>"15013298", "usec_per_call"=>"6.70"},
98
- "sadd"=>{"calls"=>"13950129156", "usec"=>"30126628979", "usec_per_call"=>"2.16"},
99
- "scard"=>{"calls"=>"153929", "usec"=>"726596", "usec_per_call"=>"4.72"},
100
- "set"=>{"calls"=>"6975081982", "usec"=>"16453671451", "usec_per_call"=>"2.36"},
101
- "slowlog"=>{"calls"=>"136", "usec"=>"16815", "usec_per_call"=>"123.64"},
102
- "smembers"=>{"calls"=>"58", "usec"=>"231", "usec_per_call"=>"3.98"},
103
- "sunionstore"=>{"calls"=>"4185027", "usec"=>"11762454022", "usec_per_call"=>"2810.60"}
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
- "cmdstat_auth"=>"calls=572506,usec=2353182,usec_per_call=4.11",
108
- "cmdstat_client"=>"calls=1,usec=80,usec_per_call=80.00",
109
- "cmdstat_config"=>"calls=4,usec=71,usec_per_call=17.75",
110
- "cmdstat_flushall"=>"calls=2097790,usec=27473940655,usec_per_call=13096.61",
111
- "cmdstat_flushdb"=>"calls=692247,usec=2235143397,usec_per_call=3228.82",
112
- "cmdstat_get"=>"calls=185724,usec=604479,usec_per_call=3.25",
113
- "cmdstat_info"=>"calls=965571,usec=229378327,usec_per_call=237.56",
114
- "cmdstat_keys"=>"calls=16591,usec=917676,usec_per_call=55.31",
115
- "cmdstat_llen"=>"calls=39,usec=150,usec_per_call=3.85",
116
- "cmdstat_ping"=>"calls=697509,usec=3836044,usec_per_call=5.50",
117
- "cmdstat_rpush"=>"calls=2239810,usec=15013298,usec_per_call=6.70",
118
- "cmdstat_sadd"=>"calls=13950129156,usec=30126628979,usec_per_call=2.16",
119
- "cmdstat_scard"=>"calls=153929,usec=726596,usec_per_call=4.72",
120
- "cmdstat_set"=>"calls=6975081982,usec=16453671451,usec_per_call=2.36",
121
- "cmdstat_slowlog"=>"calls=136,usec=16815,usec_per_call=123.64",
122
- "cmdstat_smembers"=>"calls=58,usec=231,usec_per_call=3.98",
123
- "cmdstat_sunionstore"=>"calls=4185027,usec=11762454022,usec_per_call=2810.60"
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( section = :default )
144
+ def info(section = :default)
143
145
  case section
144
- when :default ; DEFAULT_INFO
145
- when :all ; ALL_INFO
146
- when :server ; SERVER_INFO
147
- when :clients ; CLIENTS_INFO
148
- when :memory ; MEMORY_INFO
149
- when :persistence ; PERSISTENCE_INFO
150
- when :stats ; STATS_INFO
151
- when :replication ; REPLICATION_INFO
152
- when :cpu ; CPU_INFO
153
- when :keyspace ; KEYSPACE_INFO
154
- when :commandstats ; COMMAND_STATS_SOLO_INFO
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.kind_of?(Integer)
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, "ERR syntax error"
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, "ERR value is not an integer or out of range"
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, "ERR no such key"
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, "ERR index out of range"
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].kind_of?(Array)
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, "WRONGTYPE Operation against a key holding the wrong kind of value"
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