redisutil_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package redis
  2. import (
  3. "log"
  4. "testing"
  5. "time"
  6. )
  7. func Test_redis(t *testing.T) {
  8. InitRedis("192.168.3.142:6379,192.168.3.142:7379")
  9. log.Println(PutKV("key-BBB", "v-oooo"))
  10. log.Println(GetStr("", "key-BBB"))
  11. log.Println(PutCKV("code-K", "key-BBB2", 123))
  12. log.Println(GetInt("code-K", "key-BBB2"))
  13. log.Println(Put("codeA", "BBB", "oooo", 0))
  14. //log.Println(Del("codeA", "AAA"))
  15. log.Println(GetStr("codeA", "AAA"))
  16. log.Println(Put("code", "Key", &map[string]string{"name": "张三"}, 0))
  17. log.Println(Get("code", "Key"))
  18. }
  19. func Test_redisMorePut(t *testing.T) {
  20. //by := []byte("dddddddddddd555d")
  21. //InitRedis("enterprise=192.168.3.14:1379,service=192.168.3.14:2379,other=192.168.3.14:3379")
  22. InitRedis("sso=192.168.3.14:1379")
  23. //PutBytes("enterprise", "A", &by, 0)
  24. //Put("sso", "new_1070776706", "obEpLuMMDUYUM-zlzCbQ0MbuQOzc", 180)
  25. Put("sso", "1903540616", "oJULtwzXo6EFV1Ah-XeyRBimXGM8", 180)
  26. //log.Println(Get("enterprise", "A"))
  27. //GetMoreKey("ent*")
  28. }
  29. func Test_other(t *testing.T) {
  30. //s := `[{"S_remark":"kokopkopkop","s_pic":"/upload/2015/10/16/2015101611194101018681.jpg","o_extend":{"k1":"ioio","k7":"000"}}]`
  31. //mo := []map[string]interface{}{}
  32. //json.Unmarshal([]byte(s), &mo)
  33. //log.Println(mo)
  34. pools := make(chan bool, 1)
  35. pool := make(chan bool, 2)
  36. for i := 0; i < 1000; i++ {
  37. go func(i int) {
  38. pool <- true
  39. defer func() {
  40. <-pool
  41. }()
  42. log.Println("--", i)
  43. time.Sleep(5 * time.Millisecond)
  44. }(i)
  45. }
  46. <-pools
  47. }
  48. func TestIncr(t *testing.T) {
  49. InitRedis("sso=192.168.3.14:1379")
  50. log.Println(Incr("sso", "user"))
  51. }