Class: Gitlab::Redis::HLL
- Inherits:
-
Object
- Object
- Gitlab::Redis::HLL
- Defined in:
- lib/gitlab/redis/hll.rb
Constant Summary collapse
- BATCH_SIZE =
300
- KEY_REGEX =
%r{\A(\w|-|:)*\{\w*\}(\w|-|:)*\z}
- KeyFormatError =
Class.new(StandardError)
Class Method Summary collapse
Instance Method Summary collapse
-
#add(key:, value:, expiry:) ⇒ Object
Check a basic format for the Redis key in order to ensure the keys are in the same hash slot.
- #count(keys:) ⇒ Object
Class Method Details
.add(params) ⇒ Object
15 16 17 |
# File 'lib/gitlab/redis/hll.rb', line 15 def self.add(params) self.new.add(**params) end |
.count(params) ⇒ Object
11 12 13 |
# File 'lib/gitlab/redis/hll.rb', line 11 def self.count(params) self.new.count(**params) end |
Instance Method Details
#add(key:, value:, expiry:) ⇒ Object
Check a basic format for the Redis key in order to ensure the keys are in the same hash slot
Examples of keys
project:{1}:set_a
project:{1}:set_b
project:{2}:set_c
2020-216-{project_action}
i_{analytics}_dev_ops_score-2020-32
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/gitlab/redis/hll.rb', line 33 def add(key:, value:, expiry:) validate_key!(key) Gitlab::Redis::SharedState.with do |redis| redis.multi do |multi| Array.wrap(value).each_slice(BATCH_SIZE) { |batch| multi.pfadd(key, batch) } multi.expire(key, expiry) end end end |
#count(keys:) ⇒ Object
19 20 21 22 23 |
# File 'lib/gitlab/redis/hll.rb', line 19 def count(keys:) Gitlab::Redis::SharedState.with do |redis| redis.pfcount(*keys) end end |