support msetnx in cluster by tcc pre-check hook

This commit is contained in:
finley
2025-03-23 20:44:13 +08:00
parent 5285717a2d
commit 23b70325f9
4 changed files with 139 additions and 6 deletions

View File

@@ -20,4 +20,23 @@ func TestMset(t *testing.T) {
asserts.AssertStatusReply(t, res, "OK")
res2 := execMGet(node1, c, utils.ToCmdLine("mget", "1", "2"))
asserts.AssertMultiBulkReply(t, res2, []string{"1", "2"})
}
func TestMsetNx(t *testing.T) {
id1 := "1"
id2 := "2"
nodes := core.MakeTestCluster([]string{id1, id2})
node1 := nodes[id1]
c := connection.NewFakeConn()
// 1, 2 will be routed to node1 and node2, see MakeTestCluster
res := execMSetNx(node1, c, utils.ToCmdLine("mset", "1", "1", "2", "2"))
asserts.AssertIntReply(t, res, 1)
res2 := execMGet(node1, c, utils.ToCmdLine("mget", "1", "2"))
asserts.AssertMultiBulkReply(t, res2, []string{"1", "2"})
res = execMSetNx(node1, c, utils.ToCmdLine("mset", "3", "3", "2", "2"))
asserts.AssertIntReply(t, res, 0)
core.RegisterDefaultCmd("get")
res = node1.Exec(c, utils.ToCmdLine("get", "3"))
asserts.AssertNullBulk(t, res)
}