Skip to content

Commit

Permalink
fix: execute hincrby cmd more than one times after delete a field whi…
Browse files Browse the repository at this point in the history
…ch is existing (#2836)

* fix hincrby cmd

* add test for hincrby cmd
  • Loading branch information
QlQlqiqi authored Aug 2, 2024
1 parent 061edba commit 1e71ff0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
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

0 comments on commit 1e71ff0

Please sign in to comment.