rutil

command module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2020 License: MIT, Unlicense Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

About

rutil is a small command line utility that lets you selectively dump, restore and query a redis database, peek into stored data and pretty print json contents.

Attention!!! This code is a fork of project rutil We try to contact the initial developers: https://github.com/pampa/rutil/issues/6. Parallel to this, improvements were made to the code to be compiled with Go 1.15 and a Docker image was created to facilitate distribution and use.

Credits for:

Thanks @otavioprado for making improvements to the code to be compiled with Go 1.15 and creating the Dockerfile for easy distribution and use.

Demostration

rutil

Installation

Clone this repository with command:

git clone https://github.com/Sensedia/rutil

cd rutil

Using Docker

Install Docker following the instructions in this tutorial.

Generate new image with command:

make image

Or:

docker build -t rutil:latest .

List the Docker images:

docker images

Run a container:

docker run --rm rutil --help

More information about docker run command: https://docs.docker.com/engine/reference/run/

Compiling with go

Install Go following the instructions in this tutorial.

Compile rutil with Go:

make build

Or:

go build -o bin/rutil .

Run rutil:

./bin/rutil --help

Usage

rutil [global options] command [command options] [arguments...]

COMMANDS:
   dump      dump redis database to a file
   pipe      dump a redis database to stdout in a format compatible with | redis-cli --pipe
   restore   restore redis database from a file
   query, q  query keys matching the pattern provided by --keys
   help, h   Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --host value, -s value  redis host (default: "127.0.0.1")
   --auth value, -a value  authentication password
   --port value, -p value  redis port (default: 6379)
   --cluster, -c           redis cluster connection
   --help, -h              show help
   --version, -v           print the version

Examples

Command dump

rutil [global options] dump [command options] [arguments...]

GLOBAL OPTIONS:
   --host value, -s value  redis host (default: "127.0.0.1")
   --auth value, -a value  authentication password
   --port value, -p value  redis port (default: 6379)
   --cluster, -c           redis cluster connection
   --help, -h              show help
   --version, -v           print the version

OPTIONS:
   --keys value, -k value   keys pattern (passed to redis 'keys' command) (default: "*")
   --match value, -m value  regexp filter for key names
   --invert, -v             invert match regexp
   --auto, -a               make up a file name for the dump - redisYYYYMMDDHHMMSS.rdmp
Cluster

Make a dump of all keys of Redis cluster:

./bin/rutil -c --host 192.168.0.1 --port 6379 dump /tmp/dump_all_keys.rdmp

A file will be created /tmp/dump_all_keys.rdmp.

Or:

./bin/rutil -c --host 192.168.0.1 --port 6379 dump -a

A file will be created in the current directory with the following pattern: redisYYYYMMDDHHMMSS.rdmp.

Using Docker:

docker run --rm -v $PWD:/tmp rutil -c --host 192.168.0.1 --port 6379 dump /tmp/file2.rdmp

Or:

docker run --rm -v $PWD:/tmp rutil -c --host 192.168.0.1 --port 6379 dump -a
Node

Make a dump of all keys of Redis node (ommiting -c option):

./bin/rutil --host 192.168.0.1 --port 6379 dump /tmp/dump_all_keys.rdmp

A file will be created /tmp/dump_all_keys.rdmp.

Or:

./bin/rutil --host 192.168.0.1 --port 6379 dump -a

A file will be created in the current directory with the following pattern: redisYYYYMMDDHHMMSS.rdmp.

Using Docker (ommiting -c option):

docker run --rm -v $PWD:/tmp rutil --host 192.168.0.1 --port 6379 dump /tmp/file2.rdmp

Or:

docker run --rm -v $PWD:/tmp rutil --host 192.168.0.1 --port 6379 dump -a

Pipe

rutil [global options] pipe [command options] [arguments...]

GLOBAL OPTIONS:
   --host value, -s value  redis host (default: "127.0.0.1")
   --auth value, -a value  authentication password
   --port value, -p value  redis port (default: 6379)
   --cluster, -c           redis cluster connection
   --help, -h              show help
   --version, -v           print the version

OPTIONS:
   --keys value, -k value   keys pattern (passed to redis 'keys' command) (default: "*")
   --match value, -m value  regexp filter for key names
   --invert, -v             invert match regexp

Restore

rutil [global options] estore [command options] [arguments...]

GLOBAL OPTIONS:
   --host value, -s value  redis host (default: "127.0.0.1")
   --auth value, -a value  authentication password
   --port value, -p value  redis port (default: 6379)
   --cluster, -c           redis cluster connection
   --help, -h              show help
   --version, -v           print the version

OPTIONS:
   --dry-run, -r  pretend to restore
   --flushdb, -f  flush the database before restoring
   --delete, -d   delete key before restoring
   --ignore, -g   ignore BUSYKEY restore errors
   --stdin, -i    read dump from STDIN
Cluster

Simulate restore all keys of Redis cluster:

./bin/rutil --host 192.168.0.1 -c --port 6379 restore --dry-run /tmp/file2.rdmp

Or:

docker run --rm -v $PWD:/tmp rutil -c --host 192.168.0.1 --port 6379 restore --dry-run /tmp/file2.rdmp

Restore all keys of Redis cluster:

./bin/rutil -c --host 192.168.0.1 --port 6379 restore --flushdb /tmp/file2.rdmp

Or:

docker run --rm -v $PWD:/tmp rutil -c --host 192.168.0.1 --port 6379 restore --flushdb /tmp/file2.rdmp
Node

Simulate restore all keys of Redis node (ommiting -c option):

./bin/rutil --host 192.168.0.1 --port 6379 restore --dry-run /tmp/file2.rdmp

Or:

docker run --rm -v $PWD:/tmp rutil --host 192.168.0.1 --port 6379 restore --dry-run /tmp/file2.rdmp

Restore all keys of Redis node (ommiting -c option):

./bin/rutil --host 192.168.0.1 --port 6379 restore --flushdb /tmp/file2.rdmp

Or:

docker run --rm -v $PWD:/tmp rutil --host 192.168.0.1 --port 6379 restore --flushdb /tmp/file2.rdmp

Query

rutil [global options] query [command options] [arguments...]

GLOBAL OPTIONS:
   --host value, -s value  redis host (default: "127.0.0.1")
   --auth value, -a value  authentication password
   --port value, -p value  redis port (default: 6379)
   --cluster, -c           redis cluster connection
   --help, -h              show help
   --version, -v           print the version

OPTIONS:
   --keys value, -k value   keys pattern (passed to redis 'keys' command)
   --match value, -m value  regexp filter for key names
   --invert, -v             invert match regexp
   --delete                 delete keys
   --print, -p              print key values
   --field value, -f value  hash fields to print (default all)
   --json, -j               attempt to parse and pretty print strings as json
Cluster

List all keys in Redis cluster:

./bin/rutil -c --host 192.168.0.1 --port 6379 query --keys '*'

Or:

docker run --rm rutil -c --host 192.168.0.1 --port 6379 query --keys '*'

Make a query in Redis cluster:

./bin/rutil -c --host 192.168.0.1 --port 6379 query --keys 'testing:abcde:BOOK*'

Or:

docker run --rm rutil -c --host 192.168.0.1 --port 6379 query --keys 'testing:abcde:BOOK*'

Delete a key in Redis cluster:

./bin/rutil -c --host 192.168.0.1 --port 6379 query --keys 'testing:abcde:BOOK:55' --delete

Or:

docker run --rm rutil -c --host 192.168.0.1 --port 6379 query --keys 'testing:abcde:BOOK:55' --delete

Print value of a key in Redis cluster:

./bin/rutil -c --host 192.168.0.1 --port 6379 query --keys 'testing:abcde:BOOK:55' --print

Or:

docker run --rm rutil -c --host 192.168.0.1 --port 6379 query --keys 'testing:abcde:BOOK:55' --print

More information: https://redis.io/commands/keys

Node

List all keys in Redis node (ommiting -c option):

./bin/rutil --host 192.168.0.1 --port 6379 query --keys '*'

Or:

docker run --rm rutil --host 192.168.0.1 --port 6379 query --keys '*'

Make a query in Redis node (ommiting -c option):

./bin/rutil --host 192.168.0.1 --port 6379 query --keys 'testing:abcde:BOOK*'

Or:

docker run --rm rutil --host 192.168.0.1 --port 6379 query --keys 'testing:abcde:BOOK*'

Delete a key in Redis node (ommiting -c option):

./bin/rutil --host 192.168.0.1 --port 6379 query --keys 'testing:abcde:BOOK:55' --delete

Or:

docker run --rm rutil --host 192.168.0.1 --port 6379 query --keys 'testing:abcde:BOOK:55' --delete

Print value of a key in Redis node (ommiting -c option):

./bin/rutil --host 192.168.0.1 --port 6379 query --keys 'testing:abcde:BOOK:55' --print

Or:

docker run --rm rutil --host 192.168.0.1 --port 6379 query --keys 'testing:abcde:BOOK:55' --print

More information: https://redis.io/commands/keys

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址