当前位置:网站首页>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))
}
边栏推荐
- 693. Travel sequencing (map + topology)
- QT new project_ MyNotepad++
- Word frequency statistics & sorting
- MySQL45讲——学习极客时间MySQL实战45讲笔记—— 04 | 深入浅出索引(上)
- Origin绘制热重TG和微分热重DTG曲线
- Story point vs. Human Sky
- Subcontracting configuration of uniapp applet subpackages
- Use bloc to build a page instance of shutter
- Unity skframework framework (XII), score scoring module
- Mysql5.7 installation super easy tutorial
猜你喜欢
selenium 在pycharm中安装selenium
2022家用投影仪首选!当贝F5强悍音画效果带来极致视听体验
Memory management 01 - link script
BeanUtils--浅拷贝--实例/原理
Systemserver process
The 29 year old programmer in Shanghai was sentenced to 10 months for "deleting the database and running away" on the day of his resignation!
Selenium element positioning method
Codeforces Round #803 (Div. 2)(A~D)
[Blue Bridge Cup] children's worship circle
A better database client management tool than Navicat
随机推荐
In 2021, the global revenue of structural bolts was about $796.4 million, and it is expected to reach $1097.6 million in 2028
qt中uic的使用
Penetrate the remote connection database through the Intranet
Will your sleep service dream of the extra bookinfo on the service network
Dingtalk send message
Mysql5.7 installation super easy tutorial
Tupang multi-target tracking! BOT sort: robust correlated multi pedestrian tracking
Add sequence number column to query results in MySQL
Which do you choose between Alibaba P7 with an annual salary of 900000 and deputy department level cadres?
无主灯设计:如何让智能照明更加「智能」?
Codeforces Round #803 (Div. 2)(A~D)
Solve "sub number integer", "jump happily", "turn on the light"
如何设置Qt手工布局
[deep learning] simple implementation of neural network forward propagation
How to use SAP's metadata framework (MDF) to build custom business rules?
MySQL 45 lecture - learning from the actual battle of geek time MySQL 45 Lecture Notes - 04 | easy to understand index (Part 1)
On flow delivery between microservices
I did it with two lines of code. As a result, my sister had a more ingenious way
In 2021, the global TCB adapter revenue was about $93 million, and it is expected to reach $315.5 million in 2028
不会看器件手册的工程师不是个好厨子