redish 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Filip Tepper
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,18 @@
1
+ Redish
2
+ =======
3
+
4
+ Redish is a command-line shell interface for Redis.
5
+
6
+ Install
7
+ -------
8
+
9
+ gem install redish
10
+
11
+
12
+ Use
13
+ ---
14
+
15
+ All params are optional.
16
+
17
+ redish --host 127.0.0.1 --database 12 --port 1234 --password secret
18
+ >redish help
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # encoding: utf-8
4
+
5
+ require "rubygems"
6
+ require "redis"
7
+ require "pp"
8
+ require "readline"
9
+
10
+ require File.join(File.dirname(__FILE__), "..", "lib", "redish")
11
+
12
+ require "optparse"
13
+
14
+ options = {
15
+ :host => "127.0.0.1",
16
+ :port => 6379,
17
+ :db => 0
18
+ }
19
+
20
+ OptionParser.new do |opts|
21
+ opts.on("--host", "-h", "Host") { |option| options[:host] = option }
22
+ opts.on("--port", "-P", "Port") { |option| options[:port] = option.to_i }
23
+ opts.on("--database", "-db", "Database") { |option| options[:db] = option.to_i }
24
+ opts.on("--password", "-p", "Password") { |option| options[:password] = option }
25
+ end.parse!
26
+
27
+ redish = Redish::Application.new options
28
+ redish.run
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), "redish", "application")
@@ -0,0 +1,153 @@
1
+ module Redish
2
+ class Application
3
+
4
+ COMMANDS = [
5
+ "auth",
6
+ "bgrewriteaof",
7
+ "bgsave",
8
+ "blpop",
9
+ "brpop",
10
+ "dbsize",
11
+ "decr",
12
+ "decrby",
13
+ "del",
14
+ "exists",
15
+ "expire",
16
+ "flushall",
17
+ "flushdb",
18
+ "get",
19
+ "getset",
20
+ "incr",
21
+ "incrby",
22
+ "info",
23
+ "keys",
24
+ "lastsave",
25
+ "lindex",
26
+ "llen",
27
+ "lpop",
28
+ "lpush",
29
+ "lrange",
30
+ "lrem",
31
+ "lset",
32
+ "ltrim",
33
+ "mget",
34
+ "monitor",
35
+ "move",
36
+ "mset",
37
+ "msetnx",
38
+ "quit",
39
+ "randomkey",
40
+ "rename",
41
+ "renamenx",
42
+ "rpop",
43
+ "rpoplpush",
44
+ "rpush",
45
+ "sadd",
46
+ "save",
47
+ "scard",
48
+ "sdiff",
49
+ "sdiffstore",
50
+ "select",
51
+ "set",
52
+ "setnx",
53
+ "shutdown",
54
+ "sinter",
55
+ "sinterstore",
56
+ "sismember",
57
+ "slaveof",
58
+ "smembers",
59
+ "smove",
60
+ "sort",
61
+ "spop",
62
+ "srandmember",
63
+ "srem",
64
+ "sunion",
65
+ "sunionstore",
66
+ "ttl",
67
+ "type",
68
+ "zadd",
69
+ "zcard",
70
+ "zincrby",
71
+ "zrange",
72
+ "zrangebyscore",
73
+ "zrem",
74
+ "zremrangebyscore",
75
+ "zrevrange",
76
+ "zscore"
77
+ ].sort
78
+
79
+ HELP = %Q{Usage:
80
+
81
+ db [num] - switch
82
+
83
+ help - displays this document
84
+
85
+ exit - quits redis-shell
86
+ quit - quits redis-shell
87
+
88
+ Available Redis commands:
89
+
90
+ #{Redish::Application::COMMANDS.join ", "}
91
+
92
+ }
93
+
94
+ def initialize(options)
95
+ @redis = Redis.new options
96
+ end
97
+
98
+ def run
99
+ info = @redis.info
100
+ puts "Using Redis #{info[:redis_version]}-#{info[:arch_bits]}"
101
+
102
+ setup_autocompletion
103
+
104
+ loop do
105
+ begin
106
+ command = Readline.readline "redis> ", true
107
+ command = command.chomp.split " "
108
+
109
+ unless command[0].nil?
110
+ if ["quit", "exit"].include?(command[0])
111
+ break
112
+
113
+ elsif command[0] == "help"
114
+ puts Redish::Application::HELP
115
+
116
+ elsif command[0] == "db"
117
+ @redis = Redis.new :db => command[1]
118
+ puts "Switched to database #{command[1]}."
119
+
120
+ elsif ["test"].include?(command[0])
121
+ puts "-ERR unknown command '#{command[0]}'"
122
+
123
+ elsif command.length == 1
124
+ pp @redis.send(command[0].to_sym)
125
+
126
+ else
127
+ pp @redis.send(command[0].to_sym, *command[1..command.length])
128
+ end
129
+ end
130
+
131
+ rescue RuntimeError => e
132
+ puts e.message
133
+
134
+ rescue Interrupt => e
135
+ break
136
+
137
+ end
138
+ end
139
+ end
140
+
141
+
142
+ private
143
+
144
+
145
+ def setup_autocompletion
146
+ comp = proc { |s| Redish::Application::COMMANDS.grep( /^#{Regexp.escape(s)}/ ) }
147
+
148
+ Readline.completion_append_character = " "
149
+ Readline.completion_proc = comp
150
+ end
151
+
152
+ end
153
+ end
@@ -0,0 +1,5 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Redish" do
4
+ it "wants to be tested"
5
+ end
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'redish'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redish
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Filip Tepper
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-04 00:00:00 +01:00
13
+ default_executable: redish
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.9
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: redis
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.2
34
+ version:
35
+ description: Redis command-line shell
36
+ email: filip@tepper.pl
37
+ executables:
38
+ - redish
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.markdown
44
+ files:
45
+ - lib/redish.rb
46
+ - lib/redish/application.rb
47
+ - LICENSE
48
+ - README.markdown
49
+ has_rdoc: true
50
+ homepage: http://github.com/filiptepper/redish
51
+ licenses: []
52
+
53
+ post_install_message:
54
+ rdoc_options:
55
+ - --charset=UTF-8
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ version:
70
+ requirements: []
71
+
72
+ rubyforge_project:
73
+ rubygems_version: 1.3.5
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Redis command-line shell
77
+ test_files:
78
+ - spec/redish_spec.rb
79
+ - spec/spec_helper.rb