package redis import ( "fmt" "log" "testing" "time" ) func Test_redis(t *testing.T) { InitRedis("192.168.3.142:6379,192.168.3.142:7379") log.Println(PutKV("key-BBB", "v-oooo")) log.Println(GetStr("", "key-BBB")) log.Println(PutCKV("code-K", "key-BBB2", 123)) log.Println(GetInt("code-K", "key-BBB2")) log.Println(Put("codeA", "BBB", "oooo", 0)) //log.Println(Del("codeA", "AAA")) log.Println(GetStr("codeA", "AAA")) log.Println(Put("code", "Key", &map[string]string{"name": "张三"}, 0)) log.Println(Get("code", "Key")) } func Test_redisMorePut(t *testing.T) { //by := []byte("dddddddddddd555d") //InitRedis("enterprise=192.168.3.14:1379,service=192.168.3.14:2379,other=192.168.3.14:3379") InitRedis("sso=192.168.3.14:1379") //PutBytes("enterprise", "A", &by, 0) //Put("sso", "new_1070776706", "obEpLuMMDUYUM-zlzCbQ0MbuQOzc", 180) Put("sso", "1903540616", "oJULtwzXo6EFV1Ah-XeyRBimXGM8", 180) //log.Println(Get("enterprise", "A")) //GetMoreKey("ent*") } func Test_other(t *testing.T) { //s := `[{"S_remark":"kokopkopkop","s_pic":"/upload/2015/10/16/2015101611194101018681.jpg","o_extend":{"k1":"ioio","k7":"000"}}]` //mo := []map[string]interface{}{} //json.Unmarshal([]byte(s), &mo) //log.Println(mo) pools := make(chan bool, 1) pool := make(chan bool, 2) for i := 0; i < 1000; i++ { go func(i int) { pool <- true defer func() { <-pool }() log.Println("--", i) time.Sleep(5 * time.Millisecond) }(i) } <-pools } func TestIncr(t *testing.T) { InitRedis("other=192.168.3.14:1379") //log.Println(GetBytes("sso", "p_share_3200000006")) Put("other", "test", "12212212", 50000) } func Test_Pop(t *testing.T) { InitRedis("sso=192.168.3.207:1601") m := "aaaa" Put("sso", "aaa", m, 1000) log.Println(Pop("sso", "aaa")) } func Test_MGET(t *testing.T) { InitRedis("sso=192.168.3.207:3378") InitRedis("sso=192.168.3.207:1711") n := 0 for { n++ Put("sso", fmt.Sprintf("%d_1", n), n, 3600) time.Sleep(8 * time.Second) } res := Mget("sso", []string{"pn_金业街(西自由街-虎泉路)道路建设工程"}) log.Println(res) }