Genuineh commented on PR #3024:
URL: https://github.com/apache/kvrocks/pull/3024#issuecomment-2975008489
@git-hulk @PragmaTwice Hi, I have a question about the string set in single
mode that why some characters miss after `AppendNamespacePrefix`
```cpp
rocksdb::Status String::Set(engine::Context &ctx, const std::string
&user_key, const std::string &value,
StringSetArgs args, std::optional<std::string>
&ret) {
uint64_t expire = 0;
info("Set key: {}, value: {}, expire: {}, type: {}, get: {}, keep_ttl:
{}", user_key, value, args.expire,
static_cast<int>(args.type), args.get, args.keep_ttl);
std::string ns_key = AppendNamespacePrefix(user_key);
info("Set key with namespace: {}, value: {}, expire: {}, type: {}, get:
{}, keep_ttl: {}", ns_key, value, args.expire,
static_cast<int>(args.type), args.get, args.keep_ttl);
bool need_old_value = args.type != StringSetType::NONE || args.get ||
args.keep_ttl;
if (need_old_value) {
std::string old_value;
uint64_t old_expire = 0;
auto s = getValueAndExpire(ctx, ns_key, &old_value, &old_expire);
if (!s.ok() && !s.IsNotFound() && !s.IsInvalidArgument()) return s;
// GET option
if (args.get) {
if (s.IsInvalidArgument()) {
return s;
}
if (s.IsNotFound()) {
// if GET option given, the key didn't exist before: return nil
ret = std::nullopt;
} else {
// if GET option given: return The previous value of the key.
ret = std::make_optional(old_value);
}
}
// NX/XX option
if (args.type == StringSetType::NX && s.ok()) {
// if NX option given, the key already exist: return nil
if (!args.get) ret = std::nullopt;
return rocksdb::Status::OK();
} else if (args.type == StringSetType::XX && s.IsNotFound()) {
// if XX option given, the key didn't exist before: return nil
if (!args.get) ret = std::nullopt;
return rocksdb::Status::OK();
} else {
// if GET option not given, make ret not nil
if (!args.get) ret = "";
}
if (s.ok() && args.keep_ttl) {
// if KEEPTTL option given, use the old ttl
expire = old_expire;
}
} else {
// if no option given, make ret not nil
if (!args.get) ret = "";
}
// Handle expire time
if (!args.keep_ttl) {
expire = args.expire;
}
// Create new value
std::string new_raw_value;
Metadata metadata(kRedisString, false);
metadata.expire = expire;
metadata.Encode(&new_raw_value);
new_raw_value.append(value);
return updateRawValue(ctx, ns_key, new_raw_value);
}
```

--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]