Class: Blackbeard::RedisStore

Inherits:
Object
  • Object
show all
Defined in:
lib/blackbeard/redis_store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(r, namespace) ⇒ RedisStore

Returns a new instance of RedisStore.



8
9
10
11
# File 'lib/blackbeard/redis_store.rb', line 8

def initialize(r, namespace)
  r ||= Redis.new
  @redis = Redis::Namespace.new(namespace.to_sym, :redis => r)
end

Instance Attribute Details

#redisObject (readonly)

Returns the value of attribute redis.



6
7
8
# File 'lib/blackbeard/redis_store.rb', line 6

def redis
  @redis
end

Instance Method Details

#del(*keys) ⇒ Object

String commands



90
91
92
# File 'lib/blackbeard/redis_store.rb', line 90

def del(*keys)
  redis.del(*keys)
end

#get(key) ⇒ Object



102
103
104
# File 'lib/blackbeard/redis_store.rb', line 102

def get(key)
  redis.get(key)
end

#hash_field_exists(hash_key, field) ⇒ Object



60
61
62
# File 'lib/blackbeard/redis_store.rb', line 60

def hash_field_exists(hash_key, field)
  redis.hexists(hash_key, field)
end

#hash_get(hash_key, field) ⇒ Object



44
45
46
# File 'lib/blackbeard/redis_store.rb', line 44

def hash_get(hash_key, field)
  redis.hget(hash_key, field)
end

#hash_get_all(hash_key) ⇒ Object



48
49
50
# File 'lib/blackbeard/redis_store.rb', line 48

def hash_get_all(hash_key)
  redis.hgetall(hash_key)
end

#hash_increment_by(hash_key, field, int) ⇒ Object



52
53
54
# File 'lib/blackbeard/redis_store.rb', line 52

def hash_increment_by(hash_key, field, int)
  redis.hincrby(hash_key, field, int.to_i)
end

#hash_increment_by_float(hash_key, field, float) ⇒ Object



56
57
58
# File 'lib/blackbeard/redis_store.rb', line 56

def hash_increment_by_float(hash_key, field, float)
  redis.hincrbyfloat(hash_key, field, float.to_f)
end

#hash_key_set_if_not_exists(hash_key, field, value) ⇒ Object

Hash commands TODO: rename to hash_set_if_not_exisits



20
21
22
# File 'lib/blackbeard/redis_store.rb', line 20

def hash_key_set_if_not_exists(hash_key, field, value)
  redis.hsetnx(hash_key, field, value)
end

#hash_keys(hash_key) ⇒ Object



40
41
42
# File 'lib/blackbeard/redis_store.rb', line 40

def hash_keys(hash_key)
  redis.hkeys(hash_key)
end

#hash_length(hash_key) ⇒ Object



36
37
38
# File 'lib/blackbeard/redis_store.rb', line 36

def hash_length(hash_key)
  redis.hlen(hash_key)
end

#hash_multi_get(hash_key, *fields) ⇒ Object



32
33
34
# File 'lib/blackbeard/redis_store.rb', line 32

def hash_multi_get(hash_key, *fields)
  redis.hmget(hash_key, *fields) unless fields.empty?
end

#hash_multi_set(hash_key, hash) ⇒ Object



28
29
30
# File 'lib/blackbeard/redis_store.rb', line 28

def hash_multi_set(hash_key, hash)
  redis.mapped_hmset(hash_key, hash) unless hash.empty?
end

#hash_set(hash_key, field, value) ⇒ Object



24
25
26
# File 'lib/blackbeard/redis_store.rb', line 24

def hash_set(hash_key, field, value)
  redis.hset(hash_key, field, value)
end

#increment(key) ⇒ Object



98
99
100
# File 'lib/blackbeard/redis_store.rb', line 98

def increment(key)
  redis.incr(key)
end

#increment_by_float(key, float) ⇒ Object



94
95
96
# File 'lib/blackbeard/redis_store.rb', line 94

def increment_by_float(key, float)
  redis.incrbyfloat(key, float)
end

#keysObject



13
14
15
# File 'lib/blackbeard/redis_store.rb', line 13

def keys
  redis.keys
end

#multi_get(*keys) ⇒ Object



106
107
108
# File 'lib/blackbeard/redis_store.rb', line 106

def multi_get(*keys)
  redis.mget(*keys.flatten)
end

#set(key, value) ⇒ Object



110
111
112
# File 'lib/blackbeard/redis_store.rb', line 110

def set(key, value)
  redis.set(key, value)
end

#set_add_member(set_key, member) ⇒ Object



73
74
75
# File 'lib/blackbeard/redis_store.rb', line 73

def set_add_member(set_key, member)
  redis.sadd(set_key, member)
end

#set_add_members(set_key, *members) ⇒ Object



77
78
79
# File 'lib/blackbeard/redis_store.rb', line 77

def set_add_members(set_key, *members)
  redis.sadd(set_key, members.flatten)
end

#set_count(set_key) ⇒ Object



81
82
83
# File 'lib/blackbeard/redis_store.rb', line 81

def set_count(set_key)
  redis.scard(set_key)
end

#set_members(set_key) ⇒ Object

Set commands



65
66
67
# File 'lib/blackbeard/redis_store.rb', line 65

def set_members(set_key)
  redis.smembers(set_key)
end

#set_remove_member(set_key, member) ⇒ Object



69
70
71
# File 'lib/blackbeard/redis_store.rb', line 69

def set_remove_member(set_key, member)
  redis.srem(set_key, member)
end

#set_union_count(*keys) ⇒ Object



85
86
87
# File 'lib/blackbeard/redis_store.rb', line 85

def set_union_count(*keys)
  redis.sunionstore('set_union_count', keys.flatten)
end