redis-browser 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 37d0ff56203919cb9c9410c192224e8f2cad3ab6
4
- data.tar.gz: 5f47d5d2485446e8a6567c29bfbd57097ea48030
3
+ metadata.gz: ff6b4c9893603331bde51f11323e7db04c7a76b1
4
+ data.tar.gz: 27a55cfae0916125f1e38bc621ebdb454dc5f014
5
5
  SHA512:
6
- metadata.gz: 7278bff64d5fdba0cc39611901501745a78dac6e801ccc722a52f425c6074384acf052b544d1f1a5db78e7e231bf590093b626e446a3604dba94ea0c881c0238
7
- data.tar.gz: 6b1a36d1da3440e536d988a03b5281362b9899ae3f68d4d5fe21864f52b5bc1f3cace4c9dfa5aa91f75d08ed5ed0d9d3e47c470876f357c78694eb0d6ea4edf9
6
+ metadata.gz: 9cea07b936c42a39bc56bca4628b224edf786f66395d54fc23f306bf8900ea20267a535353caaa30b63dde1ad1cee6fdae13f2222d65322ea84ec9db8c228428
7
+ data.tar.gz: 6bdb82caef0777e9cab46455751444a5c1b800cf3109b7044f55296c8c1d179e747149d8881c62f0fb1738ce85c0424caaae728cc4c52fc817b583fedc4d9268
data/README.md CHANGED
@@ -8,6 +8,7 @@
8
8
  * Pretty print json values
9
9
  * Search keys
10
10
  * Can be mounted to Rails applications as engine
11
+ * Can connect to multiple databases
11
12
 
12
13
  ## Installation
13
14
 
@@ -23,6 +24,26 @@ $ gem install redis-browser
23
24
  $ redis-browser
24
25
  ```
25
26
 
27
+ You can predefine a list of available connections in a YAML file in couple of ways.
28
+
29
+ ```yaml
30
+ connections:
31
+ default:
32
+ url: redis://127.0.0.1:6379/0
33
+ production:
34
+ host: mydomain.com
35
+ port: 6666
36
+ db: 1
37
+ ```
38
+
39
+ Then start with
40
+
41
+ ```bash
42
+ $ redis-browser -C path/to/config.yml
43
+ ```
44
+
45
+ Run with `--help` to see what other options are available.
46
+
26
47
  ### As engine
27
48
 
28
49
  Add to gemfile
@@ -37,13 +58,20 @@ And to routes.rb
37
58
  mount RedisBrowser::Web => '/redis-browser'
38
59
  ```
39
60
 
61
+ Use `config/initializers/redis-browser.rb` to predefine a list of available connections
62
+
63
+ ```ruby
64
+ config = Rails.root.join('config', 'redis-browser.yml')
65
+ settings = YAML.load(ERB.new(IO.read(config)).result)
66
+ RedisBrowser.configure(settings)
67
+ ```
68
+
40
69
  ## Screenshots
41
70
 
42
71
  ![Browse keys](https://dl.dropboxusercontent.com/u/70986/redis-browser/2.png)
43
72
  ![See list with pagination](https://dl.dropboxusercontent.com/u/70986/redis-browser/3.png)
44
73
  ![ZSET support](https://dl.dropboxusercontent.com/u/70986/redis-browser/4.png)
45
74
  ![JSON pretty print](https://dl.dropboxusercontent.com/u/70986/redis-browser/5.png)
46
- ![Configuration](https://dl.dropboxusercontent.com/u/70986/redis-browser/6.png)
47
75
 
48
76
  ## Contributing
49
77
 
@@ -3,7 +3,34 @@
3
3
  $:.unshift File.expand_path('../../lib', File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__)
4
4
 
5
5
  require 'rubygems' unless Object.const_defined?(:Gem)
6
+ require 'optparse'
6
7
 
7
8
  require "redis-browser"
8
9
 
9
- RedisBrowser::Web.run! :port => 4569
10
+ # Sinatra runtime options
11
+ options = {
12
+ bind: '127.0.0.1',
13
+ port: 4567
14
+ }
15
+
16
+ OptionParser.new do |opts|
17
+ opts.banner = "Usage: redis-browser [options]"
18
+
19
+ opts.on("-C PATH", "--config PATH", "Path to YAML config file") do |v|
20
+ require 'yaml'
21
+ require 'erb'
22
+
23
+ config = YAML.load(ERB.new(IO.read(v)).result)
24
+ RedisBrowser.configure(config)
25
+ end
26
+
27
+ opts.on("-B ADDRESS", "--bind ADDRESS", "Server hostname or IP address to listen on") do |v|
28
+ options['bind'] = v
29
+ end
30
+
31
+ opts.on("-P PORT", "--port PORT", "Port number to listen on") do |v|
32
+ options['port'] = v
33
+ end
34
+ end.parse!
35
+
36
+ RedisBrowser::Web.run! options
@@ -0,0 +1,8 @@
1
+ connections:
2
+ localhost:
3
+ url: redis://127.0.0.1:6379/0
4
+ other:
5
+ host: 127.0.0.1
6
+ port: 6379
7
+ db: 1
8
+ url_db_1: redis://127.0.0.1:6379/1
@@ -8,3 +8,18 @@ require 'redis-browser/version'
8
8
  require 'redis-browser/browser'
9
9
  require 'redis-browser/web'
10
10
 
11
+ module RedisBrowser
12
+ DEFAULTS = {
13
+ 'connections' => {
14
+ 'default' => 'redis://127.0.0.1:6379/0'
15
+ }
16
+ }
17
+
18
+ def self.configure(opts)
19
+ Web.configure do |config|
20
+ config.set opts
21
+ end
22
+ end
23
+ end
24
+
25
+ RedisBrowser.configure RedisBrowser::DEFAULTS
@@ -1,8 +1,7 @@
1
1
  module RedisBrowser
2
2
  class Browser
3
- def initialize(conn = nil, db = 0)
3
+ def initialize(conn = {})
4
4
  @conn = conn
5
- @db = db
6
5
  end
7
6
 
8
7
  def split_key(key)
@@ -88,6 +87,7 @@ module RedisBrowser
88
87
  end
89
88
 
90
89
  def get_keys(key)
90
+ key ||= ""
91
91
  key << "*" unless key.end_with?("*")
92
92
 
93
93
  values = redis.keys(key).map do |k|
@@ -134,18 +134,7 @@ module RedisBrowser
134
134
 
135
135
  def redis
136
136
  @redis ||= begin
137
- conn = @conn || "127.0.0.1:6379"
138
- db = @db || 0
139
-
140
- opts = if conn.start_with?("/")
141
- {:path => conn}
142
- else
143
- host, port = conn.split(":", 2)
144
- {:host => host, :port => port}
145
- end
146
-
147
- r = Redis.new(opts)
148
- r.select(db)
137
+ r = Redis.new(@conn)
149
138
  r
150
139
  end
151
140
  end
@@ -0,0 +1,6 @@
1
+ pre {outline: 1px solid #e9e9e9; padding: 5px; margin: 5px; width: 100%; height:100%;}
2
+ .string { color: green; }
3
+ .number { color: darkorange; }
4
+ .boolean { color: blue; }
5
+ .null { color: magenta; }
6
+ .key { color: red; }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @license ng-prettyjson - v0.1.2
3
+ * (c) 2013 Julien VALERY https://github.com/darul75/ng-prettyjson
4
+ * License: MIT
5
+ **/
6
+
7
+ pre{outline:1px solid #e9e9e9;padding:5px;margin:5px;width:100%;height:100%}.string{color:green}.number{color:#ff8c00}.boolean{color:#00f}.null{color:#ff00ff}.key{color:red}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @license ng-prettyjson - v0.1.2
3
+ * (c) 2013 Julien VALERY https://github.com/darul75/ng-prettyjson
4
+ * License: MIT
5
+ **/
6
+ angular.module("ngPrettyJson",[]).directive("prettyJson",["ngPrettyJsonFunctions",function(a){"use strict";var b=angular.isDefined;return{restrict:"AE",scope:{json:"=",prettyJson:"="},replace:!0,template:'<div><button ng-click="edit()" ng-show="edition && !editActivated">Edit</button><button ng-click="edit()" ng-show="edition && editActivated">Cancel</button><button ng-click="update()" ng-show="editActivated && parsable">Update</button><pre id="prettyjson"></pre></div>',link:function(c,d,e){var f={},g="prettyjson",h=null;c.editActivated=!1,c.edition=e.edition;// prefer the "json" attribute over the "prettyJson" one.
7
+ // the value on the scope might not be defined yet, so look at the markup.
8
+ var i,j=b(e.json)?"json":"prettyJson",k=function(c){return b(c)?d.find("pre").html(a.syntaxHighlight(c)):d.empty()};i=c.$watch(j,function(a){// BACKWARDS COMPATIBILITY:
9
+ // if newValue is an object, and we find a `json` property,
10
+ // then stop watching on `exp`.
11
+ angular.isObject(a)&&b(a.json)?(i(),c.$watch(j+".json",function(a){k(a),f=a},!0)):(k(a),f=a)},!0);var l=function(){try{c.currentValue=JSON.parse(h.getValue()),c.parsable=!0}catch(a){c.parsable=!1}// trigger update
12
+ c.$apply(function(){})};c.edit=function(){c.editActivated?(h&&(document.getElementById(g).env=null),k(f)):(h=ace.edit(g),h.on("change",l),h.getSession().setMode("ace/mode/json")),c.editActivated=!c.editActivated},c.update=function(){c.$emit("json-updated",c.newValue)}}}}]).factory("ngPrettyJsonFunctions",function(){// cache some regular expressions
13
+ var a={entities:/((&)|(<)|(>))/g,json:/"(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|(null))\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g},b=["&amp;","&lt;","&gt;"],c=["number","string","key","boolean","null"],d=function(){var a=arguments.length-2;do a--;while(!arguments[a]);return a},e=function(a){var b;// the final two arguments are the length, and the entire string itself;
14
+ // we don't care about those.
15
+ if(arguments.length<7)throw new Error("markup() must be called from String.prototype.replace()");return b=d.apply(null,arguments),'<span class="'+c[b]+'">'+a+"</span>"},f=function(){var a;if(arguments.length<5)throw new Error("makeEntities() must be called from String.prototype.replace()");return a=d.apply(null,arguments),b[a-2]},g=function(b){return angular.isString(b)||(b=JSON.stringify(b,null,2)),angular.isDefined(b)?b.replace(a.entities,f).replace(a.json,e):void 0};return{syntaxHighlight:g,makeEntities:f,markup:e,rx:a}});
@@ -19,8 +19,8 @@ app.factory 'HttpLoader', ['$q', ($q) ->
19
19
  ]
20
20
 
21
21
  app.factory 'API', ['$http', ($http) ->
22
- (connection, database) ->
23
- ps = {connection: connection, database: database}
22
+ (connection) ->
23
+ ps = {connection: connection}
24
24
  {
25
25
  ping: () -> $http.get("#{jsEnv.root_path}ping.json", {
26
26
  params: ps
@@ -59,14 +59,14 @@ app.factory 'API', ['$http', ($http) ->
59
59
  $scope.keys = []
60
60
  $scope.key = {type: "empty"}
61
61
  $scope.list = {}
62
+ $scope.connections = jsEnv.connections
63
+ $scope.config = {connection: jsEnv.connection}
62
64
 
63
65
  db = localStorageService
64
66
 
65
67
  $scope.config =
66
- connection: db.get("connection") || "127.0.0.1:6379"
67
- database: parseInt(db.get("database")) || 0
68
+ connection: db.get("connection") || $scope.config.connection
68
69
  hashView: db.get("hashView") || "table"
69
- databases: [0..15]
70
70
 
71
71
  open: ->
72
72
  $scope.config.show = true
@@ -76,12 +76,11 @@ app.factory 'API', ['$http', ($http) ->
76
76
  # Check connection
77
77
  $scope.config.error = null
78
78
 
79
- test = API($scope.config.connection, $scope.config.database)
79
+ test = API($scope.config.connection)
80
80
  test.ping().then (resp) ->
81
81
  if resp.ok
82
82
  db.add("connection", $scope.config.connection)
83
- db.add("database", $scope.config.database)
84
- $scope.api = API($scope.config.connection, $scope.config.database)
83
+ $scope.api = API($scope.config.connection)
85
84
 
86
85
  $scope.fetchKeys()
87
86
  $scope.show($scope.key)
@@ -98,7 +97,7 @@ app.factory 'API', ['$http', ($http) ->
98
97
  backdropFade: true
99
98
  dialogFade: true
100
99
 
101
- $scope.api = API($scope.config.connection, $scope.config.database)
100
+ $scope.api = API($scope.config.connection)
102
101
 
103
102
 
104
103
  # Scope functions
@@ -41,18 +41,7 @@ html ng-app="browser"
41
41
  .control-group
42
42
  label.control-label for="config-connection" Connection
43
43
  .controls
44
- input type="text" id="config-connection" ng-model="config.connection"
45
- span.help-block
46
- | Examples:
47
- code 127.0.0.1:6379
48
- | ,
49
- code= "/tmp/redis.sock"
50
- | etc.
51
-
52
- .control-group
53
- label.control-label for="config-database" Database
54
- .controls
55
- select id="config-database" ng-model="config.database" ng-options="i for i in config.databases"
44
+ select id="config-connection" ng-model="config.connection" ng-options="name as name for (name, opts) in connections" ng-required="required"
56
45
 
57
46
  .modal-footer
58
47
  span.alert.alert-error.pull-left ng-show="config.error"
@@ -74,8 +63,6 @@ html ng-app="browser"
74
63
  ' Connected to
75
64
  strong
76
65
  ' {{ config.connection }}
77
- small
78
- ' ({{ config.database }})
79
66
 
80
67
 
81
68
  .container-fluid
@@ -1,3 +1,3 @@
1
1
  module RedisBrowser
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -6,7 +6,9 @@ module RedisBrowser
6
6
 
7
7
  def js_env
8
8
  jsEnv = {
9
- root_path: "#{root_path}"
9
+ root_path: root_path,
10
+ connections: settings.connections,
11
+ connection: params[:connection] || settings.connections.keys.first
10
12
  }
11
13
 
12
14
  "jsEnv = #{MultiJson.dump(jsEnv)};"
@@ -50,12 +52,9 @@ module RedisBrowser
50
52
  end
51
53
 
52
54
  def browser
53
- connection = if ENV['REDIS_URL']
54
- ENV['REDIS_URL'].sub(/\Aredis:\/\//, '')
55
- else
56
- params[:connection]
57
- end
58
- @browser ||= Browser.new(connection, params[:database])
55
+ conn = settings.connections[params[:connection]]
56
+ conn = {url: conn} unless conn.is_a?(Hash)
57
+ @browser ||= Browser.new(conn)
59
58
  end
60
59
  end
61
60
  end
metadata CHANGED
@@ -1,139 +1,139 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-browser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tymon Tobolski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-05 00:00:00.000000000 Z
11
+ date: 2014-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: sinatra
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: sinatra-contrib
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: slim
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: sass
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: coffee-script
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: multi_json
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - '>='
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - '>='
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: redis
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - '>='
129
+ - - ">="
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - '>='
136
+ - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  description: Redis browser
@@ -144,20 +144,24 @@ executables:
144
144
  extensions: []
145
145
  extra_rdoc_files: []
146
146
  files:
147
- - .gitignore
147
+ - ".gitignore"
148
148
  - Gemfile
149
149
  - LICENSE.txt
150
150
  - README.md
151
151
  - Rakefile
152
152
  - bin/redis-browser
153
+ - config.yml
153
154
  - lib/redis-browser.rb
154
155
  - lib/redis-browser/browser.rb
155
156
  - lib/redis-browser/public/css/app.css
156
157
  - lib/redis-browser/public/css/bootstrap.min.css
158
+ - lib/redis-browser/public/css/ng-prettyjson.css
159
+ - lib/redis-browser/public/css/ng-prettyjson.min.css
157
160
  - lib/redis-browser/public/img/glyphicons-halflings-white.png
158
161
  - lib/redis-browser/public/img/glyphicons-halflings.png
159
162
  - lib/redis-browser/public/js/angular.min.js
160
163
  - lib/redis-browser/public/js/localStorageModule.js
164
+ - lib/redis-browser/public/js/ng-prettyjson.min.js
161
165
  - lib/redis-browser/public/js/ui-bootstrap-tpls-0.2.0.min.js
162
166
  - lib/redis-browser/templates/coffee/app.coffee
163
167
  - lib/redis-browser/templates/index.slim
@@ -174,17 +178,17 @@ require_paths:
174
178
  - lib
175
179
  required_ruby_version: !ruby/object:Gem::Requirement
176
180
  requirements:
177
- - - '>='
181
+ - - ">="
178
182
  - !ruby/object:Gem::Version
179
183
  version: '0'
180
184
  required_rubygems_version: !ruby/object:Gem::Requirement
181
185
  requirements:
182
- - - '>='
186
+ - - ">="
183
187
  - !ruby/object:Gem::Version
184
188
  version: '0'
185
189
  requirements: []
186
190
  rubyforge_project:
187
- rubygems_version: 2.1.11
191
+ rubygems_version: 2.2.2
188
192
  signing_key:
189
193
  specification_version: 4
190
194
  summary: Redis browser