当前位置:网站首页>go操作redis
go操作redis
2022-07-02 10:31:00 【李子健】
使用goredis还是比较方便的
https://pkg.go.dev/github.com/go-redis/redis/v8#Client.Set
就是error的nil判断比较多
package main
import (
"context"
"fmt"
"time"
"github.com/go-redis/redis/v8"
)
var redis_client *redis.Client
func main() {
//redi的配置
redis_option := &redis.Options{
Addr: "127.0.0.1:6379",
DialTimeout: time.Millisecond * 100,
ReadTimeout: time.Millisecond * 100,
WriteTimeout: time.Millisecond * 200,
PoolSize: 20,
MinIdleConns: 3,
MaxConnAge: 50,
}
redis_client := redis.NewClient(redis_option)
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(time.Second*3))
defer cancel()
status_cmd := redis_client.Set(ctx, "abc", "123", time.Second*60)
fmt.Println(status_cmd.Result())
result := redis_client.Get(ctx, "abc")
result_str, err := result.Bytes()
if err != nil {
fmt.Println(err)
}
fmt.Println(string(result_str))
}
边栏推荐
猜你喜欢
Engineers who can't read device manuals are not good cooks
In 2021, the global styrene butadiene styrene (SBS) revenue was about $3722.7 million, and it is expected to reach $5679.6 million in 2028
Design of non main lamp: how to make intelligent lighting more "intelligent"?
【虹科技术分享】如何测试 DNS 服务器:DNS 性能和响应时间测试
Launcher startup process
Bridge of undirected graph
qt中uic的使用
Everyone believes that the one-stop credit platform makes the credit scenario "useful"
In 2021, the global revenue of structural bolts was about $796.4 million, and it is expected to reach $1097.6 million in 2028
Daily practice of C language --- monkeys divide peaches
随机推荐
Daily practice of C language --- monkeys divide peaches
ArrayList and LinkedList
OpenFOAM:lduMatrix&lduAddressing
Quantum three body problem: Landau fall
[deep learning] simple implementation of neural network forward propagation
Dangbei projection 4K laser projection X3 Pro received unanimous praise: 10000 yuan projector preferred
rxjs Observable 自定义 Operator 的开发技巧
qt中uic的使用
浏览器驱动的下载
ensp简单入门
selenium 在pycharm中安装selenium
无主灯设计:如何让智能照明更加「智能」?
Simple introduction to ENSP
[youcans' image processing learning course] general contents
千元投影小明Q1 Pro和极米NEW Play谁更好?和哈趣K1比哪款配置更高?
MySQL45讲——学习极客时间MySQL实战45讲笔记—— 05 | 深入浅出索引(下)
Just 1000 fans, record it
Explanation: here is your UFO, Goldbach conjecture
[USACO05JAN]Watchcow S(欧拉回路)
使用BLoC 构建 Flutter的页面实例