mock_redis 0.40.0 → 0.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/mock_redis/database.rb +32 -11
- data/lib/mock_redis/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38600e39b89ea4f37c414a69fb7ed50e4915d0f723d2d7f50e11141b4f9f9e33
|
4
|
+
data.tar.gz: 5e2830a85a5dcf6326ed01c3cac52cf5c5136393dd79f979b9a197a79dd12c60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fcdf6c59782080a318f7915b918367aa7935f4de4dee130fac4bae158574e39685db1a81a598fae56d7c97a14e33c4b333c0e357375c45edd691c31bed20455
|
7
|
+
data.tar.gz: f0a336671d8a76ad0984604ad3f29ab231188442155de7968c1e0698489f5a02f3a012ab3ae3f38a8398c3d553cbc1ca68b9915514d6c5046ebede63a5c9e842
|
data/CHANGELOG.md
CHANGED
data/lib/mock_redis/database.rb
CHANGED
@@ -43,6 +43,9 @@ class MockRedis
|
|
43
43
|
|
44
44
|
# Redis commands go below this line and above 'private'
|
45
45
|
|
46
|
+
# FIXME: Current implementation of `call` does not work propetly with kwarg-options.
|
47
|
+
# i.e. `call("EXPIRE", "foo", 40, "NX")` (which redis-rb will simply transmit to redis-server)
|
48
|
+
# will be passed to `#expire` without keywords transformation.
|
46
49
|
def call(command, &_block)
|
47
50
|
public_send(command[0].downcase, *command[1..])
|
48
51
|
end
|
@@ -89,32 +92,42 @@ class MockRedis
|
|
89
92
|
msg.to_s
|
90
93
|
end
|
91
94
|
|
92
|
-
def expire(key, seconds)
|
95
|
+
def expire(key, seconds, nx: nil, xx: nil, lt: nil, gt: nil) # rubocop:disable Metrics/ParameterLists
|
93
96
|
assert_valid_integer(seconds)
|
94
97
|
|
95
|
-
pexpire(key, seconds.to_i * 1000)
|
98
|
+
pexpire(key, seconds.to_i * 1000, nx: nx, xx: xx, lt: lt, gt: gt)
|
96
99
|
end
|
97
100
|
|
98
|
-
def pexpire(key, ms)
|
101
|
+
def pexpire(key, ms, nx: nil, xx: nil, lt: nil, gt: nil) # rubocop:disable Metrics/ParameterLists
|
99
102
|
assert_valid_integer(ms)
|
100
103
|
|
101
104
|
now, miliseconds = @base.now
|
102
105
|
now_ms = (now * 1000) + miliseconds
|
103
|
-
pexpireat(key, now_ms + ms.to_i)
|
106
|
+
pexpireat(key, now_ms + ms.to_i, nx: nx, xx: xx, lt: lt, gt: gt)
|
104
107
|
end
|
105
108
|
|
106
|
-
def expireat(key, timestamp)
|
109
|
+
def expireat(key, timestamp, nx: nil, xx: nil, lt: nil, gt: nil) # rubocop:disable Metrics/ParameterLists
|
107
110
|
assert_valid_integer(timestamp)
|
108
111
|
|
109
|
-
pexpireat(key, timestamp.to_i * 1000)
|
112
|
+
pexpireat(key, timestamp.to_i * 1000, nx: nx, xx: xx, lt: lt, gt: gt)
|
110
113
|
end
|
111
114
|
|
112
|
-
def pexpireat(key, timestamp_ms)
|
115
|
+
def pexpireat(key, timestamp_ms, nx: nil, xx: nil, lt: nil, gt: nil) # rubocop:disable Metrics/ParameterLists
|
113
116
|
assert_valid_integer(timestamp_ms)
|
114
117
|
|
115
|
-
if
|
116
|
-
|
117
|
-
|
118
|
+
if nx && gt || gt && lt || lt && nx || nx && xx
|
119
|
+
raise Redis::CommandError, <<~TXT.chomp
|
120
|
+
ERR NX and XX, GT or LT options at the same time are not compatible
|
121
|
+
TXT
|
122
|
+
end
|
123
|
+
|
124
|
+
return false unless exists?(key)
|
125
|
+
|
126
|
+
expiry = expiration(key)
|
127
|
+
new_expiry = @base.time_at(Rational(timestamp_ms.to_i, 1000))
|
128
|
+
|
129
|
+
if should_update_expiration?(expiry, new_expiry, nx: nx, xx: xx, lt: lt, gt: gt)
|
130
|
+
set_expiration(key, new_expiry)
|
118
131
|
true
|
119
132
|
else
|
120
133
|
false
|
@@ -324,7 +337,7 @@ class MockRedis
|
|
324
337
|
end
|
325
338
|
|
326
339
|
def expiration(key)
|
327
|
-
expire_times.find { |(_, k)| k == key.to_s }
|
340
|
+
expire_times.find { |(_, k)| k == key.to_s }&.first
|
328
341
|
end
|
329
342
|
|
330
343
|
def has_expiration?(key)
|
@@ -339,6 +352,14 @@ class MockRedis
|
|
339
352
|
!!Float(str) rescue false
|
340
353
|
end
|
341
354
|
|
355
|
+
def should_update_expiration?(expiry, new_expiry, nx:, xx:, lt:, gt:) # rubocop:disable Metrics/ParameterLists
|
356
|
+
return false if nx && expiry || xx && !expiry
|
357
|
+
return false if lt && expiry && new_expiry > expiry
|
358
|
+
return false if gt && (!expiry || new_expiry < expiry)
|
359
|
+
|
360
|
+
true
|
361
|
+
end
|
362
|
+
|
342
363
|
def redis_pattern_to_ruby_regex(pattern)
|
343
364
|
Regexp.new(
|
344
365
|
"^#{pattern}$".
|
data/lib/mock_redis/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mock_redis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.41.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane da Silva
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-
|
12
|
+
date: 2023-12-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -123,10 +123,10 @@ licenses:
|
|
123
123
|
- MIT
|
124
124
|
metadata:
|
125
125
|
bug_tracker_uri: https://github.com/sds/mock_redis/issues
|
126
|
-
changelog_uri: https://github.com/sds/mock_redis/blob/v0.
|
127
|
-
documentation_uri: https://www.rubydoc.info/gems/mock_redis/0.
|
126
|
+
changelog_uri: https://github.com/sds/mock_redis/blob/v0.41.0/CHANGELOG.md
|
127
|
+
documentation_uri: https://www.rubydoc.info/gems/mock_redis/0.41.0
|
128
128
|
homepage_uri: https://github.com/sds/mock_redis
|
129
|
-
source_code_uri: https://github.com/sds/mock_redis/tree/v0.
|
129
|
+
source_code_uri: https://github.com/sds/mock_redis/tree/v0.41.0
|
130
130
|
post_install_message:
|
131
131
|
rdoc_options: []
|
132
132
|
require_paths:
|