redis操作
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
996 B

  1. package redis
  2. import (
  3. "strconv"
  4. "testing"
  5. // "time"
  6. )
  7. var succ []int
  8. func Test_Watch(t *testing.T) {
  9. var key string = "tttttt"
  10. // var tx *Tx
  11. var count int
  12. for i := 0; i < 100000; i++ {
  13. // t.Log(i)
  14. go func(i int) {
  15. // t.Log(i)
  16. tx, err := NewTx()
  17. // t.Log(tx, err)
  18. if err == nil {
  19. reply, err := tx.Watch(key)
  20. // t.Log("watch:", reply, err)
  21. count_str, err := Get(key)
  22. count, _ = strconv.Atoi(count_str)
  23. // t.Log("count:", count, err)
  24. reply, err = tx.Multi()
  25. // t.Log("Multi:", reply, err)
  26. if count > 0 && err == nil {
  27. // t.Log("start decr,", i)
  28. reply, err = tx.Decr(key)
  29. // t.Log("Decr:", reply, err)
  30. reply, err = tx.Exec()
  31. // t.Log("Exec:", exec_reply, err, i)
  32. if err == nil && reply != nil {
  33. // reply, err = HSet("succ", i, i)
  34. succ = append(succ, i)
  35. t.Log("succ:", i, succ)
  36. }
  37. }
  38. err = tx.Close()
  39. // t.Log("Close:", err)
  40. }
  41. }(i)
  42. }
  43. t.Log(succ)
  44. }