module RedisModel::Types::Set
Internal: Methods needed for Set
type.
Public Instance Methods
<<(value)
click to toggle source
Public: Pushes a element into the set using SADD command.
Returns true.
# File lib/redis_model/types/set.rb, line 26 def <<(value) connection.sadd key_label, value end
count()
click to toggle source
Public: Retrieves length of Redis set using SCARD command.
Returns Integer
containing cardinality of the set.
# File lib/redis_model/types/set.rb, line 17 def count connection.scard key_label end
Also aliased as: length
include?(value)
click to toggle source
Public: Asserts value is included in the set using SISMEMBER command.
Returns true if value is included in the set, false otherwise.
# File lib/redis_model/types/set.rb, line 54 def include?(value) connection.sismember key_label, value.to_s end
pick(count)
click to toggle source
Public: Picks a member among elements in the set using SRANDMEMBER command.
count - Number of elements to pick.
Returns Array containing elements in the set randomly selected.
# File lib/redis_model/types/set.rb, line 43 def pick(count) RedisModel::Base.connection.pipelined do count.times do connection.srandmember(key_label) end end end
remove(value)
click to toggle source
Public: Removes a element from the set using SREM command.
Returns true.
# File lib/redis_model/types/set.rb, line 33 def remove(value) connection.srem key_label, value end
to_a()
click to toggle source
Public: Fetches elements in Redis set as Array using SMEMBERS command.
Returns Array containing elements in the set.
# File lib/redis_model/types/set.rb, line 10 def to_a connection.smembers key_label end