当前位置:网站首页>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))
}
边栏推荐
- Tupang multi-target tracking! BOT sort: robust correlated multi pedestrian tracking
- P1908 逆序对
- Astro learning notes
- Qt-制作一个简单的计算器-实现四则运算-将结果以对话框的形式弹出来
- Téléchargement par navigateur
- 万物生长大会在杭召开,当贝入选2022中国未来独角兽TOP100榜单
- Which do you choose between Alibaba P7 with an annual salary of 900000 and deputy department level cadres?
- [youcans' image processing learning course] general contents
- Runhe hi3516 development board openharmony small system and standard system burning
- MySQL 45 lecture - learning the actual battle of MySQL in Geek time 45 Lecture Notes - 05 | easy to understand index (Part 2)
猜你喜欢
无主灯设计:如何让智能照明更加「智能」?
瀏覽器驅動的下載
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
Launcher启动过程
SystemServer进程
Student course selection information management system based on ssm+jsp framework [source code + database]
Systemserver process
Use bloc to build a page instance of shutter
Subcontracting configuration of uniapp applet subpackages
Pointer from entry to advanced (1)
随机推荐
Dingtalk send message
Selenium element positioning method
qt中uic的使用
Detailed collection of common MySQL commands
In 2021, the global revenue of structural bolts was about $796.4 million, and it is expected to reach $1097.6 million in 2028
Astro learning notes
MySQL -- convert rownum in Oracle to MySQL
Winter vacation daily question - lucky numbers in the matrix
Memory management 01 - link script
Characteristics of selenium
Whole house Wi Fi: a pain point that no one can solve?
Qt新项目_MyNotepad++
Android kotlin broadcast technology point
Simple introduction to ENSP
浏览器驱动的下载
Add sequence number column to query results in MySQL
Browser driven Download
量子三体问题: Landau Fall
D language, possible 'string plug-ins'
Android kotlin fragment technology point