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: execute hincrby cmd more than one times after delete a field which is existing #2836

Merged
merged 2 commits into from
Aug 2, 2024
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
3 changes: 2 additions & 1 deletion src/storage/src/redis_hashes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ Status Redis::HIncrby(const Slice& key, const Slice& field, int64_t value, int64
batch.Put(handles_[kMetaCF], base_meta_key.Encode(), meta_value);
HashesDataKey hashes_data_key(key, version, field);
Int64ToStr(value_buf, 32, value);
batch.Put(handles_[kHashesDataCF], hashes_data_key.Encode(), value_buf);
BaseDataValue internal_value(value_buf);
batch.Put(handles_[kHashesDataCF], hashes_data_key.Encode(), internal_value.Encode());
*ret = value;
} else {
version = parsed_hashes_meta_value.Version();
Expand Down
21 changes: 21 additions & 0 deletions tests/integration/hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,27 @@ var _ = Describe("Hash Commands", func() {
Expect(hIncrBy.Val()).To(Equal(int64(-5)))
})

It("should HIncrBy against wrong metadata", func() {
hSet := client.HSet(ctx, "hash", "key", "5")
Expect(hSet.Err()).NotTo(HaveOccurred())

hIncrBy := client.HIncrBy(ctx, "hash", "key", 1)
Expect(hIncrBy.Err()).NotTo(HaveOccurred())
Expect(hIncrBy.Val()).To(Equal(int64(6)))

hDel := client.HDel(ctx, "hash", "key")
Expect(hDel.Err()).NotTo(HaveOccurred())
Expect(hDel.Val()).To(Equal(int64(1)))

hIncrBy = client.HIncrBy(ctx, "hash", "key", 1)
Expect(hIncrBy.Err()).NotTo(HaveOccurred())
Expect(hIncrBy.Val()).To(Equal(int64(1)))

hIncrBy = client.HIncrBy(ctx, "hash", "key", 2)
Expect(hIncrBy.Err()).NotTo(HaveOccurred())
Expect(hIncrBy.Val()).To(Equal(int64(3)))
})

It("should HIncrByFloat", func() {
hSet := client.HSet(ctx, "hash", "field", "10.50")
Expect(hSet.Err()).NotTo(HaveOccurred())
Expand Down
Loading