Class: Abaci::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/abaci/store.rb

Overview

Common interface for Redis. In the future this could be swapped out for an alternate datastore.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Store

Returns a new instance of Store.



9
10
11
12
# File 'lib/abaci/store.rb', line 9

def initialize(options)
  @redis = options[:redis] || Redis.current
  @prefix = options[:prefix] || "stats"
end

Instance Attribute Details

#prefixObject (readonly)

Returns the value of attribute prefix.



7
8
9
# File 'lib/abaci/store.rb', line 7

def prefix
  @prefix
end

#redisObject (readonly)

Returns the value of attribute redis.



7
8
9
# File 'lib/abaci/store.rb', line 7

def redis
  @redis
end

Instance Method Details

#decrby(key, by = 1) ⇒ Object



14
15
16
# File 'lib/abaci/store.rb', line 14

def decrby(key, by = 1)
  exec(:decrby, key, by)
end

#del(key) ⇒ Object



18
19
20
# File 'lib/abaci/store.rb', line 18

def del(key)
  exec(:del, key)
end

#get(key) ⇒ Object



22
23
24
# File 'lib/abaci/store.rb', line 22

def get(key)
  exec(:get, key)
end

#incrby(key, by = 1) ⇒ Object



26
27
28
# File 'lib/abaci/store.rb', line 26

def incrby(key, by = 1)
  exec(:incrby, key, by)
end

#keys(pattern = "*") ⇒ Object



30
31
32
33
# File 'lib/abaci/store.rb', line 30

def keys(pattern = "*")
  sub = Regexp.new("^#{ prefix }:")
  exec(:keys, pattern).map { |k| k.gsub(sub, "") }
end

#sadd(key, member) ⇒ Object



39
40
41
# File 'lib/abaci/store.rb', line 39

def sadd(key, member)
  exec_without_prefix(:sadd, "#{ prefix }#{ key }", member)
end

#set(key, value) ⇒ Object



35
36
37
# File 'lib/abaci/store.rb', line 35

def set(key, value)
  exec(:set, key, value)
end

#smembers(key) ⇒ Object



43
44
45
# File 'lib/abaci/store.rb', line 43

def smembers(key)
  exec_without_prefix(:smembers, "#{ prefix }#{ key }")
end

#srem(key, member) ⇒ Object



47
48
49
# File 'lib/abaci/store.rb', line 47

def srem(key, member)
  exec_without_prefix(:srem, "#{ prefix }#{ key }", member)
end