package redis import ( "strconv" "testing" // "time" ) var succ []int func Test_Watch(t *testing.T) { var key string = "tttttt" // var tx *Tx var count int for i := 0; i < 100000; i++ { // t.Log(i) go func(i int) { // t.Log(i) tx, err := NewTx() // t.Log(tx, err) if err == nil { reply, err := tx.Watch(key) // t.Log("watch:", reply, err) count_str, err := Get(key) count, _ = strconv.Atoi(count_str) // t.Log("count:", count, err) reply, err = tx.Multi() // t.Log("Multi:", reply, err) if count > 0 && err == nil { // t.Log("start decr,", i) reply, err = tx.Decr(key) // t.Log("Decr:", reply, err) reply, err = tx.Exec() // t.Log("Exec:", exec_reply, err, i) if err == nil && reply != nil { // reply, err = HSet("succ", i, i) succ = append(succ, i) t.Log("succ:", i, succ) } } err = tx.Close() // t.Log("Close:", err) } }(i) } t.Log(succ) }