Class: Counter

Inherits:
RedisConnection show all
Defined in:
lib/redis_store.rb

Instance Attribute Summary collapse

Attributes inherited from RedisConnection

#redis

Instance Method Summary collapse

Methods inherited from RedisConnection

#counters

Constructor Details

#initialize(key) ⇒ Counter

Returns a new instance of Counter.



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

def initialize key
  @key = key
  super  
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



88
89
90
# File 'lib/redis_store.rb', line 88

def key
  @key
end

Instance Method Details

#delObject



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

def del
  @redis.hdel "counters", @key
end

#incrObject



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

def incr
  @redis.hincrby "counters", @key, 1
end

#to_sObject



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

def to_s
  @redis.hget "counters", @key
end