Skip to content

Commit

Permalink
Adds include? to ordered set (#126)
Browse files Browse the repository at this point in the history
* adds include? to ordered set

* check only if element is included

* remove not needed assertion

* Update lib/kredis/types/ordered_set.rb

Co-authored-by: Lewis Buckley <[email protected]>

* add zscore to proxying

---------

Co-authored-by: Lewis Buckley <[email protected]>
  • Loading branch information
EduardoAntequera and lewispb authored Oct 19, 2023
1 parent d8809ad commit b907559
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/kredis/types/ordered_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Kredis::Types::OrderedSet < Kredis::Types::Proxying
prepend Kredis::DefaultValues

proxying :multi, :zrange, :zrem, :zadd, :zremrangebyrank, :zcard, :exists?, :del
proxying :multi, :zrange, :zrem, :zadd, :zremrangebyrank, :zcard, :exists?, :del, :zscore

attr_accessor :typed
attr_reader :limit
Expand All @@ -17,6 +17,10 @@ def remove(*elements)
zrem(types_to_strings(elements, typed))
end

def include?(element)
!!zscore(type_to_string(element, typed))
end

def prepend(elements)
insert(elements, prepending: true)
end
Expand Down
7 changes: 7 additions & 0 deletions test/types/ordered_set_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ class OrderedSetTest < ActiveSupport::TestCase
assert @set.exists?
end

test "include?" do
@set.append(%w[ 1 2 3 4 5 ])

assert @set.include?(1)
assert_not @set.include?(6)
end

test "appending over limit" do
@set.append(%w[ 1 2 3 4 5 ])
@set.append(%w[ 6 7 8 ])
Expand Down

0 comments on commit b907559

Please sign in to comment.