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

Merge redis 5.0 support #1

Merged
merged 3 commits into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# redis-migrate-tool

**redis-migrate-tool** is a convenient and useful tool for migrating data between [redis](https://github.com/antirez/redis).
**redis-migrate-tool** is a convenient and useful tool for migrating data between [redis](https://github.com/antirez/redis). it has supported redis 5.0 rdb format v9.

## [中文介绍](http://www.oschina.net/p/redis-migrate-tool)

Expand Down
33 changes: 29 additions & 4 deletions src/rmt_redis.c
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 8
#define REDIS_RDB_VERSION 9

/* 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 @@ -81,6 +81,9 @@
#define rdbIsObjectType(t) ((t >= 0 && t <= 4) || (t >= 9 && t <= 13))

/* Special RDB opcodes (saved/loaded with rdbSaveType/rdbLoadType). */
#define REDIS_RDB_OPCODE_MODULE_AUX 247
#define REDIS_RDB_OPCODE_IDLE 248
#define REDIS_RDB_OPCODE_FREQ 249
#define REDIS_RDB_OPCODE_AUX 250
#define REDIS_RDB_OPCODE_RESIZEDB 251
#define REDIS_RDB_OPCODE_EXPIRETIME_MS 252
Expand Down Expand Up @@ -6462,6 +6465,7 @@ int redis_parse_rdb_file(redis_node *srnode, int mbuf_count_one_time)
struct array *value;
int data_type;
int mbuf_count, mbuf_count_max;
long long lfu_freq, lru_idle;

ASSERT(rdb->type == REDIS_RDB_TYPE_FILE);

Expand Down Expand Up @@ -6501,7 +6505,7 @@ int redis_parse_rdb_file(redis_node *srnode, int mbuf_count_one_time)

rdb->rdbver = rmt_atoi(buf+len, 4);
if (rdb->rdbver < 1 || rdb->rdbver > REDIS_RDB_VERSION) {
log_error("ERROR: Can't handle RDB format version %d",
log_error("ERROR: Can't handle RDB format filename:%s version %d",
rdb->fname, rdb->rdbver);
goto error;
}
Expand Down Expand Up @@ -6551,7 +6555,25 @@ int redis_parse_rdb_file(redis_node *srnode, int mbuf_count_one_time)
}

expiretime_type = RMT_TIME_MILLISECOND;
} else if (type == REDIS_RDB_OPCODE_EOF) {
} else if (type == REDIS_RDB_OPCODE_FREQ) {
uint8_t byte = 0;
if (redis_rdb_file_read(rdb, &byte, 1) != RMT_OK) {
log_error("ERROR: redis rdb file:%s read freq error", rdb->fname);
goto eoferr;
}

lfu_freq = byte;
continue;
} else if (type == REDIS_RDB_OPCODE_IDLE) {
uint64_t qword;
if ((qword = redis_rdb_file_load_len(rdb, NULL)) == REDIS_RDB_LENERR) {
log_error("ERROR: redis rdb file:%s read idle error", rdb->fname);
goto eoferr;
}

lru_idle = qword;
continue;
} else if (type == REDIS_RDB_OPCODE_EOF) {
break;
} else if (type == REDIS_RDB_OPCODE_SELECTDB) {
if ((dbid = redis_rdb_file_load_len(rdb, NULL))
Expand Down Expand Up @@ -6588,7 +6610,10 @@ int redis_parse_rdb_file(redis_node *srnode, int mbuf_count_one_time)
sdsfree(auxkey);
sdsfree(auxval);
continue;
}
} else if (type == REDIS_RDB_OPCODE_MODULE_AUX) {
//redis has only checkmode now
continue;
}

if ((key = redis_rdb_file_load_str(rdb)) == NULL) {
log_error("ERROR: redis rdb file %s read key error",
Expand Down