Class: Redish::Application
- Inherits:
-
Object
- Object
- Redish::Application
- Defined in:
- lib/redish/application.rb
Constant Summary collapse
- COMMANDS =
[ "auth", "bgrewriteaof", "bgsave", "blpop", "brpop", "dbsize", "decr", "decrby", "del", "exists", "expire", "flushall", "flushdb", "get", "getset", "incr", "incrby", "info", "keys", "lastsave", "lindex", "llen", "lpop", "lpush", "lrange", "lrem", "lset", "ltrim", "mget", "monitor", "move", "mset", "msetnx", "quit", "randomkey", "rename", "renamenx", "rpop", "rpoplpush", "rpush", "sadd", "save", "scard", "sdiff", "sdiffstore", "select", "set", "setnx", "shutdown", "sinter", "sinterstore", "sismember", "slaveof", "smembers", "smove", "sort", "spop", "srandmember", "srem", "sunion", "sunionstore", "ttl", "type", "zadd", "zcard", "zincrby", "zrange", "zrangebyscore", "zrem", "zremrangebyscore", "zrevrange", "zscore" ].sort
- HELP =
%Q{Usage: db [num] - switch help - displays this document exit - quits redis-shell quit - quits redis-shell Available Redis commands: #{Redish::Application::COMMANDS.join ", "} }
Instance Method Summary collapse
-
#initialize(options) ⇒ Application
constructor
A new instance of Application.
- #run ⇒ Object
Constructor Details
#initialize(options) ⇒ Application
Returns a new instance of Application.
94 95 96 |
# File 'lib/redish/application.rb', line 94 def initialize() @redis = Redis.new end |
Instance Method Details
#run ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/redish/application.rb', line 98 def run info = @redis.info puts "Using Redis #{info[:redis_version]}-#{info[:arch_bits]}" setup_autocompletion loop do begin command = Readline.readline "redis> ", true command = command.chomp.split " " unless command[0].nil? if ["quit", "exit"].include?(command[0]) break elsif command[0] == "help" puts Redish::Application::HELP elsif command[0] == "db" @redis = Redis.new :db => command[1] puts "Switched to database #{command[1]}." elsif ["test"].include?(command[0]) puts "-ERR unknown command '#{command[0]}'" elsif command.length == 1 pp @redis.send(command[0].to_sym) else pp @redis.send(command[0].to_sym, *command[1..command.length]) end end rescue RuntimeError => e puts e. rescue Interrupt => e break end end end |