Package net.whitbeck.rdbparser


package net.whitbeck.rdbparser
Provides a simple Redis RDB file parser for Java.

This library does the minimal amount of work to read entries (e.g. a new DB selector, or a key/value pair with an expire time) from an RDB file, mostly limiting itself to returning byte arrays or lists of byte arrays for keys and values. The caller is responsible for application-level decisions like how to interpret the contents of the returned byte arrays or what types of objects to instantiate from them.

For example, sorted sets and hashes are parsed as a flat list of value/score pairs and key/value pairs, respectively. Simple Redis values are parsed as a singleton. As expected, Redis lists and sets are parsed as lists of values.

Furthermore, this library performs lazy decoding of the packed encodings (ZipMap, ZipList, Hashmap as ZipList, Sorted Set as ZipList, Intset, and Quicklist) such that those are only decoded when needed. This allows the caller to efficiently skip over these entries or defer their decoding to a worker thread.

RDB files created by all versions of Redis through 7.4.x are supported (i.e., RDB versions 1 through 12). Some features, however, are not supported:

  • Modules, introduced in RDB version 8
  • Streams, introduced in RDB version 9.

If you need them, please open an issue or a pull request.

Valkey uses the same RDB format as of 8.0.x, and this library can read those as well.

Implementation is not thread safe.

As of November 2024, the most recent RDB format version is 12. The source of truth is the rdb.h file in the Redis repo. The following resources provide a good overview of the RDB format.

  • Class
    Description
    An auxiliary field contains a key value pair that holds metadata about the RDB file.
     
    This enum holds the different types of entries that the RdbParser can read from a RDB file.
    End-of-file entry.
    Key/value pair entries contain all the data associated with a given key.
    Reads entries from a Redis RDB file, one at a time.
    Resize DB entries contain information to speed up RDB loading by avoiding additional resizes and rehashing.
    DB selection entries mark the beginning of a new database in the RDB dump file.
    This enum holds the different value serialization type encountered in an RDB file.