Skip to content

Commit

Permalink
Add support for redis commandstats
Browse files Browse the repository at this point in the history
  • Loading branch information
titanous committed Jun 17, 2012
1 parent ee5b629 commit ff78426
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/em-hiredis/client.rb
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions spec/redis_commands_spec.rb
Expand Up @@ -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')
Expand Down

0 comments on commit ff78426

Please sign in to comment.