|
1 |
| -# redis-rdb # |
2 |
| - |
3 |
| -This library provides a set of modules and classes that make it easy to handle binary |
4 |
| -database dumps generated by [Redis](http://redis.io) (.rdb files) in Ruby. |
5 |
| - |
6 |
| -Currently redis-rdb allows developers to read .rdb files in a streamable flashion |
7 |
| -with `RDB::Reader` by providing a set of callbacks. Database objects can optionally |
8 |
| -be filtered by database / key / type using custom filters. |
9 |
| - |
10 |
| -```ruby |
11 |
| -require 'rdb' |
12 |
| - |
13 |
| -class MyCallbacks |
14 |
| - include RDB::ReaderCallbacks |
15 |
| - |
16 |
| - KEY_SELECTOR = Regexp.compile(/user:\d+/) |
17 |
| - |
18 |
| - def accept_object?(state) |
19 |
| - state.database == 15 && KEY_SELECTOR.match(state.key) |
20 |
| - end |
21 |
| - |
22 |
| - def set(key, value, state) |
23 |
| - puts "SET \"#{key}\" \"#{value}\"" |
24 |
| - end |
25 |
| -end |
26 |
| - |
27 |
| -RDB::Reader.read_file('dump.rdb', callbacks: MyCallbacks.new) |
28 |
| -``` |
29 |
| - |
30 |
| -For more details about the supported callbacks you can take a look at the source code in |
31 |
| -[lib/rdb/callbacks.rb](https://github.com/nrk/redis-rdb/blob/master/lib/rdb/callbacks.rb). |
32 |
| - |
33 |
| -## Additional notes and credits ## |
34 |
| - |
35 |
| -Right now there is still no documentation about the binary format of .rdb files so we used |
36 |
| -the code in [rdb.c](https://github.com/antirez/redis/blob/unstable/src/rdb.c) as the reference |
37 |
| -implementation. Credit goes also to [sripathikrishnan](https://github.com/sripathikrishnan), |
38 |
| -his work on the [redis-rdb-tools](https://github.com/sripathikrishnan/redis-rdb-tools) Python |
39 |
| -library was quite an inspiration for the final design of `RDB::Reader` and we also reused the |
40 |
| -.rdb files shipped with his project for testing. |
41 |
| - |
42 |
| -## Dependencies ## |
43 |
| -- Ruby >= 1.9.0 |
44 |
| - |
45 |
| -## Links ## |
46 |
| - |
47 |
| -### Project ### |
48 |
| -- [Source code](https://github.com/nrk/redis-rdb/) |
49 |
| -- [Issue tracker](https://github.com/nrk/redis-rdb/issues) |
50 |
| - |
51 |
| -### Related ### |
52 |
| -- [Redis](http://redis.io/) |
53 |
| -- [redis-rdb-tools](https://github.com/sripathikrishnan/redis-rdb-tools) (Python) |
54 |
| - |
55 |
| -## Author ## |
56 |
| - |
57 |
| -- [Daniele Alessandri ](mailto:[email protected]) ( [twitter ](http://twitter.com/JoL1hAHN)) |
58 |
| - |
59 |
| -## License ## |
60 |
| - |
61 |
| -The code for redis-rdb is distributed under the terms of the MIT license (see LICENSE). |
| 1 | +# redis-rdb # |
| 2 | + |
| 3 | +This library provides a set of modules and classes that make it easy to handle binary |
| 4 | +database dumps generated by [Redis](http://redis.io) (.rdb files) in Ruby. |
| 5 | + |
| 6 | +Currently redis-rdb allows developers to read .rdb files in a streamable flashion |
| 7 | +with `RDB::Reader` by providing a set of callbacks. Database objects can optionally |
| 8 | +be filtered by database / key / type using custom filters. |
| 9 | + |
| 10 | +```ruby |
| 11 | +require 'rdb' |
| 12 | + |
| 13 | +class MyCallbacks |
| 14 | + include RDB::ReaderCallbacks |
| 15 | + |
| 16 | + KEY_SELECTOR = Regexp.compile(/user:\d+/) |
| 17 | + |
| 18 | + def accept_object?(state) |
| 19 | + state.database == 15 && KEY_SELECTOR.match(state.key) |
| 20 | + end |
| 21 | + |
| 22 | + def set(key, value, state) |
| 23 | + puts "SET \"#{key}\" \"#{value}\"" |
| 24 | + end |
| 25 | +end |
| 26 | + |
| 27 | +RDB::Reader.read_file('dump.rdb', callbacks: MyCallbacks.new) |
| 28 | +``` |
| 29 | + |
| 30 | +For more details about the supported callbacks you can take a look at the source code in |
| 31 | +[lib/rdb/callbacks.rb](https://github.com/nrk/redis-rdb/blob/master/lib/rdb/callbacks.rb). |
| 32 | + |
| 33 | +## Additional notes and credits ## |
| 34 | + |
| 35 | +Right now there is still no documentation about the binary format of .rdb files so we used |
| 36 | +the code in [rdb.c](https://github.com/antirez/redis/blob/unstable/src/rdb.c) as the reference |
| 37 | +implementation. Credit goes also to [sripathikrishnan](https://github.com/sripathikrishnan), |
| 38 | +his work on the [redis-rdb-tools](https://github.com/sripathikrishnan/redis-rdb-tools) Python |
| 39 | +library was quite an inspiration for the final design of `RDB::Reader` and we also reused the |
| 40 | +.rdb files shipped with his project for testing. |
| 41 | + |
| 42 | +## Dependencies ## |
| 43 | +- Ruby >= 1.9.0 |
| 44 | + |
| 45 | +## Links ## |
| 46 | + |
| 47 | +### Project ### |
| 48 | +- [Source code](https://github.com/nrk/redis-rdb/) |
| 49 | +- [Issue tracker](https://github.com/nrk/redis-rdb/issues) |
| 50 | + |
| 51 | +### Related ### |
| 52 | +- [Redis](http://redis.io/) |
| 53 | +- [redis-rdb-tools](https://github.com/sripathikrishnan/redis-rdb-tools) (Python) |
| 54 | + |
| 55 | +## Author ## |
| 56 | + |
| 57 | +- [Daniele Alessandri ](mailto:[email protected]) ( [twitter ](http://twitter.com/JoL1hAHN)) |
| 58 | + |
| 59 | +## License ## |
| 60 | + |
| 61 | +The code for redis-rdb is distributed under the terms of the MIT license (see LICENSE). |
0 commit comments