Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add support for redis commandstats

  • Loading branch information...
commit ff78426f1ba50834e4c09799b86e84780aab6bee 1 parent ee5b629
@titanous titanous authored
Showing with 29 additions and 0 deletions.
  1. +18 −0 lib/em-hiredis/client.rb
  2. +11 −0 spec/redis_commands_spec.rb
View
18 lib/em-hiredis/client.rb
@@ -150,6 +150,24 @@ def info(&blk)
method_missing(:info, &hash_processor)
end
+ def info_commandstats(&blk)
+ hash_processor = lambda do |response|
+ commands = {}
+ response.each_line do |line|
+ command, data = line.split(':')
+ if data
+ c = commands[command.sub('cmdstat_', '').to_sym] = {}
+ data.split(',').each do |d|
+ k, v = d.split('=')
+ c[k.to_sym] = v =~ /\./ ? v.to_f : v.to_i
+ end
+ end
+ end
+ blk.call(commands)
+ end
+ method_missing(:info, 'commandstats', &hash_processor)
+ end
+
def close_connection
@closing_connection = true
@connection.close_connection_after_writing
View
11 spec/redis_commands_spec.rb
@@ -619,6 +619,17 @@
end
end
+ it "provides commandstats (INFO COMMANDSTATS)" do
+ connect do |redis|
+ redis.info_commandstats do |r|
+ r[:get][:calls].should be_a_kind_of(Integer)
+ r[:get][:usec].should be_a_kind_of(Integer)
+ r[:get][:usec_per_call].should be_a_kind_of(Float)
+ done
+ end
+ end
+ end
+
it "flushes the database (FLUSHDB)" do
connect do |redis|
redis.set('key1', 'keyone')
Please sign in to comment.
Something went wrong with that request. Please try again.