redis-cli now checks the arity of vararg commnads
[redis.git] / client-libraries / ruby / tasks / redis.tasks.rb
1 # Inspired by rabbitmq.rake the Redbox project at http://github.com/rick/redbox/tree/master
2 require 'fileutils'
3
4 class RedisRunner
5
6 def self.redisdir
7 "/tmp/redis/"
8 end
9
10 def self.redisconfdir
11 '/etc/redis.conf'
12 end
13
14 def self.dtach_socket
15 '/tmp/redis.dtach'
16 end
17
18 # Just check for existance of dtach socket
19 def self.running?
20 File.exists? dtach_socket
21 end
22
23 def self.start
24 puts 'Detach with Ctrl+\ Re-attach with rake redis:attach'
25 sleep 3
26 exec "dtach -A #{dtach_socket} redis-server #{redisconfdir}"
27 end
28
29 def self.attach
30 exec "dtach -a #{dtach_socket}"
31 end
32
33 def self.stop
34 sh 'killall redis-server'
35 end
36
37 end
38
39 namespace :redis do
40
41 desc 'About redis'
42 task :about do
43 puts "\nSee http://code.google.com/p/redis/ for information about redis.\n\n"
44 end
45
46 desc 'Start redis'
47 task :start do
48 RedisRunner.start
49 end
50
51 desc 'Stop redis'
52 task :stop do
53 RedisRunner.stop
54 end
55
56 desc 'Attach to redis dtach socket'
57 task :attach do
58 RedisRunner.attach
59 end
60
61 desc 'Install the lastest redis from svn'
62 task :install => [:about, :download, :make] do
63 sh 'sudo cp /tmp/redis/redis-server /usr/bin/'
64 sh 'sudo cp /tmp/redis/redis-benchmark /usr/bin/'
65 puts 'Installed redis-server and redis-benchmark to /usr/bin/'
66 unless File.exists?('/etc/redis.conf')
67 sh 'sudo cp /tmp/redis/redis.conf /etc/'
68 puts "Installed redis.conf to /etc/ \n You should look at this file!"
69 end
70 end
71
72 task :make do
73 sh "cd #{RedisRunner.redisdir} && make clean"
74 sh "cd #{RedisRunner.redisdir} && make"
75 end
76
77 desc "Download package"
78 task :download do
79 system 'svn checkout http://redis.googlecode.com/svn/trunk /tmp/redis' unless File.exists?(RedisRunner.redisdir)
80 system 'svn up' if File.exists?("#{RedisRunner.redisdir}/.svn")
81 end
82
83 end
84
85 namespace :dtach do
86
87 desc 'About dtach'
88 task :about do
89 puts "\nSee http://dtach.sourceforge.net/ for information about dtach.\n\n"
90 end
91
92 desc 'Install dtach 0.8 from source'
93 task :install => [:about] do
94
95 Dir.chdir('/tmp/')
96 unless File.exists?('/tmp/dtach-0.8.tar.gz')
97 require 'net/http'
98
99 Net::HTTP.start('superb-west.dl.sourceforge.net') do |http|
100 resp = http.get('/sourceforge/dtach/dtach-0.8.tar.gz')
101 open('/tmp/dtach-0.8.tar.gz', 'wb') do |file| file.write(resp.body) end
102 end
103 end
104
105 unless File.directory?('/tmp/dtach-0.8')
106 system('tar xzf dtach-0.8.tar.gz')
107 end
108
109 Dir.chdir('/tmp/dtach-0.8/')
110 sh 'cd /tmp/dtach-0.8/ && ./configure && make'
111 sh 'sudo cp /tmp/dtach-0.8/dtach /usr/bin/'
112
113 puts 'Dtach successfully installed to /usr/bin.'
114 end
115 end
116