Class: Blackbeard::RedisStore
- Inherits:
-
Object
- Object
- Blackbeard::RedisStore
- Defined in:
- lib/blackbeard/redis_store.rb
Instance Attribute Summary collapse
-
#redis ⇒ Object
readonly
Returns the value of attribute redis.
Instance Method Summary collapse
-
#del(*keys) ⇒ Object
String commands.
- #get(key) ⇒ Object
- #hash_field_exists(hash_key, field) ⇒ Object
- #hash_get(hash_key, field) ⇒ Object
- #hash_get_all(hash_key) ⇒ Object
- #hash_increment_by_float(hash_key, field, float) ⇒ Object
-
#hash_key_set_if_not_exists(hash_key, field, value) ⇒ Object
Hash commands.
- #hash_keys(hash_key) ⇒ Object
- #hash_length(hash_key) ⇒ Object
- #hash_multi_set(hash_key, hash) ⇒ Object
- #hash_set(hash_key, field, value) ⇒ Object
- #increment(key) ⇒ Object
- #increment_by_float(key, float) ⇒ Object
-
#initialize(r, namespace) ⇒ RedisStore
constructor
A new instance of RedisStore.
- #keys ⇒ Object
- #multi_get(*keys) ⇒ Object
- #set(key, value) ⇒ Object
- #set_add_member(set_key, member) ⇒ Object
- #set_add_members(set_key, *members) ⇒ Object
- #set_count(set_key) ⇒ Object
-
#set_members(set_key) ⇒ Object
Set commands.
- #set_remove_member(set_key, member) ⇒ Object
- #set_union_count(*keys) ⇒ Object
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
#redis ⇒ Object (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
81 82 83 |
# File 'lib/blackbeard/redis_store.rb', line 81 def del(*keys) redis.del(*keys) end |
#get(key) ⇒ Object
93 94 95 |
# File 'lib/blackbeard/redis_store.rb', line 93 def get(key) redis.get(key) end |
#hash_field_exists(hash_key, field) ⇒ Object
51 52 53 |
# File 'lib/blackbeard/redis_store.rb', line 51 def hash_field_exists(hash_key, field) redis.hexists(hash_key, field) end |
#hash_get(hash_key, field) ⇒ Object
39 40 41 |
# File 'lib/blackbeard/redis_store.rb', line 39 def hash_get(hash_key, field) redis.hget(hash_key, field) end |
#hash_get_all(hash_key) ⇒ Object
43 44 45 |
# File 'lib/blackbeard/redis_store.rb', line 43 def hash_get_all(hash_key) redis.hgetall(hash_key) end |
#hash_increment_by_float(hash_key, field, float) ⇒ Object
47 48 49 |
# File 'lib/blackbeard/redis_store.rb', line 47 def hash_increment_by_float(hash_key, field, float) redis.hincrbyfloat(hash_key, field, float) end |
#hash_key_set_if_not_exists(hash_key, field, value) ⇒ Object
Hash commands
19 20 21 |
# File 'lib/blackbeard/redis_store.rb', line 19 def hash_key_set_if_not_exists(hash_key, field, value) redis.hsetnx(hash_key, field, value) end |
#hash_keys(hash_key) ⇒ Object
35 36 37 |
# File 'lib/blackbeard/redis_store.rb', line 35 def hash_keys(hash_key) redis.hkeys(hash_key) end |
#hash_length(hash_key) ⇒ Object
31 32 33 |
# File 'lib/blackbeard/redis_store.rb', line 31 def hash_length(hash_key) redis.hlen(hash_key) end |
#hash_multi_set(hash_key, hash) ⇒ Object
27 28 29 |
# File 'lib/blackbeard/redis_store.rb', line 27 def hash_multi_set(hash_key, hash) redis.mapped_hmset(hash_key, hash) unless hash.empty? end |
#hash_set(hash_key, field, value) ⇒ Object
23 24 25 |
# File 'lib/blackbeard/redis_store.rb', line 23 def hash_set(hash_key, field, value) redis.hset(hash_key, field, value) end |
#increment(key) ⇒ Object
89 90 91 |
# File 'lib/blackbeard/redis_store.rb', line 89 def increment(key) redis.incr(key) end |
#increment_by_float(key, float) ⇒ Object
85 86 87 |
# File 'lib/blackbeard/redis_store.rb', line 85 def increment_by_float(key, float) redis.incrbyfloat(key, float) end |
#keys ⇒ Object
13 14 15 |
# File 'lib/blackbeard/redis_store.rb', line 13 def keys redis.keys end |
#multi_get(*keys) ⇒ Object
97 98 99 |
# File 'lib/blackbeard/redis_store.rb', line 97 def multi_get(*keys) redis.mget(*keys.flatten) end |
#set(key, value) ⇒ Object
101 102 103 |
# File 'lib/blackbeard/redis_store.rb', line 101 def set(key, value) redis.set(key, value) end |
#set_add_member(set_key, member) ⇒ Object
64 65 66 |
# File 'lib/blackbeard/redis_store.rb', line 64 def set_add_member(set_key, member) redis.sadd(set_key, member) end |
#set_add_members(set_key, *members) ⇒ Object
68 69 70 |
# File 'lib/blackbeard/redis_store.rb', line 68 def set_add_members(set_key, *members) redis.sadd(set_key, members.flatten) end |
#set_count(set_key) ⇒ Object
72 73 74 |
# File 'lib/blackbeard/redis_store.rb', line 72 def set_count(set_key) redis.scard(set_key) end |
#set_members(set_key) ⇒ Object
Set commands
56 57 58 |
# File 'lib/blackbeard/redis_store.rb', line 56 def set_members(set_key) redis.smembers(set_key) end |
#set_remove_member(set_key, member) ⇒ Object
60 61 62 |
# File 'lib/blackbeard/redis_store.rb', line 60 def set_remove_member(set_key, member) redis.srem(set_key, member) end |
#set_union_count(*keys) ⇒ Object
76 77 78 |
# File 'lib/blackbeard/redis_store.rb', line 76 def set_union_count(*keys) redis.sunionstore('set_union_count', keys.flatten) end |