This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Fix `Daikon::Monitor` to handle log from multiple databases correctly

  • Loading branch information...
sikachu committed May 13, 2011
1 parent a1889ce commit 59883f02a83a9c996a7f4350b1f4f7a834335163
Showing with 12 additions and 1 deletion.
  1. +1 −1 lib/daikon/monitor.rb
  2. +11 −0 spec/monitor_spec.rb
View
@@ -6,7 +6,7 @@ class Monitor
OTHER_COMMANDS = ["AUTH", "BGREWRITEAOF", "BGSAVE", "CONFIG GET", "CONFIG SET", "CONFIG RESETSTAT", "DBSIZE", "DEBUG OBJECT", "DEBUG SEGFAULT", "DISCARD", "ECHO", "EXEC", "FLUSHALL", "FLUSHDB", "INFO", "LASTSAVE", "MONITOR", "MULTI", "PING", "PSUBSCRIBE", "PUBLISH", "PUNSUBSCRIBE", "QUIT", "RANDOMKEY", "SAVE", "SELECT", "SHUTDOWN", "SUBSCRIBE", "SYNC", "UNSUBSCRIBE", "UNWATCH", "WATCH"].to_set
ALL_COMMANDS = READ_COMMANDS + WRITE_COMMANDS + OTHER_COMMANDS
- NEW_FORMAT = /^\+?\d+\.\d+ "(.*)"$/i
+ NEW_FORMAT = /^\+?\d+\.\d+ (?:\(db \d+\) )?"(.*)"$/i
OLD_SINGLE_FORMAT = /^(#{NO_ARG_COMMANDS.join('|')})$/i
OLD_MORE_FORMAT = /^[A-Z]+ .*$/i
View
@@ -227,6 +227,17 @@
end
end
+describe Daikon::Monitor, "#parse multiple database log" do
+ it "parses the data correctly" do
+ parse('1304626114.869421 (db 2) "rpop" "shoppinshoppinshoppinshoppinshoppingggggshopping"')
+
+ Daikon::Monitor.pop do |summary|
+ summary["commands"].should == {"RPOP" => 1}
+ summary["keys"].should == {"shoppinshoppinshoppinshoppinshoppingggggshopping" => 1}
+ end
+ end
+end
+
describe Daikon::Monitor, ".start" do
let(:redis) { stub('redis', :monitor => true) }
before do

0 comments on commit 59883f0

Please sign in to comment.