redis客户端一次性批量写入multiple keys对应的值可以减少网络操作。代码如下:
package main
import (
"fmt"
"github.com/go-redis/redis"
)
func main() {
client := redis.NewClient(&redis.Options{
Addr: "127.0.0.1:6380",
Password: "",
DB: 0,
})
result, err := client.MSet("key1", "value1", "key2", "value2").Result()
if err != nil {
fmt.Printf("%v\n", err.Error())
} else {
fmt.Printf("%v\n", result)
}
value1, _ := client.Get("key1").Result()
fmt.Printf("%v\n", value1)
value2, _ := client.Get("key2").Result()
fmt.Printf("%v\n", value2)
}
输出:
OK
value1
value2
相关文章:
《Go语言: go-redis客户端通过MGet方法一次性批量读取多个key的值》