Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/tweibley/redis-rb
Browse files Browse the repository at this point in the history
* 'master' of git://github.com/tweibley/redis-rb:
  Implemented flush_db and last_save (w/specs).
  Fix redis download task so svn up is called on the right directory.
  Added support for info command (w/spec).  Added redis restart task.  Updated redis install task to include redis-cli.  Bumped version to 0.0.3.
  • Loading branch information
Ezra Zygmuntowicz committed Mar 21, 2009
2 parents d26c67c + 90f4edd commit cefbf1e
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require 'tasks/redis.tasks'


GEM = 'redis'
GEM_VERSION = '0.0.2'
GEM_VERSION = '0.0.3'
AUTHORS = ['Ezra Zygmuntowicz', 'Taylor Weibley']
EMAIL = "ez@engineyard.com"
HOMEPAGE = "http://github.com/ezmobius/redis-rb"
Expand Down
32 changes: 32 additions & 0 deletions lib/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,38 @@ def quit
}
end


def info
info = {}

x = timeout_retry(3, 3){
write "INFO\r\n"
read(read_proto.to_i.abs).split("\r\n")
}

x.each do |kv|
k,v = kv.split(':')[0], kv.split(':')[1]
info[k.to_sym] = v
end

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)
Expand Down
21 changes: 21 additions & 0 deletions spec/redis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,25 @@ class MyFail; def fail; 'it will' end; end
@r.sort('dogs', :get => 'dog_*', :limit => [0,1]).should == ['louie']
@r.sort('dogs', :get => 'dog_*', :limit => [0,1], :order => 'desc alpha').should == ['taj']
end

it "should provide info" do
[: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|
@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
19 changes: 14 additions & 5 deletions tasks/redis.tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ def self.stop
task :stop do
RedisRunner.stop
end

desc 'Restart redis'
task :restart do
RedisRunner.stop
RedisRunner.start
end

desc 'Attach to redis dtach socket'
task :attach do
Expand All @@ -60,9 +66,12 @@ def self.stop

desc 'Install the lastest redis from svn'
task :install => [:about, :download, :make] do
sh 'sudo cp /tmp/redis/redis-server /usr/bin/'
sh 'sudo cp /tmp/redis/redis-benchmark /usr/bin/'
puts 'Installed redis-server and redis-benchmark to /usr/bin/'
%w(redis-benchmark redis-cli redis-server).each do |bin|
sh "sudo cp /tmp/redis/#{bin} /usr/bin/"
end

puts "Installed redis-benchmark, redis-cli and redis-server to /usr/bin/"

unless File.exists?('/etc/redis.conf')
sh 'sudo cp /tmp/redis/redis.conf /etc/'
puts "Installed redis.conf to /etc/ \n You should look at this file!"
Expand All @@ -76,8 +85,8 @@ def self.stop

desc "Download package"
task :download do
system 'svn checkout http://redis.googlecode.com/svn/trunk /tmp/redis' unless File.exists?(RedisRunner.redisdir)
system 'svn up' if File.exists?("#{RedisRunner.redisdir}/.svn")
sh 'svn checkout http://redis.googlecode.com/svn/trunk /tmp/redis' unless File.exists?(RedisRunner.redisdir)
sh "cd #{RedisRunner.redisdir} && svn up" if File.exists?("#{RedisRunner.redisdir}/.svn")
end

end
Expand Down

0 comments on commit cefbf1e

Please sign in to comment.