Class: RedisObj::Base

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/redis_obj/base.rb

Direct Known Subclasses

Hash, List, Set, SortedSet

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(redis, key = nil) ⇒ Base

Returns a new instance of Base.



4
5
6
7
8
9
10
11
# File 'lib/redis_obj/base.rb', line 4

def initialize redis, key=nil
  unless key
    key = redis
    redis = RedisObj.redis
  end
  @key = key
  @redis = redis
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



3
4
5
# File 'lib/redis_obj/base.rb', line 3

def key
  @key
end

#redisObject

Returns the value of attribute redis.



3
4
5
# File 'lib/redis_obj/base.rb', line 3

def redis
  @redis
end

Instance Method Details

#==(other) ⇒ Object



13
14
15
# File 'lib/redis_obj/base.rb', line 13

def == other
  self.class == other.class and self.key == other.key
end

#clearObject



21
22
23
# File 'lib/redis_obj/base.rb', line 21

def clear
  redis.del(key)
end

#del_keyObject



17
18
19
# File 'lib/redis_obj/base.rb', line 17

def del_key
  redis.del(key)
end

#get_keys(keys) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/redis_obj/base.rb', line 25

def get_keys(keys)
  keys = keys.flatten
  if keys.first.respond_to?(:key)
    keys.collect(&:key)
  else
    keys
  end
end