Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support RDB version 8 (for Redis version 4.x) and the new RDB data ty… #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion src/rmt_redis.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

/* The current RDB version. When the format changes in a way that is no longer
* backward compatible this number gets incremented. */
#define REDIS_RDB_VERSION 7
#define REDIS_RDB_VERSION 8

/* Defines related to the dump file format. To store 32 bits lengths for short
* keys requires a lot of space, so we check the most significant 2 bits of
Expand Down Expand Up @@ -66,6 +66,7 @@
#define REDIS_RDB_TYPE_SET 2
#define REDIS_RDB_TYPE_ZSET 3
#define REDIS_RDB_TYPE_HASH 4
#define REDIS_RDB_TYPE_ZSET2 5

/* Object types for encoded objects. */
#define REDIS_RDB_TYPE_HASH_ZIPMAP 9
Expand Down Expand Up @@ -5832,6 +5833,18 @@ static sds redis_rdb_file_load_double_str(redis_rdb *rdb) {
}
}

static sds redis_rdb_file_load_binary_double_str(redis_rdb *rdb) {
char dbuf[128];
int dlen;
double d;
if (redis_rdb_file_read(rdb,&d,sizeof(d)) != RMT_OK) return NULL;
memrev64ifbe(num);

dlen = snprintf(dbuf,sizeof(dbuf),"%.17g",d);

return sdsnewlen(dbuf, dlen);
}

static sds redis_rdb_file_load_lzf_str(redis_rdb *rdb) {
unsigned int len, clen;
unsigned char *c = NULL;
Expand Down Expand Up @@ -5955,6 +5968,28 @@ static struct array *redis_rdb_file_load_value(redis_rdb *rdb, int rdbtype)
goto error;
}

str = array_push(value);
*str = elem2;
ASSERT(sdsIsNum(*str) == 1);
str = array_push(value);
*str = elem1;
}
}else if (rdbtype == REDIS_RDB_TYPE_ZSET2) {
if ((len = redis_rdb_file_load_len(rdb,NULL)) == REDIS_RDB_LENERR) goto error;

value = redis_value_create((uint32_t)(2*len));
if (value == NULL) {
log_error("ERROR: Out of memory");
goto error;
}

while(len--) {
if ((elem1 = redis_rdb_file_load_str(rdb)) == NULL) goto error;
if ((elem2 = redis_rdb_file_load_binary_double_str(rdb)) == NULL) {
sdsfree(elem1);
goto error;
}

str = array_push(value);
*str = elem2;
ASSERT(sdsIsNum(*str) == 1);
Expand Down Expand Up @@ -6208,6 +6243,7 @@ static int redis_object_type_get_by_rdbtype(int dbtype)
return REDIS_SET;
break;
case REDIS_RDB_TYPE_ZSET:
case REDIS_RDB_TYPE_ZSET2:
case REDIS_RDB_TYPE_ZSET_ZIPLIST:

return REDIS_ZSET;
Expand Down