redis
如果技术允许的话,封装自定义一种高级缓存 --- 多key一值
例子
package main
import (
"fmt"
"github.com/go-redis/redis/v7"
"github.com/hyahm/xredis"
"time"
)
func main() {
conf := &redis.Options{
Network: "",
Addr: "127.0.0.1:6379",
Dialer: nil,
OnConnect: nil,
Password: "",
DB: 0,
MaxRetries: 0,
MinRetryBackoff: 0,
MaxRetryBackoff: 0,
DialTimeout: 0,
ReadTimeout: 0,
WriteTimeout: 0,
PoolSize: 0,
MinIdleConns: 0,
MaxConnAge: 0,
PoolTimeout: 0,
IdleTimeout: 0,
IdleCheckFrequency: 0,
TLSConfig: nil,
}
client, err := xredis.Conn(conf)
if err != nil {
panic(err)
}
if _, err := client.Str().Set("aa", "bbb", time.Second*10); err != nil {
panic(err)
}
// lset list+set 有序集合, 新增特殊有序集合
ls := client.NewListSet()
//
ls.LPush("aaa", "bbb")
ls.LPush("aaa", "ccc")
ls.LPush("aaa", "ddd")
ls.LPush("aaa", "eee")
ls.LPush("aaa", "eee")
result, err := ls.Range("aaa", 0, 10)
if err != nil {
log.Fatal(err)
}
fmt.Println(result) // [eee ddd ccc bbb]
fmt.Println("设置成功")
}