Skip to content

Commit

Permalink
Merge remote-tracking branch 'piki/unstable' into fix-type.tcl-quit.tcl
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyuecai committed Jul 31, 2024
2 parents 48d1a5a + 7c6c27e commit ab864d3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/base_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,16 @@ void BaseCmd::Execute(PClient* client) {
if (!HasFlag(kCmdFlagsExclusive)) {
PSTORE.GetBackend(dbIndex)->LockShared();
}
DEFER {
if (!HasFlag(kCmdFlagsExclusive)) {
PSTORE.GetBackend(dbIndex)->UnLockShared();
}
};

if (!DoInitial(client)) {
return;
}
DoCmd(client);

if (!HasFlag(kCmdFlagsExclusive)) {
PSTORE.GetBackend(dbIndex)->UnLockShared();
}
}

std::string BaseCmd::ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum,
Expand Down
3 changes: 2 additions & 1 deletion src/storage/src/redis_hashes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ Status Redis::HIncrby(const Slice& key, const Slice& field, int64_t value, int64
batch->Put(kMetaCF, base_meta_key.Encode(), meta_value);
HashesDataKey hashes_data_key(key, version, field);
Int64ToStr(value_buf, 32, value);
batch->Put(kHashesDataCF, hashes_data_key.Encode(), value_buf);
BaseDataValue internal_value(value_buf);
batch->Put(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/hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,27 @@ var _ = Describe("Hash", Ordered, func() {
Expect(length.Val()).To(Equal(int64(len("hello1"))))
})

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("HIncrbyFloat", func() {
hSet := client.HSet(ctx, "hash", "field", "10.50")
Expect(hSet.Err()).NotTo(HaveOccurred())
Expand Down

0 comments on commit ab864d3

Please sign in to comment.