https://github.com/nrk/redis-rdb
A set of utilities to handle Redis .rdb files with Ruby.
https://github.com/nrk/redis-rdb
Last synced: 3 months ago
JSON representation
A set of utilities to handle Redis .rdb files with Ruby.
- Host: GitHub
- URL: https://github.com/nrk/redis-rdb
- Owner: nrk
- License: mit
- Created: 2012-03-25T13:12:41.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2018-04-05T15:46:04.000Z (almost 8 years ago)
- Last Synced: 2025-11-12T06:19:44.781Z (4 months ago)
- Language: Ruby
- Homepage:
- Size: 269 KB
- Stars: 36
- Watchers: 4
- Forks: 9
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-redis - Redis-rdb - A set of utilities to handle Redis .rdb files with Ruby. (Ruby) (Higher level libraries and tools)
README
# redis-rdb #
This library provides a set of modules and classes that make it easy to handle binary
database dumps generated by [Redis](http://redis.io) (.rdb files) in Ruby.
Currently redis-rdb allows developers to read .rdb files in a streamable flashion
with `RDB::Reader` by providing a set of callbacks. Database objects can optionally
be filtered by database / key / type using custom filters.
```ruby
require 'rdb'
class MyCallbacks
include RDB::ReaderCallbacks
KEY_SELECTOR = Regexp.compile(/user:\d+/)
def accept_key?(state)
state.database == 15 && KEY_SELECTOR.match(state.key)
end
def set(key, value, state)
puts "SET \"#{key}\" \"#{value}\""
end
end
RDB::Reader.read_file('dump.rdb', callbacks: MyCallbacks.new)
```
For more details about the supported callbacks you can take a look at the source code in
[lib/rdb/callbacks.rb](https://github.com/nrk/redis-rdb/blob/master/lib/rdb/callbacks.rb).
### Data dumpers ###
The `RDB::Dumper` module can be used to create classes that dump the data read from an .rdb file
into a new file using a different format. An example would be to create an AOF file for Redis or
to store the data into JSON or CSV. This is an example of using `RDB::Dumpers::AOF`:
```ruby
require 'rdb'
source = 'test/rdb/database_multiple_logical_dbs.rdb'
destination = File.basename(source, '.rdb') + '.aof'
dumper = RDB::Dumpers::AOF.new(source, destination)
dumper.dump
```
A dumper really is no more than a slightly augmented version of a class defining the callbacks
for `RDB::Reader` with a few additional helper methods. You can find more about how to implement
dumpers in [lib/rdb/dumper.rb](https://github.com/nrk/redis-rdb/blob/master/lib/rdb/dumper.rb)
and [lib/rdb/dumpers/aof.rb](https://github.com/nrk/redis-rdb/blob/master/lib/rdb/dumpers/aof.rb).
## RDB file format ##
Right now there is still no official documentation about the binary format of .rdb files beside
the code in [rdb.c](https://github.com/antirez/redis/blob/unstable/src/rdb.c) as the reference
implementation.
[An unofficial](https://github.com/sripathikrishnan/redis-rdb-tools/wiki/Redis-RDB-Dump-File-Format)
but comprehensive description of the RDB format has been recently made available, but there is
still no official documentation about it beside the actual implementation that can be found in
[rdb.c](https://github.com/antirez/redis/blob/unstable/src/rdb.c).
## Additional notes and credits ##
Credit goes to [sripathikrishnan](https://github.com/sripathikrishnan) for his work on the
[redis-rdb-tools](https://github.com/sripathikrishnan/redis-rdb-tools) Python library that
proved to be quite an inspiration for the final design of `RDB::Reader`.We also reused the
.rdb files shipped with his project for testing.
## Dependencies ##
- Ruby >= 1.9.0
## Links ##
### Project ###
- [Source code](https://github.com/nrk/redis-rdb/)
- [Issue tracker](https://github.com/nrk/redis-rdb/issues)
### Related ###
- [Redis](http://redis.io/)
- [redis-rdb-tools](https://github.com/sripathikrishnan/redis-rdb-tools) (Python)
## Author ##
- [Daniele Alessandri](mailto:suppakilla@gmail.com) ([twitter](http://twitter.com/JoL1hAHN))
## License ##
The code for redis-rdb is distributed under the terms of the MIT license (see LICENSE).