Code Monkey home page Code Monkey logo

redis-rdb's Introduction

redis-rdb

This library provides a set of modules and classes that make it easy to handle binary database dumps generated by Redis (.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.

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.

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:

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 and 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 as the reference implementation.

An unofficial 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.

Additional notes and credits

Credit goes to sripathikrishnan for his work on the 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

Related

Author

License

The code for redis-rdb is distributed under the terms of the MIT license (see LICENSE).

redis-rdb's People

Contributors

nrk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.