| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# |
|
2
|
|
|
|
|
|
|
# $Id$ |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
# server::redis Brik |
|
5
|
|
|
|
|
|
|
# |
|
6
|
|
|
|
|
|
|
package Metabrik::Server::Redis; |
|
7
|
1
|
|
|
1
|
|
766
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
29
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
27
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
7
|
use base qw(Metabrik::System::Process); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
1001
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub brik_properties { |
|
13
|
|
|
|
|
|
|
return { |
|
14
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
|
15
|
|
|
|
|
|
|
tags => [ qw(unstable) ], |
|
16
|
|
|
|
|
|
|
author => 'GomoR ', |
|
17
|
|
|
|
|
|
|
license => 'http://opensource.org/licenses/BSD-3-Clause', |
|
18
|
|
|
|
|
|
|
attributes => { |
|
19
|
|
|
|
|
|
|
datadir => [ qw(datadir) ], |
|
20
|
|
|
|
|
|
|
version => [ qw(version) ], |
|
21
|
|
|
|
|
|
|
conf_file => [ qw(file) ], |
|
22
|
|
|
|
|
|
|
listen => [ qw(address) ], |
|
23
|
|
|
|
|
|
|
port => [ qw(port) ], |
|
24
|
|
|
|
|
|
|
pidfile => [ qw(pidfile) ], |
|
25
|
|
|
|
|
|
|
log_file => [ qw(log_file) ], |
|
26
|
|
|
|
|
|
|
}, |
|
27
|
|
|
|
|
|
|
attributes_default => { |
|
28
|
|
|
|
|
|
|
listen => '127.0.0.1', |
|
29
|
|
|
|
|
|
|
port => 6379, |
|
30
|
|
|
|
|
|
|
}, |
|
31
|
|
|
|
|
|
|
commands => { |
|
32
|
|
|
|
|
|
|
install => [ ], # Inherited |
|
33
|
|
|
|
|
|
|
generate_conf => [ qw(conf|OPTIONAL port|OPTIONAL listen|OPTIONAL) ], |
|
34
|
|
|
|
|
|
|
start => [ qw(port|OPTIONAL listen|OPTIONAL) ], |
|
35
|
|
|
|
|
|
|
stop => [ ], |
|
36
|
|
|
|
|
|
|
status => [ ], |
|
37
|
|
|
|
|
|
|
}, |
|
38
|
|
|
|
|
|
|
require_modules => { |
|
39
|
|
|
|
|
|
|
'Metabrik::File::Text' => [ ], |
|
40
|
|
|
|
|
|
|
'Metabrik::System::File' => [ ], |
|
41
|
|
|
|
|
|
|
}, |
|
42
|
|
|
|
|
|
|
require_binaries => { |
|
43
|
|
|
|
|
|
|
'redis-server' => [ ], |
|
44
|
|
|
|
|
|
|
}, |
|
45
|
|
|
|
|
|
|
need_packages => { |
|
46
|
|
|
|
|
|
|
ubuntu => [ qw(redis-server) ], |
|
47
|
|
|
|
|
|
|
debian => [ qw(redis-server) ], |
|
48
|
|
|
|
|
|
|
kali => [ qw(redis-server) ], |
|
49
|
|
|
|
|
|
|
freebsd => [ qw(redis) ], |
|
50
|
|
|
|
|
|
|
}, |
|
51
|
|
|
|
|
|
|
}; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub brik_use_properties { |
|
55
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
56
|
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
my $datadir = $self->datadir; |
|
58
|
0
|
|
|
|
|
|
my $conf_file = $datadir.'/redis.conf'; |
|
59
|
0
|
|
|
|
|
|
my $log_file = $datadir.'/redis.log'; |
|
60
|
0
|
|
|
|
|
|
my $pidfile = $datadir.'/redis.pid'; |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
return { |
|
63
|
0
|
|
|
|
|
|
attributes_default => { |
|
64
|
|
|
|
|
|
|
conf_file => $conf_file, |
|
65
|
|
|
|
|
|
|
log_file => $log_file, |
|
66
|
|
|
|
|
|
|
pidfile => $pidfile, |
|
67
|
|
|
|
|
|
|
}, |
|
68
|
|
|
|
|
|
|
}; |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub generate_conf { |
|
72
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
73
|
0
|
|
|
|
|
|
my ($conf_file, $port, $listen) = @_; |
|
74
|
|
|
|
|
|
|
|
|
75
|
0
|
|
0
|
|
|
|
$conf_file ||= $self->conf_file; |
|
76
|
0
|
|
0
|
|
|
|
$port ||= $self->port; |
|
77
|
0
|
|
0
|
|
|
|
$listen ||= $self->listen; |
|
78
|
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my $datadir = $self->datadir; |
|
80
|
0
|
|
|
|
|
|
my $log_file = $self->log_file; |
|
81
|
0
|
|
|
|
|
|
my $pidfile = $self->pidfile; |
|
82
|
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
my $lib_dir = 'var/lib/redis'; |
|
84
|
|
|
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
|
my $sf = Metabrik::System::File->new_from_brik_init($self) or return; |
|
86
|
0
|
0
|
|
|
|
|
$sf->mkdir($datadir.'/'.$lib_dir) or return; |
|
87
|
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
my $dir = $self->datadir.'/'.$lib_dir; |
|
89
|
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
my $params = { |
|
91
|
|
|
|
|
|
|
"daemonize" => "yes", |
|
92
|
|
|
|
|
|
|
"bind" => $listen, |
|
93
|
|
|
|
|
|
|
"dir" => $dir, |
|
94
|
|
|
|
|
|
|
"logfile" => $log_file, |
|
95
|
|
|
|
|
|
|
"pidfile" => $pidfile, |
|
96
|
|
|
|
|
|
|
"port" => $port, |
|
97
|
|
|
|
|
|
|
"client-output-buffer-limit" => [ |
|
98
|
|
|
|
|
|
|
'normal 0 0 0', |
|
99
|
|
|
|
|
|
|
'slave 256mb 64mb 60', |
|
100
|
|
|
|
|
|
|
'pubsub 32mb 8mb 60', |
|
101
|
|
|
|
|
|
|
], |
|
102
|
|
|
|
|
|
|
"databases" => 16, |
|
103
|
|
|
|
|
|
|
"activerehashing" => "yes", |
|
104
|
|
|
|
|
|
|
"aof-load-truncated" => "yes", |
|
105
|
|
|
|
|
|
|
"aof-rewrite-incremental-fsync" => "yes", |
|
106
|
|
|
|
|
|
|
"appendfilename" => "\"appendonly.aof\"", |
|
107
|
|
|
|
|
|
|
"appendfsync" => "everysec", |
|
108
|
|
|
|
|
|
|
"appendonly" => "no", |
|
109
|
|
|
|
|
|
|
"auto-aof-rewrite-min-size" => "64mb", |
|
110
|
|
|
|
|
|
|
"auto-aof-rewrite-percentage" => 100, |
|
111
|
|
|
|
|
|
|
"dbfilename" => "dump.rdb", |
|
112
|
|
|
|
|
|
|
"hash-max-ziplist-entries" => 512, |
|
113
|
|
|
|
|
|
|
"hash-max-ziplist-value" => 64, |
|
114
|
|
|
|
|
|
|
"hll-sparse-max-bytes" => 3000, |
|
115
|
|
|
|
|
|
|
"hz" => 10, |
|
116
|
|
|
|
|
|
|
"latency-monitor-threshold" => 0, |
|
117
|
|
|
|
|
|
|
"list-max-ziplist-entries" => 512, |
|
118
|
|
|
|
|
|
|
"list-max-ziplist-value" => 64, |
|
119
|
|
|
|
|
|
|
"loglevel" => "notice", |
|
120
|
|
|
|
|
|
|
"lua-time-limit" => 5000, |
|
121
|
|
|
|
|
|
|
"no-appendfsync-on-rewrite" => "no", |
|
122
|
|
|
|
|
|
|
"notify-keyspace-events" => "\"\"", |
|
123
|
|
|
|
|
|
|
"rdbchecksum" => "yes", |
|
124
|
|
|
|
|
|
|
"rdbcompression" => "yes", |
|
125
|
|
|
|
|
|
|
"repl-disable-tcp-nodelay" => "no", |
|
126
|
|
|
|
|
|
|
"repl-diskless-sync" => "no", |
|
127
|
|
|
|
|
|
|
"repl-diskless-sync-delay" => 5, |
|
128
|
|
|
|
|
|
|
"save" => 60, |
|
129
|
|
|
|
|
|
|
"set-max-intset-entries" => 512, |
|
130
|
|
|
|
|
|
|
"slave-priority" => 100, |
|
131
|
|
|
|
|
|
|
"slave-read-only" => "yes", |
|
132
|
|
|
|
|
|
|
"slave-serve-stale-data" => "yes", |
|
133
|
|
|
|
|
|
|
"slowlog-log-slower-than" => 10000, |
|
134
|
|
|
|
|
|
|
"slowlog-max-len" => 128, |
|
135
|
|
|
|
|
|
|
"stop-writes-on-bgsave-error" => "yes", |
|
136
|
|
|
|
|
|
|
"tcp-backlog" => 511, |
|
137
|
|
|
|
|
|
|
"tcp-keepalive" => 0, |
|
138
|
|
|
|
|
|
|
"timeout" => 0, |
|
139
|
|
|
|
|
|
|
"zset-max-ziplist-entries" => 128, |
|
140
|
|
|
|
|
|
|
"zset-max-ziplist-value" => 64, |
|
141
|
|
|
|
|
|
|
}; |
|
142
|
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
my @lines = (); |
|
144
|
0
|
|
|
|
|
|
for my $k (keys %$params) { |
|
145
|
0
|
0
|
|
|
|
|
if (ref($params->{$k}) eq 'ARRAY') { |
|
146
|
0
|
|
|
|
|
|
for my $this (@{$params->{$k}}) { |
|
|
0
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
push @lines, "$k $this"; |
|
148
|
|
|
|
|
|
|
} |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
else { |
|
151
|
0
|
|
|
|
|
|
push @lines, "$k ".$params->{$k}; |
|
152
|
|
|
|
|
|
|
} |
|
153
|
|
|
|
|
|
|
} |
|
154
|
|
|
|
|
|
|
|
|
155
|
0
|
0
|
|
|
|
|
my $ft = Metabrik::File::Text->new_from_brik_init($self) or return; |
|
156
|
0
|
|
|
|
|
|
$ft->append(0); |
|
157
|
0
|
|
|
|
|
|
$ft->overwrite(1); |
|
158
|
0
|
0
|
|
|
|
|
$ft->write(\@lines, $conf_file) or return; |
|
159
|
|
|
|
|
|
|
|
|
160
|
0
|
|
|
|
|
|
return $conf_file; |
|
161
|
|
|
|
|
|
|
} |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
# |
|
164
|
|
|
|
|
|
|
# redis-server --port 9999 --slaveof 127.0.0.1 6379 |
|
165
|
|
|
|
|
|
|
# redis-server /etc/redis/6379.conf --loglevel debug |
|
166
|
|
|
|
|
|
|
# |
|
167
|
|
|
|
|
|
|
sub start { |
|
168
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
169
|
0
|
|
|
|
|
|
my ($port, $listen) = @_; |
|
170
|
|
|
|
|
|
|
|
|
171
|
0
|
0
|
|
|
|
|
if ($self->status) { |
|
172
|
0
|
|
|
|
|
|
return $self->info_process_is_running; |
|
173
|
|
|
|
|
|
|
} |
|
174
|
|
|
|
|
|
|
|
|
175
|
0
|
|
0
|
|
|
|
$port ||= $self->port; |
|
176
|
0
|
|
0
|
|
|
|
$listen ||= $self->listen; |
|
177
|
|
|
|
|
|
|
|
|
178
|
0
|
|
|
|
|
|
my $conf_file = $self->conf_file; |
|
179
|
0
|
0
|
|
|
|
|
$self->brik_help_run_file_not_found('start', $conf_file) or return; |
|
180
|
|
|
|
|
|
|
|
|
181
|
0
|
|
|
|
|
|
my $cmd = "redis-server $conf_file"; |
|
182
|
0
|
0
|
|
|
|
|
if ($port) { |
|
183
|
0
|
|
|
|
|
|
$cmd .= " --port $port"; |
|
184
|
|
|
|
|
|
|
} |
|
185
|
0
|
0
|
|
|
|
|
if ($listen) { |
|
186
|
0
|
|
|
|
|
|
$cmd .= " --bind $listen"; |
|
187
|
|
|
|
|
|
|
} |
|
188
|
0
|
0
|
|
|
|
|
if ($self->log->level > 2) { |
|
189
|
0
|
|
|
|
|
|
$cmd .= " --loglevel debug"; |
|
190
|
|
|
|
|
|
|
} |
|
191
|
|
|
|
|
|
|
|
|
192
|
0
|
|
|
|
|
|
return $self->system($cmd); |
|
193
|
|
|
|
|
|
|
} |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub stop { |
|
196
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
197
|
|
|
|
|
|
|
|
|
198
|
0
|
0
|
|
|
|
|
if (! $self->status) { |
|
199
|
0
|
|
|
|
|
|
return $self->info_process_is_not_running; |
|
200
|
|
|
|
|
|
|
} |
|
201
|
|
|
|
|
|
|
|
|
202
|
0
|
|
|
|
|
|
my $pidfile = $self->pidfile; |
|
203
|
|
|
|
|
|
|
|
|
204
|
0
|
|
|
|
|
|
return $self->kill_from_pidfile($pidfile); |
|
205
|
|
|
|
|
|
|
} |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
sub status { |
|
208
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
209
|
|
|
|
|
|
|
|
|
210
|
0
|
|
|
|
|
|
my $pidfile = $self->pidfile; |
|
211
|
|
|
|
|
|
|
|
|
212
|
0
|
0
|
|
|
|
|
if ($self->is_running_from_pidfile($pidfile)) { |
|
213
|
0
|
|
|
|
|
|
$self->verbose_process_is_running; |
|
214
|
0
|
|
|
|
|
|
return 1; |
|
215
|
|
|
|
|
|
|
} |
|
216
|
|
|
|
|
|
|
|
|
217
|
0
|
|
|
|
|
|
$self->verbose_process_is_not_running; |
|
218
|
0
|
|
|
|
|
|
return 0; |
|
219
|
|
|
|
|
|
|
} |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
1; |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
__END__ |