Module: FreshRedis::String

Included in:
FreshRedis
Defined in:
lib/fresh_redis/string.rb

Instance Method Summary collapse

Instance Method Details

#fincr(key, options = {}) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/fresh_redis/string.rb', line 3

def fincr(key, options={})
  key = build_key(key, options)
  @redis.multi do
    @redis.incr(key.redis_key)
    @redis.expire(key.redis_key, key.freshness)
  end
end

#fsum(key, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/fresh_redis/string.rb', line 11

def fsum(key, options={})
  key = build_key(key, options)
  @redis.pipelined {
    key.timestamp_buckets.each do |bucket_key|
      @redis.get(bucket_key)
    end
  }.reduce(0){|acc, value|
    value ? acc + value.to_i : acc
  }
end