-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(unique_values_list): fast (non blocking) unique values list a…
…dded - refactoring unique_values_list; - fast (non blocking) unique values list added; - unique_list[:list_class] property introduced on UniqueHashCounter.
- Loading branch information
Showing
11 changed files
with
313 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# coding: utf-8 | ||
require 'redis_counters/base_counter' | ||
|
||
module RedisCounters | ||
module UniqueValuesLists | ||
|
||
class Base < RedisCounters::BaseCounter | ||
alias_method :add, :process | ||
|
||
protected | ||
|
||
def key(partition = partition_params) | ||
[counter_name, group_params, partition].flatten.compact.join(KEY_DELIMITER) | ||
end | ||
|
||
def group_params | ||
group_keys.map { |key| params.fetch(key) } | ||
end | ||
|
||
def partition_params | ||
partition_keys.map { |key| params.fetch(key) } | ||
end | ||
|
||
def value | ||
value_params = value_keys.map { |key| params.fetch(key) } | ||
value_params.join(KEY_DELIMITER) | ||
end | ||
|
||
def use_partitions? | ||
partition_keys.present? | ||
end | ||
|
||
def value_keys | ||
@value_keys ||= Array.wrap(options.fetch(:value_keys)) | ||
end | ||
|
||
def partition_keys | ||
@partition_keys ||= Array.wrap(options.fetch(:partition_keys, [])) | ||
end | ||
|
||
def group_keys | ||
@group_keys ||= Array.wrap(options.fetch(:group_keys, [])) | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# coding: utf-8 | ||
require 'redis_counters/unique_values_lists/base' | ||
|
||
module RedisCounters | ||
module UniqueValuesLists | ||
|
||
class Fast < UniqueValuesLists::Base | ||
|
||
protected | ||
|
||
def process_value | ||
return unless add_value | ||
yield redis if block_given? | ||
true | ||
end | ||
|
||
def add_value | ||
return unless redis.sadd(main_partition_key, value) | ||
redis.sadd(current_partition_key, value) if use_partitions? | ||
true | ||
end | ||
|
||
def main_partition_key | ||
key([]) | ||
end | ||
|
||
def current_partition_key | ||
key | ||
end | ||
|
||
def partitions | ||
redis.keys(key('*')) | ||
end | ||
end | ||
|
||
end | ||
end |
Oops, something went wrong.