Skip to content

Commit

Permalink
Added database option
Browse files Browse the repository at this point in the history
  • Loading branch information
jupiter committed Feb 17, 2015
1 parent 286a6e5 commit e4a670b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 17 deletions.
9 changes: 5 additions & 4 deletions bin/cli.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 21 additions & 7 deletions bin/dump.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -24,7 +24,8 @@
"optimist": ">=0.3.1"
},
"devDependencies": {
"coffee-script": ">=1.2.0"
"coffee-script": ">=1.2.0",
"findit": "1"
},
"repository": {
"type": "git",
Expand Down
6 changes: 4 additions & 2 deletions src/cli.coffee
Expand Up @@ -3,16 +3,17 @@ fs = require 'fs'
path = require 'path'
argv = require('optimist').argv
dump = require './dump'
package = JSON.parse fs.readFileSync path.normalize(__dirname+'/../package.json'), 'utf8'
pkg = JSON.parse fs.readFileSync path.normalize(__dirname+'/../package.json'), 'utf8'

# Display help if requested
if argv.help
console.log """
#{package.name} #{package.version}
#{pkg.name} #{pkg.version}
Usage: redis-dump [OPTIONS]
-h <hostname> Server hostname (default: 127.0.0.1)
-p <port> Server port (default: 6379)
-d <db> Database number (default: 0)
-f <filter> Query filter (default: *)
--convert Convert from json to redis commands
--help Output this help and exit
Expand All @@ -35,6 +36,7 @@ if argv.help
else
params =
filter: argv.f ? '*'
db: argv.d ? 0
port: argv.p ? 6379
host: argv.h ? '127.0.0.1'
format: if argv.json then 'json' else 'redis'
Expand Down
7 changes: 4 additions & 3 deletions src/dump.coffee
Expand Up @@ -5,6 +5,7 @@ redis = require 'redis'
module.exports = (params, callback) ->
params.port ?= 6379
params.host ?= '127.0.0.1'
params.db ?= '0'
params.filter ?= '*'
params.format ?= 'redis'
params.convert ?= null
Expand All @@ -28,8 +29,8 @@ class RedisDumper
return "#{value}"
else
return "'"+"#{value}".split('\\').join('\\\\').split('\'').join('\\\'')+"'"
dump: ({filter, format, convert, pretty}, callback) ->

dump: ({db, filter, format, convert, pretty}, callback) ->
keys = []
types = []
values = []
Expand All @@ -39,7 +40,7 @@ class RedisDumper
convert = JSON.parse convert
catch e
return callback e

@db.select db
run [
# Get keys matching filter
(next) =>
Expand Down

0 comments on commit e4a670b

Please sign in to comment.