Permalink
Browse files

Implemented flush_db and last_save (w/specs).

  • Loading branch information...
1 parent 0643704 commit 90f4eddf4dbac847b2c2ea2219378c7deb41b0a2 Taylor Weibley committed Mar 21, 2009
Showing with 31 additions and 1 deletion.
  1. +16 −1 lib/redis.rb
  2. +15 −0 spec/redis_spec.rb
View
17 lib/redis.rb
@@ -728,7 +728,7 @@ def info
info = {}
x = timeout_retry(3, 3){
- write "INFO \r\n"
+ write "INFO\r\n"
read(read_proto.to_i.abs).split("\r\n")
}
@@ -740,6 +740,21 @@ def info
info
end
+ def flush_db
+ timeout_retry(3, 3){
+ write "FLUSHDB\r\n"
+ status_code_reply
+ }
+ end
+
+
+ def last_save
+ timeout_retry(3, 3){
+ write "LASTSAVE\r\n"
+ single_line_reply.to_i
+ }
+ end
+
private
def redis_unmarshal(obj)
View
15 spec/redis_spec.rb
@@ -280,4 +280,19 @@ class MyFail; def fail; 'it will' end; end
@r.info.keys.should include(x)
end
end
+
+ it "should be able to flush the database" do
+ @r['key1'] = 'keyone'
+ @r['key2'] = 'keytwo'
+ @r.keys('*').sort.should == ['foo', 'key1', 'key2'] #foo from before
+ @r.flush_db
+ @r.keys('*').should == []
+ end
+
+ it "should be able to provide the last save time" do
+ savetime = @r.last_save
+ Time.at(savetime).class.should == Time
+ Time.at(savetime).should <= Time.now
+ end
+
end

0 comments on commit 90f4edd

Please sign in to comment.