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

Use LMOVE logic to handle RPOPLPUSH #1596

Merged
merged 3 commits into from
Jul 19, 2023
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 src/commands/cmd_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ class CommandRPopLPUSH : public Commander {
Status Execute(Server *svr, Connection *conn, std::string *output) override {
redis::List list_db(svr->storage, conn->GetNamespace());
std::string elem;
auto s = list_db.RPopLPush(args_[1], args_[2], &elem);
auto s = list_db.LMove(args_[1], args_[2], /*src_left=*/false, /*dst_left=*/true, &elem);
if (!s.ok() && !s.IsNotFound()) {
return {Status::RedisExecErr, s.ToString()};
}
Expand Down
18 changes: 0 additions & 18 deletions src/types/redis_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -433,24 +433,6 @@ rocksdb::Status List::Set(const Slice &user_key, int index, Slice elem) {
return storage_->Write(storage_->DefaultWriteOptions(), batch->GetWriteBatch());
}

rocksdb::Status List::RPopLPush(const Slice &src, const Slice &dst, std::string *elem) {
RedisType type = kRedisNone;
rocksdb::Status s = Type(dst, &type);
if (!s.ok()) return s;
if (type != kRedisNone && type != kRedisList) {
return rocksdb::Status::InvalidArgument(kErrMsgWrongType);
}

s = Pop(src, false, elem);
if (!s.ok()) return s;

uint64_t ret = 0;
std::vector<Slice> elems;
elems.emplace_back(*elem);
s = Push(dst, elems, true, &ret);
return s;
}

rocksdb::Status List::LMove(const rocksdb::Slice &src, const rocksdb::Slice &dst, bool src_left, bool dst_left,
std::string *elem) {
if (src == dst) {
Expand Down
1 change: 0 additions & 1 deletion src/types/redis_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class List : public Database {
rocksdb::Status PopMulti(const Slice &user_key, bool left, uint32_t count, std::vector<std::string> *elems);
rocksdb::Status Rem(const Slice &user_key, int count, const Slice &elem, uint64_t *removed_cnt);
rocksdb::Status Index(const Slice &user_key, int index, std::string *elem);
rocksdb::Status RPopLPush(const Slice &src, const Slice &dst, std::string *elem);
rocksdb::Status LMove(const Slice &src, const Slice &dst, bool src_left, bool dst_left, std::string *elem);
rocksdb::Status Push(const Slice &user_key, const std::vector<Slice> &elems, bool left, uint64_t *new_size);
rocksdb::Status PushX(const Slice &user_key, const std::vector<Slice> &elems, bool left, uint64_t *new_size);
Expand Down
19 changes: 0 additions & 19 deletions tests/cppunit/types/list_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -314,25 +314,6 @@ TEST_F(RedisListSpecificTest, Trim) {
list_->Del(key_);
}

TEST_F(RedisListTest, RPopLPush) {
uint64_t ret = 0;
list_->Push(key_, fields_, true, &ret);
EXPECT_EQ(fields_.size(), ret);
Slice dst("test-list-rpoplpush-key");
for (auto &field : fields_) {
std::string elem;
list_->RPopLPush(key_, dst, &elem);
EXPECT_EQ(field.ToString(), elem);
}
for (auto &field : fields_) {
std::string elem;
list_->Pop(dst, false, &elem);
EXPECT_EQ(elem, field.ToString());
}
list_->Del(key_);
list_->Del(dst);
}

TEST_F(RedisListLMoveTest, LMoveSrcNotExist) {
std::string elem;
auto s = list_->LMove(key_, dst_key_, true, true, &elem);
Expand Down