diff --git a/lib/kredis/types/ordered_set.rb b/lib/kredis/types/ordered_set.rb index 52a408d..49e0a78 100644 --- a/lib/kredis/types/ordered_set.rb +++ b/lib/kredis/types/ordered_set.rb @@ -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 @@ -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 diff --git a/test/types/ordered_set_test.rb b/test/types/ordered_set_test.rb index baad280..e1d9f73 100644 --- a/test/types/ordered_set_test.rb +++ b/test/types/ordered_set_test.rb @@ -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 ])