This rdbtools now support rdb-parser and redis-counter services.
Notice:
- many files was copied from redis, like sds, zmalloc without any change, I think it's not necessary to rewrite again, but some like t_set, t_list, t_zset, just take the function which we needed, like iterator.
- This tools only tested on redis branch 2.2 & 2.4 in github, so it can't be used in redis 2.4 later.
parse rdb file to user's format data, like aof file, json etc.
rdb file parser can be used in many places, and there are too many data types in redis, also too complicated for many developers. so I write this tool to resolve it, by parsing rdb file to simple format data seems like json but difference. like below:
if type is STRING, value like "value1"
if type is SET, value is array and element type is string. like ["1", "3", "7"]
if type is LIST,value is array and element type is string. like ["a", "b", "c"]
if type is ZSET,value is array and element type is string. like ["member1", "score1", "member2", "score2"]
if type is HASH,value is array and element type is string. like ["key1", "val1", "key2", "val2"]
$ cd rdb_tools # (or rdb_tools/src)
$ make # and will be a binary file named rdb-parser in src.
$ ./rdb-parser -d -f dump.rdb # start parse
open src/main.c you can see an example callback function called userHandler, which prints data to screen. Prototype is below:
/*
* user can define handler to different data type.
* @param type: may be STRING, SET, LIST, ZSET, HASH
* if type == STRING, val is sds.
* if type == SET, val is array and element type is sds. like ["1", "3", "7"]
* if type == LIST,val is array and element type is sds. like ["a", "b", "c"]
* if type == ZSET,val is array and element type is sds. like ["member1", "score1", "member2", "score2"]
* if type == HASH,val is array and element type is sds. like ["key1", "val1", "key2", "val2"]
* @param key: key is key object in redis, it's type is sds.
* @param val: val is denpend on type.
* @ vlen, if type == STRING, vlen represent length of val string, or vlen is length of val array.
* @ expiretime, expiretime in db,if not set, expiretime = -1.
* @ return any data as you like.
*/
void* keyValueHandler(int type, void *key, void *val, unsigned int vlen, time_t expiretime);
any bugs? send mail, and I will appreciate your help.
##Introduce redis-counter works for a specified version of REDIS. It's used to analysis rdb files.
##Function redis-counter parse redis rdb file, count deleted keys, other keys and saved keys. Save key value pair into aof files.
##Format and hash Key-value format saved in aof files and hash strategy for which file current key-value pair go can be defined in this handle in main.c:
/**
* @brief _format_kv
* Format a string with key and value, the string is to be dumped in aof file.
* Define a way to get a aof file number from hashing key.
* @param key
* @param key_len
* @param value
* @param hashed_key
* Save hashed aof file number of type int.
* @return Formatted string of k&v
*/
typedef char * format_kv_handler(void * key, int key_len, long value, void *hashed_key);