]> git.saurik.com Git - redis.git/blame - client-libraries/ruby/tasks/redis.tasks.rb
initial multi-bulk query protocol, this will allow MSET and other interesting features.
[redis.git] / client-libraries / ruby / tasks / redis.tasks.rb
CommitLineData
ed9b544e 1# Inspired by rabbitmq.rake the Redbox project at http://github.com/rick/redbox/tree/master
2require 'fileutils'
3113921a 3require 'open-uri'
ed9b544e 4
5class RedisRunner
6
7 def self.redisdir
8 "/tmp/redis/"
9 end
10
11 def self.redisconfdir
12 '/etc/redis.conf'
13 end
14
15 def self.dtach_socket
16 '/tmp/redis.dtach'
17 end
18
19 # Just check for existance of dtach socket
20 def self.running?
21 File.exists? dtach_socket
22 end
23
24 def self.start
25 puts 'Detach with Ctrl+\ Re-attach with rake redis:attach'
26 sleep 3
27 exec "dtach -A #{dtach_socket} redis-server #{redisconfdir}"
28 end
29
30 def self.attach
31 exec "dtach -a #{dtach_socket}"
32 end
33
34 def self.stop
9495122b 35 sh 'echo "SHUTDOWN" | nc localhost 6379'
ed9b544e 36 end
37
38end
39
40namespace :redis do
41
42 desc 'About redis'
43 task :about do
44 puts "\nSee http://code.google.com/p/redis/ for information about redis.\n\n"
45 end
46
47 desc 'Start redis'
48 task :start do
49 RedisRunner.start
50 end
51
52 desc 'Stop redis'
53 task :stop do
54 RedisRunner.stop
55 end
29fac617 56
57 desc 'Restart redis'
58 task :restart do
59 RedisRunner.stop
60 RedisRunner.start
61 end
ed9b544e 62
63 desc 'Attach to redis dtach socket'
64 task :attach do
65 RedisRunner.attach
66 end
67
d7fc9edb 68 desc 'Install the lastest verison of Redis from Github (requires git, duh)'
ed9b544e 69 task :install => [:about, :download, :make] do
29fac617 70 %w(redis-benchmark redis-cli redis-server).each do |bin|
71 sh "sudo cp /tmp/redis/#{bin} /usr/bin/"
72 end
73
74 puts "Installed redis-benchmark, redis-cli and redis-server to /usr/bin/"
75
ed9b544e 76 unless File.exists?('/etc/redis.conf')
77 sh 'sudo cp /tmp/redis/redis.conf /etc/'
78 puts "Installed redis.conf to /etc/ \n You should look at this file!"
79 end
80 end
81
82 task :make do
83 sh "cd #{RedisRunner.redisdir} && make clean"
84 sh "cd #{RedisRunner.redisdir} && make"
85 end
86
87 desc "Download package"
88 task :download do
29fac617 89 sh 'rm -rf /tmp/redis/' if File.exists?("#{RedisRunner.redisdir}/.svn")
90 sh 'git clone git://github.com/antirez/redis.git /tmp/redis' unless File.exists?(RedisRunner.redisdir)
91 sh "cd #{RedisRunner.redisdir} && git pull" if File.exists?("#{RedisRunner.redisdir}/.git")
ed9b544e 92 end
93
94end
95
96namespace :dtach do
97
98 desc 'About dtach'
99 task :about do
100 puts "\nSee http://dtach.sourceforge.net/ for information about dtach.\n\n"
101 end
102
103 desc 'Install dtach 0.8 from source'
104 task :install => [:about] do
105
106 Dir.chdir('/tmp/')
107 unless File.exists?('/tmp/dtach-0.8.tar.gz')
108 require 'net/http'
109
3113921a 110 url = 'http://downloads.sourceforge.net/project/dtach/dtach/0.8/dtach-0.8.tar.gz'
111 open('/tmp/dtach-0.8.tar.gz', 'wb') do |file| file.write(open(url).read) end
ed9b544e 112 end
113
114 unless File.directory?('/tmp/dtach-0.8')
115 system('tar xzf dtach-0.8.tar.gz')
116 end
117
118 Dir.chdir('/tmp/dtach-0.8/')
119 sh 'cd /tmp/dtach-0.8/ && ./configure && make'
120 sh 'sudo cp /tmp/dtach-0.8/dtach /usr/bin/'
121
122 puts 'Dtach successfully installed to /usr/bin.'
123 end
124end
3113921a 125