Module: RedisCommandCounter
- Defined in:
- lib/redis_middleware.rb
Overview
RedisCommandCounter is RedisClient middleware.
This middleware counts the number of Redis commands executed. It can be useful for performance monitoring and debugging, allowing you to track the volume of Redis operations in your application.
Class Attribute Summary collapse
-
.count ⇒ Integer
readonly
Gets the current count of Redis commands executed.
Class Method Summary collapse
- .count_commands ⇒ Object
-
.increment ⇒ Integer
Increments the command count.
-
.reset ⇒ Integer
Resets the command count to zero.
Instance Method Summary collapse
-
#call(command, redis_config) ⇒ Object
Counts the Redis command and delegates its execution.
Class Attribute Details
.count ⇒ Integer (readonly)
Gets the current count of Redis commands executed.
73 74 75 |
# File 'lib/redis_middleware.rb', line 73 def count @count end |
Class Method Details
.count_commands ⇒ Object
89 90 91 92 93 94 |
# File 'lib/redis_middleware.rb', line 89 def count_commands start_count = count yield end_count = count end_count - start_count end |
.increment ⇒ Integer
Increments the command count. This method is thread-safe.
85 86 87 |
# File 'lib/redis_middleware.rb', line 85 def increment @mutex.synchronize { @count += 1 } end |
.reset ⇒ Integer
Resets the command count to zero. This method is thread-safe.
78 79 80 |
# File 'lib/redis_middleware.rb', line 78 def reset @mutex.synchronize { @count = 0 } end |
Instance Method Details
#call(command, redis_config) ⇒ Object
Counts the Redis command and delegates its execution.
This method is called for each Redis command when the middleware is active. It increments the command count and then yields to execute the actual command.
105 106 107 108 |
# File 'lib/redis_middleware.rb', line 105 def call(command, redis_config) RedisCommandCounter.increment yield end |