Class: Redis::Model::SetProxy

Inherits:
FieldProxy show all
Defined in:
lib/redis/model.rb

Overview

:nodoc:

Constant Summary collapse

COMMANDS =
{
  :intersect_store  => "sinterstore",
  :union_store      => "sunionstore",
  :diff_store       => "sdiffstore",
  :move             => "smove",
}

Instance Method Summary collapse

Methods inherited from FieldProxy

#initialize, #method_missing

Constructor Details

This class inherits a constructor from Redis::Model::FieldProxy

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Redis::Model::FieldProxy

Instance Method Details

#<<(v) ⇒ Object Also known as: add



320
321
322
# File 'lib/redis/model.rb', line 320

def <<(v)
  @redis.sadd @name, @marshal.dump(v)
end

#delete(v) ⇒ Object Also known as: remove



325
326
327
# File 'lib/redis/model.rb', line 325

def delete(v)
  @redis.srem @name, @marshal.dump(v)
end

#diff(*keys) ⇒ Object



348
349
350
# File 'lib/redis/model.rb', line 348

def diff(*keys)
  @redis.sdiff(@name, *keys).map { |v| @marshal.load(v) }
end

#include?(v) ⇒ Boolean Also known as: has_key?, member?

Returns:

  • (Boolean)


330
331
332
# File 'lib/redis/model.rb', line 330

def include?(v)
  @redis.sismember @name, @marshal.dump(v)
end

#intersect(*keys) ⇒ Object



340
341
342
# File 'lib/redis/model.rb', line 340

def intersect(*keys)
  @redis.sinter(@name, *keys).map { |v| @marshal.load(v) }
end

#lengthObject



352
353
354
# File 'lib/redis/model.rb', line 352

def length
  @redis.llen(@name)
end

#membersObject



336
337
338
# File 'lib/redis/model.rb', line 336

def members
  @redis.smembers(@name).map { |v| @marshal.load(v) }
end

#to_sObject



356
357
358
# File 'lib/redis/model.rb', line 356

def to_s
  members.join(', ')
end

#union(*keys) ⇒ Object



344
345
346
# File 'lib/redis/model.rb', line 344

def union(*keys)
  @redis.sunion(@name, *keys).map { |v| @marshal.load(v) }
end