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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 51d5bc5ef12c98487d1fc31d420608e1265eb6b7
4
- data.tar.gz: 7fcf609fe19c71439098a4f4e588c50e588c91f3
3
+ metadata.gz: 01d1bfd5cf966db9fd2883757cb12f2c59f09d57
4
+ data.tar.gz: 80260a25e033a419eac875729b5e04be332b819f
5
5
  SHA512:
6
- metadata.gz: 7f51ea5086ba013622a7bf782607757c78d9eb9b54f146079e50d37ba7c7486446fe4face94d208395f0aa70b61d5ee4aed7240659682421e4e1461ba52b8546
7
- data.tar.gz: c55ead056d294255f2cef773c0e8c4e9960974bda6a64887d60445b6e9211e6d7f82adfda74222294691cc659e035f4d88fea40887a3bd41f6992416f42e1085
6
+ metadata.gz: 33c9fde7412bf24e0180010c048fb80265e98b620d445765377f590286240063b5fd018cc6398d989f74084eccfaebe5c4333ad8f51db8af4c2dab9eb7d04136
7
+ data.tar.gz: 25739a7c7e6ec24ccc0079966116c9e2c6bf85011da0b17e4a308407ce1d44332416a41258affeb86855239637175c1d593d949120b4b620d0cb14e576539c10
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ coverage/
1
2
  pkg/*
2
3
  .bundle
3
4
  Gemfile.lock
data/.overcommit.yml CHANGED
@@ -5,7 +5,7 @@ PreCommit:
5
5
  HardTabs:
6
6
  enabled: true
7
7
 
8
- Rubocop:
8
+ RuboCop:
9
9
  enabled: true
10
10
  command: ['bundle', 'exec', 'rubocop']
11
11
 
data/.rubocop.yml ADDED
@@ -0,0 +1,91 @@
1
+ Lint/AssignmentInCondition:
2
+ Enabled: false
3
+
4
+ # We use this a lot in specs where it's perfectly valid
5
+ Lint/Void:
6
+ Exclude:
7
+ - spec/**/*
8
+
9
+ Metrics/AbcSize:
10
+ Enabled: false
11
+
12
+ Metrics/CyclomaticComplexity:
13
+ Enabled: false
14
+
15
+ Metrics/ClassLength:
16
+ Enabled: false
17
+
18
+ Metrics/LineLength:
19
+ Max: 100
20
+
21
+ Metrics/MethodLength:
22
+ Enabled: false
23
+
24
+ Metrics/ModuleLength:
25
+ Enabled: false
26
+
27
+ Metrics/PerceivedComplexity:
28
+ Enabled: false
29
+
30
+ Style/AlignParameters:
31
+ Enabled: false
32
+
33
+ Style/Documentation:
34
+ Enabled: false
35
+
36
+ Style/DotPosition:
37
+ Enabled: false
38
+
39
+ Style/DoubleNegation:
40
+ Enabled: false
41
+
42
+ Style/GuardClause:
43
+ Enabled: false
44
+
45
+ Style/HashSyntax:
46
+ Enabled: false
47
+
48
+ Style/IfUnlessModifier:
49
+ Enabled: false
50
+
51
+ Style/Lambda:
52
+ Enabled: false
53
+
54
+ Style/MultilineBlockChain:
55
+ Enabled: false
56
+
57
+ # Prefer curly braces except for %i/%w/%W, since those return arrays.
58
+ Style/PercentLiteralDelimiters:
59
+ PreferredDelimiters:
60
+ '%': '{}'
61
+ '%i': '[]'
62
+ '%q': '{}'
63
+ '%Q': '{}'
64
+ '%r': '{}'
65
+ '%s': '()'
66
+ '%w': '[]'
67
+ '%W': '[]'
68
+ '%x': '{}'
69
+
70
+ Style/PerlBackrefs:
71
+ Enabled: false
72
+
73
+ # This hides the has-a versus is-a relationship indicated by the method name
74
+ Style/PredicateName:
75
+ Enabled: false
76
+
77
+ Style/RescueModifier:
78
+ Enabled: false
79
+
80
+ Style/SignalException:
81
+ Enabled: false
82
+
83
+ Style/SingleLineBlockParams:
84
+ Enabled: false
85
+
86
+ # End last item of a muli-line list with a comma for better diffs in future
87
+ Style/TrailingComma:
88
+ EnforcedStyleForMultiline: comma
89
+
90
+ Style/WhenThen:
91
+ Enabled: false
data/.simplecov ADDED
@@ -0,0 +1,4 @@
1
+ SimpleCov.start do
2
+ add_filter '/bin/'
3
+ add_filter '/spec/'
4
+ end
data/.travis.yml CHANGED
@@ -1,14 +1,26 @@
1
1
  language: ruby
2
+
3
+ sudo: false
4
+
5
+ cache: bundler
6
+
2
7
  services:
3
8
  - redis-server
9
+
4
10
  rvm:
5
11
  - 1.9.3
6
- - 2.0.0
7
- - 2.1.1
12
+ - 2.0
13
+ - 2.1
14
+ - 2.2
8
15
  - jruby-19mode
9
16
 
17
+ before_script:
18
+ - git config --local user.email "travis@travis.ci"
19
+ - git config --local user.name "Travis CI"
20
+
10
21
  script:
11
22
  - bundle exec rspec
23
+ - bundle exec overcommit --run
12
24
 
13
25
  matrix:
14
26
  allow_failures:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # MockRedis Changelog
2
2
 
3
+ ### 0.15.0
4
+
5
+ * Add support for the `time` method
6
+
3
7
  ### 0.14.1
4
8
 
5
9
  * Upgrade `redis` gem dependency to 3.2.x series
data/Gemfile CHANGED
@@ -4,8 +4,10 @@ source 'http://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  # Run all pre-commit hooks via Overcommit during CI runs
7
- gem 'overcommit', '0.24.0'
7
+ gem 'overcommit', '0.26.0'
8
8
 
9
9
  # Pin tool versions (which are executed by Overcommit) for Travis builds
10
- gem 'rubocop', '0.30.0'
10
+ gem 'rubocop', '0.32.1'
11
11
  gem 'travis', '~> 1.7'
12
+
13
+ gem 'coveralls', require: false
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/mock_redis.svg)](http://badge.fury.io/rb/mock_redis)
4
4
  [![Build Status](https://travis-ci.org/brigade/mock_redis.svg)](https://travis-ci.org/brigade/mock_redis)
5
+ [![Coverage Status](https://coveralls.io/repos/brigade/mock_redis/badge.svg)](https://coveralls.io/r/brigade/mock_redis)
5
6
  [![Dependency Status](https://gemnasium.com/brigade/mock_redis.svg)](https://gemnasium.com/brigade/mock_redis)
6
7
 
7
8
  MockRedis provides the same interface as `redis-rb`, but it stores its
data/Rakefile CHANGED
@@ -3,8 +3,8 @@ Bundler::GemHelper.install_tasks
3
3
 
4
4
  require 'rspec/core/rake_task'
5
5
  RSpec::Core::RakeTask.new(:spec) do |t|
6
- t.rspec_opts = %w(-fs --color)
7
- t.pattern = "spec/**/*_spec.rb"
6
+ t.rspec_opts = %w[-fs --color]
7
+ t.pattern = 'spec/**/*_spec.rb'
8
8
  end
9
9
 
10
10
  task :default => :spec
data/lib/mock_redis.rb CHANGED
@@ -15,14 +15,14 @@ class MockRedis
15
15
  attr_reader :options
16
16
 
17
17
  DEFAULTS = {
18
- :scheme => "redis",
19
- :host => "127.0.0.1",
20
- :port => 6379,
21
- :path => nil,
22
- :timeout => 5.0,
23
- :password => nil,
24
- :db => 0,
25
- :time_class => Time,
18
+ :scheme => 'redis',
19
+ :host => '127.0.0.1',
20
+ :port => 6379,
21
+ :path => nil,
22
+ :timeout => 5.0,
23
+ :password => nil,
24
+ :db => 0,
25
+ :time_class => Time,
26
26
  }
27
27
 
28
28
  def self.connect(*args)
@@ -36,36 +36,37 @@ class MockRedis
36
36
  TransactionWrapper.new(
37
37
  ExpireWrapper.new(
38
38
  MultiDbWrapper.new(
39
- Database.new(self, *args)))))
39
+ Database.new(self, *args)))))
40
40
  end
41
41
 
42
42
  def id
43
- "redis://#{self.host}:#{self.port}/#{self.db}"
43
+ "redis://#{host}:#{port}/#{db}"
44
44
  end
45
- alias :location :id
45
+ alias_method :location, :id
46
46
 
47
- def call(command, &block)
48
- self.send(*command)
47
+ def call(command, &_block)
48
+ send(*command)
49
49
  end
50
50
 
51
51
  def host
52
- self.options[:host]
52
+ options[:host]
53
53
  end
54
54
 
55
55
  def port
56
- self.options[:port]
56
+ options[:port]
57
57
  end
58
58
 
59
59
  def db
60
- self.options[:db]
60
+ options[:db]
61
61
  end
62
62
 
63
63
  def now
64
- self.options[:time_class].now
64
+ options[:time_class].now
65
65
  end
66
+ alias_method :time, :now
66
67
 
67
68
  def time_at(timestamp)
68
- self.options[:time_class].at(timestamp)
69
+ options[:time_class].at(timestamp)
69
70
  end
70
71
 
71
72
  def client
@@ -80,7 +81,7 @@ class MockRedis
80
81
  self
81
82
  end
82
83
 
83
- def respond_to?(method, include_private=false)
84
+ def respond_to?(method, include_private = false)
84
85
  super || @db.respond_to?(method, include_private)
85
86
  end
86
87
 
@@ -93,7 +94,6 @@ class MockRedis
93
94
  @db = @db.clone
94
95
  end
95
96
 
96
-
97
97
  protected
98
98
 
99
99
  def _parse_options(options)
@@ -101,19 +101,19 @@ class MockRedis
101
101
 
102
102
  defaults = DEFAULTS.dup
103
103
 
104
- url = options[:url] || ENV["REDIS_URL"]
104
+ url = options[:url] || ENV['REDIS_URL']
105
105
 
106
106
  # Override defaults from URL if given
107
107
  if url
108
- require "uri"
108
+ require 'uri'
109
109
 
110
110
  uri = URI(url)
111
111
 
112
- if uri.scheme == "unix"
112
+ if uri.scheme == 'unix'
113
113
  defaults[:path] = uri.path
114
114
  else
115
115
  # Require the URL to have at least a host
116
- raise ArgumentError, "invalid url" unless uri.host
116
+ raise ArgumentError, 'invalid url' unless uri.host
117
117
 
118
118
  defaults[:scheme] = uri.scheme
119
119
  defaults[:host] = uri.host
@@ -126,7 +126,7 @@ class MockRedis
126
126
  options = defaults.merge(options)
127
127
 
128
128
  if options[:path]
129
- options[:scheme] = "unix"
129
+ options[:scheme] = 'unix'
130
130
  options.delete(:host)
131
131
  options.delete(:port)
132
132
  else
@@ -139,5 +139,4 @@ class MockRedis
139
139
 
140
140
  options
141
141
  end
142
-
143
142
  end
@@ -8,6 +8,5 @@ class MockRedis
8
8
  "ERR wrong number of arguments for '#{command}' command"
9
9
  end
10
10
  end
11
-
12
11
  end
13
12
  end
@@ -21,25 +21,31 @@ class MockRedis
21
21
 
22
22
  attr_reader :data, :expire_times
23
23
 
24
- def initialize(base, *args)
24
+ def initialize(base, *_args)
25
25
  @base = base
26
26
  @data = MockRedis::IndifferentHash.new
27
27
  @expire_times = []
28
28
  end
29
29
 
30
- def initialize_copy(source)
30
+ def initialize_copy(_source)
31
31
  @data = @data.clone
32
- @data.keys.each {|k| @data[k] = @data[k].clone}
33
- @expire_times = @expire_times.map{|x| x.clone}
32
+ @data.keys.each { |k| @data[k] = @data[k].clone }
33
+ @expire_times = @expire_times.map(&:clone)
34
34
  end
35
35
 
36
36
  # Redis commands go below this line and above 'private'
37
37
 
38
- def auth(_) 'OK' end
38
+ def auth(_)
39
+ 'OK'
40
+ end
39
41
 
40
- def bgrewriteaof() "Background append only file rewriting started" end
42
+ def bgrewriteaof
43
+ 'Background append only file rewriting started'
44
+ end
41
45
 
42
- def bgsave() "Background saving started" end
46
+ def bgsave
47
+ 'Background saving started'
48
+ end
43
49
 
44
50
  def disconnect
45
51
  nil
@@ -58,9 +64,9 @@ class MockRedis
58
64
  assert_has_args(keys, 'del')
59
65
 
60
66
  keys.
61
- find_all{|key| data[key]}.
62
- each {|k| persist(k)}.
63
- each {|k| data.delete(k)}.
67
+ find_all { |key| data[key] }.
68
+ each { |k| persist(k) }.
69
+ each { |k| data.delete(k) }.
64
70
  length
65
71
  end
66
72
 
@@ -79,7 +85,7 @@ class MockRedis
79
85
 
80
86
  def expireat(key, timestamp)
81
87
  unless looks_like_integer?(timestamp.to_s)
82
- raise Redis::CommandError, "ERR value is not an integer or out of range"
88
+ raise Redis::CommandError, 'ERR value is not an integer or out of range'
83
89
  end
84
90
 
85
91
  pexpireat(key, timestamp.to_i * 1000)
@@ -87,7 +93,7 @@ class MockRedis
87
93
 
88
94
  def pexpireat(key, timestamp_ms)
89
95
  unless looks_like_integer?(timestamp_ms.to_s)
90
- raise Redis::CommandError, "ERR value is not an integer or out of range"
96
+ raise Redis::CommandError, 'ERR value is not an integer or out of range'
91
97
  end
92
98
 
93
99
  if exists(key)
@@ -100,11 +106,11 @@ class MockRedis
100
106
  end
101
107
 
102
108
  def exists(key)
103
- data.has_key?(key)
109
+ data.key?(key)
104
110
  end
105
111
 
106
112
  def flushdb
107
- data.keys.each {|k| del(k)}
113
+ data.keys.each { |k| del(k) }
108
114
  'OK'
109
115
  end
110
116
 
@@ -150,9 +156,9 @@ class MockRedis
150
156
 
151
157
  def rename(key, newkey)
152
158
  if !data.include?(key)
153
- raise Redis::CommandError, "ERR no such key"
159
+ raise Redis::CommandError, 'ERR no such key'
154
160
  elsif key == newkey
155
- raise Redis::CommandError, "ERR source and destination objects are the same"
161
+ raise Redis::CommandError, 'ERR source and destination objects are the same'
156
162
  end
157
163
  data[newkey] = data.delete(key)
158
164
  if has_expiration?(key)
@@ -164,9 +170,9 @@ class MockRedis
164
170
 
165
171
  def renamenx(key, newkey)
166
172
  if !data.include?(key)
167
- raise Redis::CommandError, "ERR no such key"
173
+ raise Redis::CommandError, 'ERR no such key'
168
174
  elsif key == newkey
169
- raise Redis::CommandError, "ERR source and destination objects are the same"
175
+ raise Redis::CommandError, 'ERR source and destination objects are the same'
170
176
  end
171
177
  if exists(newkey)
172
178
  false
@@ -222,9 +228,9 @@ class MockRedis
222
228
 
223
229
  def assert_valid_timeout(timeout)
224
230
  if !looks_like_integer?(timeout.to_s)
225
- raise Redis::CommandError, "ERR timeout is not an integer or out of range"
231
+ raise Redis::CommandError, 'ERR timeout is not an integer or out of range'
226
232
  elsif timeout < 0
227
- raise Redis::CommandError, "ERR timeout is negative"
233
+ raise Redis::CommandError, 'ERR timeout is negative'
228
234
  end
229
235
  timeout
230
236
  end
@@ -242,7 +248,7 @@ class MockRedis
242
248
  if options.is_a?(Hash) && options[:timeout]
243
249
  timeout = assert_valid_timeout(options[:timeout])
244
250
  [arglist[0..-2], timeout]
245
- elsif options.kind_of?(Integer)
251
+ elsif options.is_a?(Integer)
246
252
  timeout = assert_valid_timeout(options)
247
253
  [arglist[0..-2], timeout]
248
254
  else
@@ -251,11 +257,11 @@ class MockRedis
251
257
  end
252
258
 
253
259
  def expiration(key)
254
- expire_times.find {|(_,k)| k == key.to_s}.first
260
+ expire_times.find { |(_, k)| k == key.to_s }.first
255
261
  end
256
262
 
257
263
  def has_expiration?(key)
258
- expire_times.any? {|(_,k)| k == key.to_s}
264
+ expire_times.any? { |(_, k)| k == key.to_s }
259
265
  end
260
266
 
261
267
  def looks_like_integer?(str)
@@ -270,12 +276,12 @@ class MockRedis
270
276
  Regexp.new(
271
277
  "^#{pattern}$".
272
278
  gsub(/([+|()])/, '\\\\\1').
273
- gsub(/([^\\])\?/, "\\1.").
274
- gsub(/([^\\])\*/, "\\1.*"))
279
+ gsub(/([^\\])\?/, '\\1.').
280
+ gsub(/([^\\])\*/, '\\1.*'))
275
281
  end
276
282
 
277
283
  def remove_expiration(key)
278
- expire_times.delete_if do |(t, k)|
284
+ expire_times.delete_if do |(_t, k)|
279
285
  key.to_s == k
280
286
  end
281
287
  end
@@ -295,16 +301,17 @@ class MockRedis
295
301
  end
296
302
 
297
303
  public
304
+
298
305
  # This method isn't private, but it also isn't a Redis command, so
299
306
  # it doesn't belong up above with all the Redis commands.
300
307
  def expire_keys
301
308
  now = @base.now
302
309
 
303
- to_delete = expire_times.take_while do |(time, key)|
310
+ to_delete = expire_times.take_while do |(time, _key)|
304
311
  (time.to_r * 1_000).to_i <= (now.to_r * 1_000).to_i
305
312
  end
306
313
 
307
- to_delete.each do |(time, key)|
314
+ to_delete.each do |(_time, key)|
308
315
  del(key)
309
316
  end
310
317
  end