Skip to content

Commit 1e361a3

Browse files
committed
[ENG-2644] HMSet should not return int response for one subkey
Summary: We use a flag expect_int_response in the proto instead of number of subkeys in the array. Test Plan: redisserver-test Reviewers: amitanand Reviewed By: amitanand Subscribers: eng, kannan Differential Revision: https://phabricator.dev.yugabyte.com/D3724
1 parent c97bc3d commit 1e361a3

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

src/yb/common/redis_protocol.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ message RedisKeyValuePB {
139139

140140
// SET, SETNX, SETXX, HSET, HSETNX, LSET, MSET, HMSET, MSETNX
141141
message RedisSetRequestPB {
142+
optional bool expect_ok_response = 1 [ default = false ];
142143
optional int64 ttl = 2; // Expiry time in milliseconds.
143144
optional RedisWriteMode mode = 3 [ default = REDIS_WRITEMODE_UPSERT ];
144145
}

src/yb/docdb/doc_operation.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,8 @@ Status RedisWriteOperation::ApplySet(const DocOperationApplyData& data) {
504504
// For an HSET command (which has only one subkey), we need to read the subkey to find out
505505
// if the key already existed, and return 0 or 1 accordingly. This read is unnecessary for
506506
// HMSET and TSADD.
507-
if (kv.subkey_size() == 1 && EmulateRedisResponse(kv.type())) {
507+
if (kv.subkey_size() == 1 && EmulateRedisResponse(kv.type()) &&
508+
!request_.set_request().expect_ok_response()) {
508509
auto type = GetValueType(data, 0);
509510
RETURN_NOT_OK(type);
510511
// For HSET/TSADD, we return 0 or 1 depending on if the key already existed.

src/yb/yql/redis/redisserver/redis_parser.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ CHECKED_STATUS ParseHMSetLikeCommands(YBRedisWriteOp *op, const RedisClientComma
174174
op->mutable_request()->mutable_key_value()->set_type(type);
175175
op->mutable_request()->mutable_key_value()->set_key(args[1].cdata(), args[1].size());
176176

177+
if (type == REDIS_TYPE_HASH) {
178+
op->mutable_request()->mutable_set_request()->set_expect_ok_response(true);
179+
}
180+
177181
std::unordered_map<string, string> kv_map;
178182
for (int i = 2; i < args.size(); i += 2) {
179183
// EXPIRE_AT/EXPIRE_IN only supported for redis timeseries currently.

src/yb/yql/redis/redisserver/redisserver-test.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,9 @@ TEST_F(TestRedisService, TestTimeSeriesTTL) {
14041404
"4", "v400",
14051405
"5", "v500",
14061406
});
1407+
DoRedisTestOk(__LINE__, {"HMSET", "map_key",
1408+
"6", "v600"
1409+
});
14071410
DoRedisTestOk(__LINE__, {"SET", "key", "value"});
14081411
SyncClient();
14091412
DoRedisTestExpectError(__LINE__, {"TSRANGEBYTIME" , "map_key", "1", "5"});

0 commit comments

Comments
 (0)