Browse files

Merge pull request #18 from titanous/fix-info

Fix INFO command parsing
  • Loading branch information...
2 parents d019dd0 + ff78426 commit aa5ae6bd019946a492e1879f5f8f860fef9b49f0 @mloughran committed Jun 19, 2012
Showing with 32 additions and 3 deletions.
  1. +20 −2 lib/em-hiredis/client.rb
  2. +12 −1 spec/redis_commands_spec.rb
View
22 lib/em-hiredis/client.rb
@@ -142,14 +142,32 @@ def info(&blk)
hash_processor = lambda do |response|
info = {}
response.each_line do |line|
- key, value = line.split(":", 2)
- info[key.to_sym] = value.chomp
+ key, value = line.chomp.split(":", 2)
+ info[key.to_sym] = value if value && key =~ /^[^#]/
end
blk.call(info)
end
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
13 spec/redis_commands_spec.rb
@@ -611,14 +611,25 @@
it "provides info (INFO)" do
connect do |redis|
redis.info do |r|
- [:last_save_time, :redis_version, :total_connections_received, :connected_clients, :total_commands_processed, :connected_slaves, :uptime_in_seconds, :used_memory, :uptime_in_days, :changes_since_last_save].each do |x|
+ [:redis_version, :total_connections_received, :connected_clients, :total_commands_processed, :connected_slaves, :uptime_in_seconds, :used_memory, :uptime_in_days].each do |x|
r.keys.include?(x).should == true
end
done
end
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')

0 comments on commit aa5ae6b

Please sign in to comment.