-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Redis-rb v5 #314
Merged
Merged
Support Redis-rb v5 #314
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,32 +95,33 @@ def echo(msg) | |
end | ||
|
||
def expire(key, seconds, nx: nil, xx: nil, lt: nil, gt: nil) # rubocop:disable Metrics/ParameterLists | ||
assert_valid_integer(seconds) | ||
seconds = Integer(seconds) | ||
|
||
pexpire(key, seconds.to_i * 1000, nx: nx, xx: xx, lt: lt, gt: gt) | ||
end | ||
|
||
def pexpire(key, ms, nx: nil, xx: nil, lt: nil, gt: nil) # rubocop:disable Metrics/ParameterLists | ||
assert_valid_integer(ms) | ||
ms = Integer(ms) | ||
|
||
now, miliseconds = @base.now | ||
now_ms = (now * 1000) + miliseconds | ||
pexpireat(key, now_ms + ms.to_i, nx: nx, xx: xx, lt: lt, gt: gt) | ||
end | ||
|
||
def expireat(key, timestamp, nx: nil, xx: nil, lt: nil, gt: nil) # rubocop:disable Metrics/ParameterLists | ||
assert_valid_integer(timestamp) | ||
timestamp = Integer(timestamp) | ||
|
||
pexpireat(key, timestamp.to_i * 1000, nx: nx, xx: xx, lt: lt, gt: gt) | ||
end | ||
|
||
def pexpireat(key, timestamp_ms, nx: nil, xx: nil, lt: nil, gt: nil) # rubocop:disable Metrics/ParameterLists | ||
assert_valid_integer(timestamp_ms) | ||
timestamp_ms = Integer(timestamp_ms) | ||
|
||
if nx && gt || gt && lt || lt && nx || nx && xx | ||
raise Redis::CommandError, <<~TXT.chomp | ||
ERR NX and XX, GT or LT options at the same time are not compatible | ||
TXT | ||
raise Error.command_error( | ||
'ERR NX and XX, GT or LT options at the same time are not compatible', | ||
self | ||
) | ||
end | ||
|
||
return false unless exists?(key) | ||
|
@@ -157,7 +158,7 @@ def dump(key) | |
|
||
def restore(key, ttl, value, replace: false) | ||
if !replace && exists?(key) | ||
raise Redis::CommandError, 'BUSYKEY Target key name already exists.' | ||
raise Error.command_error('BUSYKEY Target key name already exists.', self) | ||
Comment on lines
-160
to
+161
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change is tested only with |
||
end | ||
data[key] = Marshal.load(value) # rubocop:disable Security/MarshalLoad | ||
if ttl > 0 | ||
|
@@ -211,7 +212,7 @@ def randomkey | |
|
||
def rename(key, newkey) | ||
unless data.include?(key) | ||
raise Redis::CommandError, 'ERR no such key' | ||
raise Error.command_error('ERR no such key', self) | ||
end | ||
|
||
if key != newkey | ||
|
@@ -227,7 +228,7 @@ def rename(key, newkey) | |
|
||
def renamenx(key, newkey) | ||
unless data.include?(key) | ||
raise Redis::CommandError, 'ERR no such key' | ||
raise Error.command_error('ERR no such key', self) | ||
end | ||
|
||
if exists?(newkey) | ||
|
@@ -301,19 +302,13 @@ def eval(*args); end | |
|
||
private | ||
|
||
def assert_valid_integer(integer) | ||
unless looks_like_integer?(integer.to_s) | ||
raise Redis::CommandError, 'ERR value is not an integer or out of range' | ||
end | ||
integer | ||
end | ||
|
||
def assert_valid_timeout(timeout) | ||
if !looks_like_integer?(timeout.to_s) | ||
raise Redis::CommandError, 'ERR timeout is not an integer or out of range' | ||
elsif timeout < 0 | ||
raise Redis::CommandError, 'ERR timeout is negative' | ||
timeout = Integer(timeout) | ||
|
||
if timeout < 0 | ||
raise ArgumentError, 'time interval must not be negative' | ||
end | ||
|
||
timeout | ||
end | ||
|
||
|
@@ -347,7 +342,7 @@ def has_expiration?(key) | |
end | ||
|
||
def looks_like_integer?(str) | ||
str =~ /^-?\d+$/ | ||
!!Integer(str) rescue false | ||
end | ||
|
||
def looks_like_float?(str) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class MockRedis | ||
module Error | ||
module_function | ||
|
||
def build(error_class, message, database) | ||
connection = database.connection | ||
url = "redis://#{connection[:host]}:#{connection[:port]}" | ||
error_class.new("#{message} (#{url})") | ||
end | ||
|
||
def wrong_type_error(database) | ||
build( | ||
Redis::WrongTypeError, | ||
'WRONGTYPE Operation against a key holding the wrong kind of value', | ||
database | ||
) | ||
end | ||
|
||
def syntax_error(database) | ||
command_error('ERR syntax error', database) | ||
end | ||
|
||
def command_error(message, database) | ||
build(Redis::CommandError, message, database) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes mimic how
redis-rb
handles the number conversion