当前位置:网站首页>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))
}
边栏推荐
- Skillfully use SSH to get through the Internet restrictions
- BeanUtils -- shallow copy -- example / principle
- 万物生长大会在杭召开,当贝入选2022中国未来独角兽TOP100榜单
- Mysql5.7 installation super easy tutorial
- SystemServer进程
- Word frequency statistics & sorting
- Will your sleep service dream of the extra bookinfo on the service network
- Astro learning notes
- (POJ - 1984) navigation nightare (weighted and search set)
- 2022家用投影仪首选!当贝F5强悍音画效果带来极致视听体验
猜你喜欢
Qt-制作一个简单的计算器-实现四则运算
Mysql5.7 installation super easy tutorial
Drawing Nyquist diagram with MATLAB
[Hongke technology sharing] how to test DNS server: DNS performance and response time test
Téléchargement par navigateur
Daily practice of C language --- monkeys divide peaches
联合搜索:搜索中的所有需求
Qt新项目_MyNotepad++
Will your sleep service dream of the extra bookinfo on the service network
2022家用投影仪首选!当贝F5强悍音画效果带来极致视听体验
随机推荐
OpenFOAM:lduMatrix&lduAddressing
Whole house Wi Fi: a pain point that no one can solve?
[document tree, setting] font becomes smaller
Android kotlin fragment technology point
selenium的特点
石子合并板子【区间DP】(普通石子合并 & 环形石子合并)
D language, possible 'string plug-ins'
Codeforces Round #803 (Div. 2)(A~D)
[Hongke technology sharing] how to test DNS server: DNS performance and response time test
刚好1000粉丝,记录一下
ArrayList and LinkedList
P3008 [usaco11jan]roads and planes g (SPFA + SLF optimization)
Launcher startup process
Dingtalk 发送消息
Origin plots thermogravimetric TG and differential thermogravimetric DTG curves
Selenium, element operation and browser operation methods
Route (II)
故事點 vs. 人天
MySQL45讲——学习极客时间MySQL实战45讲笔记—— 05 | 深入浅出索引(下)
Word frequency statistics & sorting