-
Notifications
You must be signed in to change notification settings - Fork 79
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
Add the smove method to Kredis::Types::Set #160
base: main
Are you sure you want to change the base?
Conversation
the Redis documentation currently supports the use of the `smove` method, this change make that method also available in kredis example: my_kredis_set.smove(another_kredis_set.key, value_to_move) use case: when using sets as queues for a multi step process it is helpful to move values between sets: queued -> issued issued -> completed issued -> failed & add back to queued for retying https://redis.io/docs/latest/commands/smove/
Add smove test coverage
Add 'smove' method to Kredis::Types::Set
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.
could add a wrapper method to make the method more semantic like remove
and include?
in this class
@@ -3,7 +3,7 @@ | |||
class Kredis::Types::Set < Kredis::Types::Proxying | |||
prepend Kredis::DefaultValues | |||
|
|||
proxying :smembers, :sadd, :srem, :multi, :del, :sismember, :scard, :spop, :exists?, :srandmember | |||
proxying :smembers, :sadd, :srem, :multi, :del, :sismember, :scard, :spop, :exists?, :srandmember, :smove | |||
|
|||
attr_accessor :typed | |||
|
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.
def move(set, member) | |
destination = set.respond_to?(:key) ? set.key : set | |
smove(destination, member) | |
end |
test "smove" do | ||
@set.add(%w[ 1 2 ]) | ||
another_set = Kredis.set "another_set" | ||
another_set.add(%w[ 3 ]) | ||
|
||
assert @set.smove(another_set.key, "2") | ||
assert_equal %w[ 1 ], @set.members | ||
assert_equal %w[ 2 3 ], another_set.members | ||
end |
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.
test "smove" do | |
@set.add(%w[ 1 2 ]) | |
another_set = Kredis.set "another_set" | |
another_set.add(%w[ 3 ]) | |
assert @set.smove(another_set.key, "2") | |
assert_equal %w[ 1 ], @set.members | |
assert_equal %w[ 2 3 ], another_set.members | |
end | |
test "smove" do | |
@set.add(%w[ 1 2 ]) | |
another_set = Kredis.set "another_set" | |
another_set.add(%w[ 3 ]) | |
assert @set.smove(another_set.key, "2") | |
assert_equal %w[ 1 ], @set.members | |
assert_equal %w[ 2 3 ], another_set.members | |
end | |
test "move with set" do | |
@set.add(%w[ x y ]) | |
another_set = Kredis.set "another_set" | |
another_set.add(%w[ z ]) | |
assert @set.move(another_set, "y") | |
assert_equal %w[ x ], @set.members | |
assert_equal %w[ y z ], another_set.members | |
end | |
test "move with key" do | |
@set.add(%w[ a b ]) | |
another_set = Kredis.set "another_set" | |
another_set.add(%w[ c ]) | |
assert @set.move(another_set.key, "b") | |
assert_equal %w[ a ], @set.members | |
assert_equal %w[ b c ], another_set.members | |
end |
Redis documentation currently supports the use of the
smove
method, this change makes that method available in Kredishttps://redis.io/docs/latest/commands/smove/