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.
go-library/utils/redis/redis_test.go

85 lines
2.0 KiB

3 years ago
package redis
3 years ago
import (
3 years ago
"fmt"
3 years ago
"github.com/bitly/go-simplejson"
"testing"
"time"
)
func TestName(t *testing.T) {
3 years ago
}
func client() {
3 years ago
// 连接
3 years ago
err := InitRedis("127.0.0.1", 6379, "", 2)
3 years ago
if err != nil {
3 years ago
fmt.Printf("err%v\n", err)
3 years ago
}
jsonSimpleJson()
}
func set() {
// 设置
3 years ago
NewStringOperation().Set("test", "test", WithExpire(time.Second*1))
3 years ago
}
func mGet() {
// 获取
3 years ago
iter := NewStringOperation().MGet("test1", "test2").Iter()
3 years ago
for iter.HasNext() {
3 years ago
fmt.Println("MGet", iter.Next())
3 years ago
}
}
func json() {
3 years ago
newCache := NewSimpleCache(NewStringOperation(), time.Second*10, SerializerJson)
3 years ago
newCache.JsonGetter = func() interface{} {
3 years ago
fmt.Println("【没有命中】SerializerJson")
3 years ago
type a []string
b := a{
"me", "she", "you",
}
return b
}
cacheJSon := newCache.GetCache("test123")
3 years ago
fmt.Printf("【GetCache】cacheJSon%v\n", cacheJSon)
3 years ago
}
func dbString() {
3 years ago
newCache := NewSimpleCache(NewStringOperation(), time.Second*10, SerializerString)
3 years ago
newCache.DBGetter = func() string {
3 years ago
fmt.Println("【没有命中】SerializerString")
3 years ago
return "data by id=123"
}
cacheString := newCache.GetCache("test456")
3 years ago
fmt.Printf("【GetCache】cacheString%v\n", cacheString)
3 years ago
}
func simpleJson() {
3 years ago
newCache := NewSimpleCache(NewStringOperation(), time.Second*50, SerializerSimpleJson)
3 years ago
newCache.SimpleJsonGetter = func() *simplejson.Json {
3 years ago
fmt.Println("_test【没有命中】SerializerSimpleJson")
3 years ago
js := simplejson.New()
js.Set("name", "test")
return js
}
cacheSimpleJson := newCache.GetCacheSimpleJson("test789")
3 years ago
fmt.Printf("_test【GetCache】cacheSimpleJson%v\n", cacheSimpleJson.Get("name"))
3 years ago
}
func jsonSimpleJson() {
3 years ago
newCache := NewSimpleCache(NewStringOperation(), time.Second*50, SerializerJson)
3 years ago
newCache.JsonGetter = func() interface{} {
3 years ago
fmt.Println("【没有命中】SerializerJson")
3 years ago
type a []string
b := a{
"me", "she", "you",
}
return b
}
cacheJson := newCache.GetCacheSimpleJson("test789")
3 years ago
fmt.Printf("_test【JsonGetter GetCacheSimpleJson】jsonSimpleJson%v\n", cacheJson.GetIndex(1))
3 years ago
}