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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01d1bfd5cf966db9fd2883757cb12f2c59f09d57
|
4
|
+
data.tar.gz: 80260a25e033a419eac875729b5e04be332b819f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33c9fde7412bf24e0180010c048fb80265e98b620d445765377f590286240063b5fd018cc6398d989f74084eccfaebe5c4333ad8f51db8af4c2dab9eb7d04136
|
7
|
+
data.tar.gz: 25739a7c7e6ec24ccc0079966116c9e2c6bf85011da0b17e4a308407ce1d44332416a41258affeb86855239637175c1d593d949120b4b620d0cb14e576539c10
|
data/.gitignore
CHANGED
data/.overcommit.yml
CHANGED
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
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
|
7
|
-
- 2.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
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.
|
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.
|
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
|
7
|
-
t.pattern =
|
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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
|
39
|
+
Database.new(self, *args)))))
|
40
40
|
end
|
41
41
|
|
42
42
|
def id
|
43
|
-
"redis://#{
|
43
|
+
"redis://#{host}:#{port}/#{db}"
|
44
44
|
end
|
45
|
-
|
45
|
+
alias_method :location, :id
|
46
46
|
|
47
|
-
def call(command, &
|
48
|
-
|
47
|
+
def call(command, &_block)
|
48
|
+
send(*command)
|
49
49
|
end
|
50
50
|
|
51
51
|
def host
|
52
|
-
|
52
|
+
options[:host]
|
53
53
|
end
|
54
54
|
|
55
55
|
def port
|
56
|
-
|
56
|
+
options[:port]
|
57
57
|
end
|
58
58
|
|
59
59
|
def db
|
60
|
-
|
60
|
+
options[:db]
|
61
61
|
end
|
62
62
|
|
63
63
|
def now
|
64
|
-
|
64
|
+
options[:time_class].now
|
65
65
|
end
|
66
|
+
alias_method :time, :now
|
66
67
|
|
67
68
|
def time_at(timestamp)
|
68
|
-
|
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[
|
104
|
+
url = options[:url] || ENV['REDIS_URL']
|
105
105
|
|
106
106
|
# Override defaults from URL if given
|
107
107
|
if url
|
108
|
-
require
|
108
|
+
require 'uri'
|
109
109
|
|
110
110
|
uri = URI(url)
|
111
111
|
|
112
|
-
if uri.scheme ==
|
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,
|
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] =
|
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
|
data/lib/mock_redis/database.rb
CHANGED
@@ -21,25 +21,31 @@ class MockRedis
|
|
21
21
|
|
22
22
|
attr_reader :data, :expire_times
|
23
23
|
|
24
|
-
def initialize(base, *
|
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(
|
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
|
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(_)
|
38
|
+
def auth(_)
|
39
|
+
'OK'
|
40
|
+
end
|
39
41
|
|
40
|
-
def bgrewriteaof
|
42
|
+
def bgrewriteaof
|
43
|
+
'Background append only file rewriting started'
|
44
|
+
end
|
41
45
|
|
42
|
-
def bgsave
|
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,
|
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,
|
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.
|
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,
|
159
|
+
raise Redis::CommandError, 'ERR no such key'
|
154
160
|
elsif key == newkey
|
155
|
-
raise Redis::CommandError,
|
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,
|
173
|
+
raise Redis::CommandError, 'ERR no such key'
|
168
174
|
elsif key == newkey
|
169
|
-
raise Redis::CommandError,
|
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,
|
231
|
+
raise Redis::CommandError, 'ERR timeout is not an integer or out of range'
|
226
232
|
elsif timeout < 0
|
227
|
-
raise Redis::CommandError,
|
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.
|
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(/([^\\])\?/,
|
274
|
-
gsub(/([^\\])\*/,
|
279
|
+
gsub(/([^\\])\?/, '\\1.').
|
280
|
+
gsub(/([^\\])\*/, '\\1.*'))
|
275
281
|
end
|
276
282
|
|
277
283
|
def remove_expiration(key)
|
278
|
-
expire_times.delete_if do |(
|
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,
|
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 |(
|
314
|
+
to_delete.each do |(_time, key)|
|
308
315
|
del(key)
|
309
316
|
end
|
310
317
|
end
|