Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

CoderMiguel
Copy link

Redis documentation currently supports the use of the smove method, this change makes that method available in Kredis

https://redis.io/docs/latest/commands/smove/

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' method to Kredis::Types::Set
Copy link
Author

@CoderMiguel CoderMiguel left a 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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def move(set, member)
destination = set.respond_to?(:key) ? set.key : set
smove(destination, member)
end

Comment on lines +104 to +112
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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant