Class: Pause::Redis::ShardedAdapter

Inherits:
Adapter
  • Object
show all
Defined in:
lib/pause/redis/sharded_adapter.rb

Overview

This class encapsulates Redis operations used by Pause. Operations that are not possible when data is sharded raise an error.

Instance Attribute Summary

Attributes inherited from Adapter

#history, #resolution, #time_blocks_to_keep

Instance Method Summary collapse

Methods inherited from Adapter

#all_keys, #delete_rate_limited_key, #delete_rate_limited_keys, #disable, #disabled?, #enable, #enabled?, #expire_block_list, #initialize, #key_history, #rate_limit!, #rate_limited?, #rate_limited_keys

Methods included from Helper::Timing

#period_marker

Constructor Details

This class inherits a constructor from Pause::Redis::Adapter

Instance Method Details

#increment(scope, identifier, timestamp, count = 1) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/pause/redis/sharded_adapter.rb', line 10

def increment(scope, identifier, timestamp, count = 1)
  k = tracked_key(scope, identifier)
  redis.zincrby k, count, period_marker(resolution, timestamp)
  redis.expire k, history

  if redis.zcard(k) > time_blocks_to_keep
    list = extract_set_elements(k)
    to_remove = list.slice(0, (list.size - time_blocks_to_keep))
    redis.zrem(k, to_remove.map(&:ts))
  end
end