当前位置:网站首页>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))
}边栏推荐
- P1347 sorting (topology + SPFA judgment ring or topology [inner judgment ring])
- 路由(二)
- [document tree, setting] font becomes smaller
- (POJ - 1308)Is It A Tree? (tree)
- Design of non main lamp: how to make intelligent lighting more "intelligent"?
- Whole house Wi Fi: a pain point that no one can solve?
- Which do you choose between Alibaba P7 with an annual salary of 900000 and deputy department level cadres?
- Add sequence number column to query results in MySQL
- Sum of the first n terms of Fibonacci (fast power of matrix)
- Codeforces Round #803 (Div. 2)(A~D)
猜你喜欢

ensp简单入门

Origin plots thermogravimetric TG and differential thermogravimetric DTG curves

Origin绘制热重TG和微分热重DTG曲线

selenium 在pycharm中安装selenium

Error: eacces: permission denied, access to "/usr/lib/node_modules"
![Student course selection information management system based on ssm+jsp framework [source code + database]](/img/71/900d83dba41974589b15d23e632119.png)
Student course selection information management system based on ssm+jsp framework [source code + database]

In 2021, the global TCB adapter revenue was about $93 million, and it is expected to reach $315.5 million in 2028

Memory management 01 - link script

A better database client management tool than Navicat

When tidb meets Flink: tidb efficiently enters the lake "new play" | tilaker team interview
随机推荐
Quantum three body problem: Landau fall
Three talking about exception -- error handling
Story point vs. Human Sky
The conference on the growth of all things was held in Hangzhou, and dangbei was selected into the top 100 list of future unicorns in China in 2022
自定义事件,全局事件总线,消息订阅与发布,$nextTick
【文档树、设置】字体变小
693. 行程排序(map + 拓扑)
题解《子数整数》、《欢乐地跳》、《开灯》
万物生长大会在杭召开,当贝入选2022中国未来独角兽TOP100榜单
Skillfully use SSH to get through the Internet restrictions
路由(二)
Origin plots thermogravimetric TG and differential thermogravimetric DTG curves
mysql ---- Oracle中的rownum转换成MySQL
Error: eacces: permission denied, access to "/usr/lib/node_modules"
Student course selection information management system based on ssm+jsp framework [source code + database]
Multi rotor aircraft control using PID and LQR controllers
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
Use of UIC in QT
How to use SAP's metadata framework (MDF) to build custom business rules?
Design of non main lamp: how to make intelligent lighting more "intelligent"?