当前位置:网站首页>Go operation redis
Go operation redis
2022-07-02 14:07:00 【Lizijian】
Use goredis It's more convenient
https://pkg.go.dev/github.com/go-redis/redis/v8#Client.Set
Namely error Of nil More judgments
package main
import (
"context"
"fmt"
"time"
"github.com/go-redis/redis/v8"
)
var redis_client *redis.Client
func main() {
//redi Configuration of
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))
}
边栏推荐
- P3008 [USACO11JAN]Roads and Planes G (SPFA + SLF优化)
- Qt-制作一个简单的计算器-实现四则运算
- P1042 [NOIP2003 普及组] 乒乓球
- 代码实现MNLM
- Error function ERF
- Achievements in science and Technology (27)
- Data consistency between redis and database
- How to set QT manual layout
- 使用BLoC 构建 Flutter的页面实例
- A better database client management tool than Navicat
猜你喜欢
In 2021, the global TCB adapter revenue was about $93 million, and it is expected to reach $315.5 million in 2028
Find love for speed in F1 delta time Grand Prix
selenium 元素定位方法
Launcher startup process
Mysql5.7 installation super easy tutorial
Node. JS accessing PostgreSQL database through ODBC
2022家用投影仪首选!当贝F5强悍音画效果带来极致视听体验
错误:EACCES:权限被拒绝,访问“/usr/lib/node_modules”
Qt新项目_MyNotepad++
不会看器件手册的工程师不是个好厨子
随机推荐
BeanUtils -- shallow copy -- example / principle
Default slot, named slot, scope slot
[USACO05JAN]Watchcow S(欧拉回路)
PyQt5_QScrollArea内容保存成图片
qt中uic的使用
代码实现MNLM
[template] longest common subsequence ([DP or greedy] board)
Design of non main lamp: how to make intelligent lighting more "intelligent"?
selenium的特点
Don't spend money, spend an hour to build your own blog website
Unity small map production [2]
rxjs Observable 自定义 Operator 的开发技巧
自定义事件,全局事件总线,消息订阅与发布,$nextTick
Golang 快速生成数据库表的 model 和 queryset
[development environment] 010 editor tool (tool download | binary file analysis template template installation | shortcut key viewing and setting)
Winter vacation daily question - lucky numbers in the matrix
当贝投影4K激光投影X3 Pro获得一致好评:万元投影仪首选
selenium,元素操作以及浏览器操作方法
Integral link, inertia link and proportion link in Simulink
Word frequency statistics & sorting