Skip to content

A command line tool for parsing, displaying, loading and constructing Redis RDB files.

License

Notifications You must be signed in to change notification settings

JunhongMao/rdbparser

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Readme for Rdbparser

Copr build status

  1. Why does Rdbparser exist?
  2. What is Rdbparser?
  3. Build or Install on Fedora / CentOS
  4. Build or Install on Ubuntu / Debian

Why does Rdbparser exist?

I needed a C++ library for parsing and constructiong Redis Rdb files.

There are a couple of other tools for doing this, the ones I have found are:

  1. redis-rdb-tools

  2. redis-rdb-cli

These are wonderful, but they are not something I can use in a program.

I created a document that details my understanding of the stucture of Rdb, Redis Rdb Dump Structures.

What is Rdbparser?

Rdbparser is a C++ library and command line tool for parsing, displaying, loading and constructing Redis Rdb files.

Here are some usage examples:

  1. Display the contents of a Rdb database dump in json format:
$ redis-cli xadd stream '*' loc mel temp 23
"1582154892743-0"
$ redis-cli xadd stream '*' loc sfo temp 10
"1582154901501-0"
$ redis-cli save
OK
$ sudo rdbp -f /var/lib/redis/dump.rdb -e stream
{
"stream" : {
  "entries" : [
    { "id" : "1582154892743-0", "loc" : "mel", "temp" : 23 },
    { "id" : "1582154901501-0", "loc" : "sfo", "temp" : 10 } ],
  "last_id" : "1582154901501-0",
  "num_elems" : 2,
  "num_cgroups" : 0
}
}
  1. Display the contents of a dump command, from redis-cli:
$ redis-cli hset hash aaa 10 bbb 20 ccc 30 hello world
(integer) 4
$ redis-cli dump hash | rdbp
{
"hash" : {
  "aaa" : 10,
  "bbb" : 20,
  "ccc" : 30,
  "hello" : "world"
}
}
  1. List the keys in a saved rdb.
$ redis-cli save
OK
$ sudo rdbp -f /var/lib/redis/dump.rdb -l
stream
hash
  1. Use restore command to insert dumped data into a running instance:
# deleted my keys accidentally

$ redis-cli del stream hash
(integer) 2

# restore keys from saved rdb

$ sudo rdbp -f /var/lib/redis/dump.rdb -r | redis-cli --pipe
All data transferred. Waiting for the last reply...
Last reply received from server.
errors: 0, replies: 2

# check that my keys are alive again

$ redis-cli dump stream | rdbp
{
"stream" : {
  "entries" : [
    { "id" : "1582155066471-0", "loc" : "mel", "temp" : 23 },
    { "id" : "1582155072341-0", "loc" : "sfo", "temp" : 10 } ],
  "last_id" : "1582155072341-0",
  "num_elems" : 2,
  "num_cgroups" : 0
}
}
$ redis-cli dump hash | rdbp
{
"hash" : {
  "aaa" : 10,
  "bbb" : 20,
  "ccc" : 30,
  "hello" : "world"
}
}

Build or Install on Fedora / CentOS

# Install packages needed to build and install it

$ sudo dnf install make gcc-c++ chrpath pcre2-devel liblzf-devel rpm-build

# Get the source

$ git clone https://www.github.com/injinj/rdbparser
$ cd rdbparser

# Build stuff, rdbp is usable without installing

$ make
$ ./FC30_x86_64/bin/rdbp -h
./FC30_x86_64/bin/rdbp [-e pat] [-v] [-i] [-f file]
   -e pat  : match key with glob pattern
   -v      : invert key match
   -i      : ignore key match case
   -f file : dump rdb file to read
   -m      : show meta data in json output
   -l      : list keys which match
   -r      : write restore commands for | redis-cli --pipe
default is to print json of matching data
if no file is given, will read data from stdin

# Install the rpm, which has bins, libs, include

$ make dist_rpm
$ sudo rpm -i rpmbuild/RPMS/x86_64/rdbparser-1.0.0-1.fc30.x86_64.rpm

# Show where the files are installed

$ rpmquery -ql rdbparser
/usr/bin/rdbp
/usr/include/rdbparser
/usr/include/rdbparser/glob_cvt.h
/usr/include/rdbparser/rdb_decode.h
/usr/include/rdbparser/rdb_json.h
/usr/include/rdbparser/rdb_restore.h
/usr/lib/.build-id
/usr/lib/.build-id/1f
/usr/lib/.build-id/1f/e8db66a884214828ad922a79cf818313ba9cff
/usr/lib/.build-id/4c
/usr/lib/.build-id/4c/f91176f9babf09dc3713f0405c29c1b430e2a3
/usr/lib64/librdbparser.a
/usr/lib64/librdbparser.so
/usr/lib64/librdbparser.so.1.0
/usr/lib64/librdbparser.so.1.0.0-1

# Uninstall / erase rdbparser files

$ sudo rpm -e rdbparser

Build or Install on Ubuntu / Debian

Go here: https://github.com/injinj/lzf and install that.

# Install packages needed to build and install it

$ sudo apt-get install make g++ gcc chrpath libpcre2-dev devscripts

# Get the source

$ git clone https://www.github.com/injinj/rdbparser
$ cd rdbparser

# Build stuff, rdbp is usable without installing

$ make
$ ./DEB9_x86_64/bin/rdbp -h                                                
./DEB9_x86_64/bin/rdbp [-e pat] [-v] [-i] [-f file]
   -e pat  : match key with glob pattern
   -v      : invert key match
   -i      : ignore key match case
   -f file : dump rdb file to read
   -m      : show meta data in json output
   -l      : list keys which match
   -r      : write restore commands for | redis-cli --pipe
default is to print json of matching data
if no file is given, will read data from stdin

# Install the rpm, which has bins, libs, include

$ make dist_dpkg
$ sudo dpkg -i dpkgbuild/rdbparser_1.0.0-1_amd64.deb

# Try it

$ redis-cli set k 'hello world'
OK
$ redis-cli dump k | rdbp
{
"string" : "hello world"
}

# Show where the files are installed

$ dpkg -L rdbparser
/.
/usr
/usr/bin
/usr/bin/rdbp
/usr/include
/usr/include/rdbparser
/usr/include/rdbparser/glob_cvt.h
/usr/include/rdbparser/rdb_decode.h
/usr/include/rdbparser/rdb_json.h
/usr/include/rdbparser/rdb_pcre.h
/usr/include/rdbparser/rdb_restore.h
/usr/lib
/usr/lib/librdbparser.a
/usr/lib/librdbparser.so.1.0.0-1
/usr/share
/usr/share/doc
/usr/share/doc/rdbparser
/usr/share/doc/rdbparser/changelog.Debian.gz
/usr/share/doc/rdbparser/copyright
/usr/lib/librdbparser.so
/usr/lib/librdbparser.so.1.0

# Uninstall / erase rdbparser files

$ sudo dpkg -r rdbparser

About

A command line tool for parsing, displaying, loading and constructing Redis RDB files.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 88.9%
  • Makefile 9.7%
  • CMake 1.4%