diff --git a/src/storage/src/redis_hashes.cc b/src/storage/src/redis_hashes.cc index 03a3c1c9b8..9193dddd1c 100644 --- a/src/storage/src/redis_hashes.cc +++ b/src/storage/src/redis_hashes.cc @@ -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(); diff --git a/tests/integration/hash_test.go b/tests/integration/hash_test.go index cf9448f75e..0ee0dccf1b 100644 --- a/tests/integration/hash_test.go +++ b/tests/integration/hash_test.go @@ -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())