Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix INFO command parsing #18

Merged
merged 2 commits into from

2 participants

@titanous

This patch fixes INFO parsing for Redis 2.6.

@mloughran
Owner

Thanks, looks good!

@mloughran mloughran merged commit aa5ae6b into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 16, 2012
  1. @titanous

    Fix INFO command parsing

    titanous authored
Commits on Jun 17, 2012
  1. @titanous
This page is out of date. Refresh to see the latest.
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,7 +611,7 @@
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
@@ -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')
Something went wrong with that request. Please try again.