Class: Readis::Inspect
Constant Summary
collapse
- WHITELIST =
%w[
keys
exists get hexists hget hgetall hkeys hlen hmget hvals
info lindex llen lrange mget randomkey scard sdiff
sinter sismember smembers srandmember strlen sunion
ttl type zcard zcount zrange zrangebyscore zrank
zrevrange zrevrangebyscore zrevrank zscore
]
Instance Method Summary
collapse
Methods inherited from Readis
command_runner, #help, #options
Constructor Details
#initialize(*args) ⇒ Inspect
Returns a new instance of Inspect.
13
14
15
16
|
# File 'lib/readis/inspect.rb', line 13
def initialize(*args)
super
@redis = Redis.new(:host => self.options[:host], :port => self.options[:port])
end
|
Instance Method Details
#execute_command(input_string) ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/readis/inspect.rb', line 53
def execute_command(input_string)
parts = input_string.split(" ")
redis_command = parts.shift
if redis_command
redis_command.downcase!
end
case redis_command
when nil
when *WHITELIST
@redis.send(redis_command, *parts)
when "exit", "quit"
exit
else
raise ArgumentError, "Unknown or unsupported command"
end
end
|
#parser ⇒ Object
18
19
20
21
22
23
24
25
26
|
# File 'lib/readis/inspect.rb', line 18
def parser
optparser = super
optparser.banner = <<-BANNER
Usage: readis inspect [options]
BANNER
optparser
end
|
#run ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/readis/inspect.rb', line 28
def run
loop do
print "readis #{self.options[:host]}:#{self.options[:port]}> "
input_string = gets.chomp
begin
out = execute_command(input_string)
case out
when nil
else
puts out.inspect
end
rescue => error
puts "Error: #{error.message}"
end
end
end
|