当前位置:网站首页>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))
}边栏推荐
猜你喜欢

Mysql5.7 installation super easy tutorial

Chaos engineering platform chaosblade box new heavy release

Téléchargement par navigateur

2022家用投影仪首选!当贝F5强悍音画效果带来极致视听体验

【虹科技术分享】如何测试 DNS 服务器:DNS 性能和响应时间测试

Qt入门-制作一个简易的计算器
![Unity small map production [2]](/img/d6/9d6556d37525b9986b74133f2a7aaa.jpg)
Unity small map production [2]

Who is better, Qianyuan projection Xiaoming Q1 pro or Jimi new play? Which configuration is higher than haqu K1?

Origin plots thermogravimetric TG and differential thermogravimetric DTG curves

Codeforces Round #803 (Div. 2)(A~D)
随机推荐
693. Travel sequencing (map + topology)
错误:EACCES:权限被拒绝,访问“/usr/lib/node_modules”
Memory management 01 - link script
How to set QT manual layout
Android kotlin fragment technology point
Pattern matching and regular expressions in PostgreSQL - Das
每天坚持20分钟go的基础二
[Blue Bridge Cup] children's worship circle
Node. JS accessing PostgreSQL database through ODBC
给Android程序员的一些面试建议「建议收藏」
Qt入门-制作一个简易的计算器
A better database client management tool than Navicat
P1347 sorting (topology + SPFA judgment ring or topology [inner judgment ring])
Codeforces Round #803 (Div. 2)(A~D)
Add sequence number column to query results in MySQL
Find love for speed in F1 delta time Grand Prix
Story point vs. Human Sky
Qt新建项目
当贝投影4K激光投影X3 Pro获得一致好评:万元投影仪首选
Do you know that there is an upper limit on the size of Oracle data files?