-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is an attempt to fix #281. This PR was also tested using the test suite of our service. There are a few decisions I made regarding this PR, please let me know if it's not appropriate: 1. Error from Redis now contains the redis connection URL - To fix this, I created `MockRedis::Error` module which decorate `Redis::CommandError` and related errors with the connection URL - I replace most of the `Redis::CommandError` with the new module wrapper 2. Some methods now return integer as output instead of boolean and `exists_returns_integer` is removed - I replace the output as is 3. Interfaces of most data structures (Hash, Set, ...) now validate type to be 4 main primitive types - `assert_type` is added to validate the arguments. Currently it doesn't look very clean, so any improvements would be great. 4. `sadd`, `srem` now support multiple arguments 5. Transaction: `multi` now needs to call with a block and `discard`/`exec` cannot be called outside that block anymore - I tried to refactor the logic to make the tests pass, but I'm not entirely confident that it works correctly
- Loading branch information
Showing
63 changed files
with
415 additions
and
269 deletions.
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
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.