redisutil_test.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package redis
  2. import (
  3. "fmt"
  4. "log"
  5. "testing"
  6. "time"
  7. )
  8. func Test_redis(t *testing.T) {
  9. InitRedis("192.168.3.142:6379,192.168.3.142:7379")
  10. log.Println(PutKV("key-BBB", "v-oooo"))
  11. log.Println(GetStr("", "key-BBB"))
  12. log.Println(PutCKV("code-K", "key-BBB2", 123))
  13. log.Println(GetInt("code-K", "key-BBB2"))
  14. log.Println(Put("codeA", "BBB", "oooo", 0))
  15. //log.Println(Del("codeA", "AAA"))
  16. log.Println(GetStr("codeA", "AAA"))
  17. log.Println(Put("code", "Key", &map[string]string{"name": "张三"}, 0))
  18. log.Println(Get("code", "Key"))
  19. }
  20. func Test_redisMorePut(t *testing.T) {
  21. //by := []byte("dddddddddddd555d")
  22. //InitRedis("enterprise=192.168.3.14:1379,service=192.168.3.14:2379,other=192.168.3.14:3379")
  23. InitRedis("sso=192.168.3.14:1379")
  24. //PutBytes("enterprise", "A", &by, 0)
  25. //Put("sso", "new_1070776706", "obEpLuMMDUYUM-zlzCbQ0MbuQOzc", 180)
  26. Put("sso", "1903540616", "oJULtwzXo6EFV1Ah-XeyRBimXGM8", 180)
  27. //log.Println(Get("enterprise", "A"))
  28. //GetMoreKey("ent*")
  29. }
  30. func Test_other(t *testing.T) {
  31. //s := `[{"S_remark":"kokopkopkop","s_pic":"/upload/2015/10/16/2015101611194101018681.jpg","o_extend":{"k1":"ioio","k7":"000"}}]`
  32. //mo := []map[string]interface{}{}
  33. //json.Unmarshal([]byte(s), &mo)
  34. //log.Println(mo)
  35. pools := make(chan bool, 1)
  36. pool := make(chan bool, 2)
  37. for i := 0; i < 1000; i++ {
  38. go func(i int) {
  39. pool <- true
  40. defer func() {
  41. <-pool
  42. }()
  43. log.Println("--", i)
  44. time.Sleep(5 * time.Millisecond)
  45. }(i)
  46. }
  47. <-pools
  48. }
  49. func TestIncr(t *testing.T) {
  50. InitRedis("other=192.168.3.14:1379")
  51. //log.Println(GetBytes("sso", "p_share_3200000006"))
  52. Put("other", "test", "12212212", 50000)
  53. }
  54. func Test_Pop(t *testing.T) {
  55. InitRedis("sso=192.168.3.207:1601")
  56. m := "aaaa"
  57. Put("sso", "aaa", m, 1000)
  58. log.Println(Pop("sso", "aaa"))
  59. }
  60. func Test_MGET(t *testing.T) {
  61. InitRedis("sso=192.168.3.207:3378")
  62. InitRedis("sso=192.168.3.207:1711")
  63. n := 0
  64. for {
  65. n++
  66. Put("sso", fmt.Sprintf("%d_1", n), n, 3600)
  67. time.Sleep(8 * time.Second)
  68. }
  69. res := Mget("sso", []string{"pn_金业街(西自由街-虎泉路)道路建设工程"})
  70. log.Println(res)
  71. }