Skip to content

Commit

Permalink
Support to convert sortedint type to zset type in kvrocks2redis (#431)
Browse files Browse the repository at this point in the history
Co-authored-by: Myth <caipengbo@outlook.com>
  • Loading branch information
fishery86 and caipengbo authored Dec 22, 2021
1 parent 6c8534a commit b9dc65a
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions tools/kvrocks2redis/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Status Parser::parseSimpleKV(const Slice &ns_key, const Slice &value, int expire

Status Parser::parseComplexKV(const Slice &ns_key, const Metadata &metadata) {
RedisType type = metadata.Type();
if (type < kRedisHash || type > kRedisBitmap) {
if (type < kRedisHash || type > kRedisSortedint) {
return Status(Status::NotOK, "unknown metadata type: " + std::to_string(type));
}

Expand Down Expand Up @@ -95,6 +95,11 @@ Status Parser::parseComplexKV(const Slice &ns_key, const Metadata &metadata) {
s = Parser::parseBitmapSegment(ns, user_key, index, value);
break;
}
case kRedisSortedint: {
std::string val = std::to_string(DecodeFixed64(ikey.GetSubKey().data()));
output = Rocksdb2Redis::Command2RESP({"ZADD", user_key, val, val});
break;
}
default:break; // should never get here
}
if (type != kRedisBitmap) {
Expand Down Expand Up @@ -247,8 +252,11 @@ rocksdb::Status WriteBatchExtractor::PutCF(uint32_t column_family_id, const Slic
break;
}
case kRedisSortedint: {
std::string val = std::to_string(DecodeFixed64(sub_key.data()));
if (!to_redis_) {
command_args = {"SIADD", user_key, std::to_string(DecodeFixed64(sub_key.data()))};
command_args = {"SIADD", user_key, val};
} else {
command_args = {"ZADD", user_key, val, val};
}
break;
}
Expand Down Expand Up @@ -323,9 +331,9 @@ rocksdb::Status WriteBatchExtractor::DeleteCF(uint32_t column_family_id, const S
break;
}
case kRedisSortedint: {
if (!to_redis_) {
command_args = {"SIREM", user_key, std::to_string(DecodeFixed64(sub_key.data()))};
}
std::string sub_key_str = std::to_string(DecodeFixed64(sub_key.data()));
std::string cmd_str = to_redis_ ? "ZREM" : "SIREM";
command_args = {cmd_str, user_key, sub_key_str};
break;
}
default: break;
Expand Down

0 comments on commit b9dc65a

Please sign in to comment.