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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/kredis/types/set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions test/types/set_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ class SetTest < ActiveSupport::TestCase
assert_equal [ 1.5, 2.7 ], @set.sample(2).sort
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
Comment on lines +104 to +112
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


test "default" do
@set = Kredis.set "mylist", default: %w[ 1 2 3 ]
Expand Down
Loading