Skip to content

Commit

Permalink
docs(all): documenting
Browse files Browse the repository at this point in the history
  • Loading branch information
Napolskih committed Sep 13, 2013
1 parent 43016ec commit f8d037c
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/redis_counters/base_counter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

module RedisCounters

# Базовый класс счетчика на основе Redis.

class BaseCounter
extend Forwardable

Expand All @@ -20,17 +22,39 @@ class BaseCounter
attr_reader :options
attr_reader :params

# Public: Фабричный метод создания счетчика заданного класса.
#
# redis - Redis - экземпляр redis - клиента.
# opts - Hash - хеш опций счетчика:
# counter_name - Symbol/String - идентификатор счетчика.
# key_delimiter - String - разделитель ключа (опционально).
# value_delimiter - String - разделитель значений (опционально).
#
# Returns RedisCounters::BaseCounter.
#
def self.create(redis, opts)
counter_class = opts.fetch(:counter_class).to_s.constantize
counter_class.new(redis, opts)
end

# Public: Конструктор.
#
# см. self.create.
#
# Returns RedisCounters::BaseCounter.
#
def initialize(redis, opts)
@redis = redis
@options = opts
init
end

# Public: Метод производит обработку события.
#
# params - Hash - хеш параметров события.
#
# Returns process_value result.
#
def process(params = {}, &block)
@params = params
process_value(&block)
Expand Down
2 changes: 2 additions & 0 deletions lib/redis_counters/hash_counter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

module RedisCounters

# Счетчик на основе redis-hash, с возможностью партиционирования и группировки значений.

class HashCounter < BaseCounter
alias_method :increment, :process

Expand Down
2 changes: 2 additions & 0 deletions lib/redis_counters/unique_hash_counter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

module RedisCounters

# HashCounter, с возможностью подсчета только уникальных значений.

class UniqueHashCounter < HashCounter
UNIQUE_LIST_POSTFIX = 'uq'.freeze

Expand Down
3 changes: 3 additions & 0 deletions lib/redis_counters/unique_values_lists/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
module RedisCounters
module UniqueValuesLists

# Базовый класс уникального списка значений,
# с возможностью группировки и партиционирования.

class Base < RedisCounters::BaseCounter
alias_method :add, :process

Expand Down
7 changes: 7 additions & 0 deletions lib/redis_counters/unique_values_lists/fast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
module RedisCounters
module UniqueValuesLists

# Список уникального значений, на основе не блокирующего алгоритма.
#
# Особенности:
# * 2-х кратный расхзод памяти в случае использования партиций;
# * Не ведет список партиций;
# * Не транзакционен.

class Fast < UniqueValuesLists::Base

protected
Expand Down
10 changes: 10 additions & 0 deletions lib/redis_counters/unique_values_lists/standard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
module RedisCounters
module UniqueValuesLists

# Список уникального значений, на основе механизма оптимистических блокировок.
#
# смотри Optimistic locking using check-and-set:
# http://redis.io/topics/transactions
#
# Особенности:
# * Значения сохраняет в партициях;
# * Ведет список партиций;
# * Полностью транзакционен.

class Standard < Base
PARTITIONS_LIST_POSTFIX = :partitions

Expand Down

0 comments on commit f8d037c

Please sign in to comment.