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

fix: binary list key randomly droped by lrem #2118

Merged
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
10 changes: 5 additions & 5 deletions src/storage/src/redis_lists.cc
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ Status RedisLists::LInsert(const Slice& key, const BeforeOrAfter& before_or_afte
ListsDataKey start_data_key(key, version, current_index);
for (iter->Seek(start_data_key.Encode()); iter->Valid() && current_index < parsed_lists_meta_value.right_index();
iter->Next(), current_index++) {
if (strcmp(iter->value().ToString().data(), pivot.data()) == 0) {
if (iter->value() == Slice(pivot)) {
find_pivot = true;
pivot_index = current_index;
break;
Expand Down Expand Up @@ -538,7 +538,7 @@ Status RedisLists::LRem(const Slice& key, int64_t count, const Slice& value, uin
for (iter->Seek(start_data_key.Encode());
iter->Valid() && current_index <= stop_index && ((count == 0) || rest != 0);
iter->Next(), current_index++) {
if (strcmp(iter->value().ToString().data(), value.data()) == 0) {
if (iter->value() == value) {
target_index.push_back(current_index);
if (count != 0) {
rest--;
Expand All @@ -552,7 +552,7 @@ Status RedisLists::LRem(const Slice& key, int64_t count, const Slice& value, uin
for (iter->Seek(stop_data_key.Encode());
iter->Valid() && current_index >= start_index && ((count == 0) || rest != 0);
iter->Prev(), current_index--) {
if (strcmp(iter->value().ToString().data(), value.data()) == 0) {
if (iter->value() == value) {
target_index.push_back(current_index);
if (count != 0) {
rest--;
Expand All @@ -577,7 +577,7 @@ Status RedisLists::LRem(const Slice& key, int64_t count, const Slice& value, uin
rocksdb::Iterator* iter = db_->NewIterator(default_read_options_, handles_[1]);
for (iter->Seek(sublist_right_key.Encode()); iter->Valid() && current_index >= start_index;
iter->Prev(), current_index--) {
if ((strcmp(iter->value().ToString().data(), value.data()) == 0) && rest > 0) {
if ((iter->value() == value) && rest > 0) {
rest--;
} else {
ListsDataKey lists_data_key(key, version, left--);
Expand All @@ -597,7 +597,7 @@ Status RedisLists::LRem(const Slice& key, int64_t count, const Slice& value, uin
rocksdb::Iterator* iter = db_->NewIterator(default_read_options_, handles_[1]);
for (iter->Seek(sublist_left_key.Encode()); iter->Valid() && current_index <= stop_index;
iter->Next(), current_index++) {
if ((strcmp(iter->value().ToString().data(), value.data()) == 0) && rest > 0) {
if ((iter->value() == value) && rest > 0) {
rest--;
} else {
ListsDataKey lists_data_key(key, version, right++);
Expand Down
23 changes: 23 additions & 0 deletions tests/integration/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,29 @@ var _ = Describe("List Commands", func() {
Expect(lRange.Val()).To(Equal([]string{"hello", "key"}))
})

It("should LRem binary", func() {
rPush := client.RPush(ctx, "list", "\x00\xa2\x00")
Expect(rPush.Err()).NotTo(HaveOccurred())
rPush = client.RPush(ctx, "list", "\x00\x9d")
Expect(rPush.Err()).NotTo(HaveOccurred())

lInsert := client.LInsert(ctx, "list", "BEFORE", "\x00\x9d", "\x00\x5f")
Expect(lInsert.Err()).NotTo(HaveOccurred())
Expect(lInsert.Val()).To(Equal(int64(3)))

lRange := client.LRange(ctx, "list", 0, -1)
Expect(lRange.Err()).NotTo(HaveOccurred())
Expect(lRange.Val()).To(Equal([]string{"\x00\xa2\x00", "\x00\x5f", "\x00\x9d"}))

lRem := client.LRem(ctx, "list", -1, "\x00\x5f")
Expect(lRem.Err()).NotTo(HaveOccurred())
Expect(lRem.Val()).To(Equal(int64(1)))

lRange = client.LRange(ctx, "list", 0, -1)
Expect(lRange.Err()).NotTo(HaveOccurred())
Expect(lRange.Val()).To(Equal([]string{"\x00\xa2\x00", "\x00\x9d"}))
})

It("should LSet", func() {
rPush := client.RPush(ctx, "list", "one")
Expect(rPush.Err()).NotTo(HaveOccurred())
Expand Down