当前位置:网站首页>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))
}边栏推荐
- 你知道Oracle的数据文件大小有上限么?
- Whole house Wi Fi: a pain point that no one can solve?
- Story points vs. human days
- 千元投影小明Q1 Pro和极米NEW Play谁更好?和哈趣K1比哪款配置更高?
- Origin plots thermogravimetric TG and differential thermogravimetric DTG curves
- [Blue Bridge Cup] children's worship circle
- selenium的特点
- Multi rotor aircraft control using PID and LQR controllers
- Three talking about exception -- error handling
- The xftp connection Haikang camera reported an error: the SFTP subsystem application has been rejected. Please ensure that the SFTP subsystem settings of the SSH connection are valid
猜你喜欢

uniapp小程序 subPackages分包配置

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

Solve "sub number integer", "jump happily", "turn on the light"

代码实现MNLM

ensp简单入门

Explanation: here is your UFO, Goldbach conjecture

Tupang multi-target tracking! BOT sort: robust correlated multi pedestrian tracking

Use of UIC in QT

In 2021, the global revenue of structural bolts was about $796.4 million, and it is expected to reach $1097.6 million in 2028
![Unity small map production [2]](/img/d6/9d6556d37525b9986b74133f2a7aaa.jpg)
Unity small map production [2]
随机推荐
故事点 vs. 人天
三谈exception——错误处理
[unity] using GB2312, the solution to abnormal program after packaging
Selenium installing selenium in pycharm
Verification failed, please check your call back website. You can follow the instructions
无主灯设计:如何让智能照明更加「智能」?
Error function ERF
[template] longest common subsequence ([DP or greedy] board)
Unity skframework framework (XII), score scoring module
Common options of tcpdump command: Three
How to use SAP's metadata framework (MDF) to build custom business rules?
Story points vs. human days
Node. JS accessing PostgreSQL database through ODBC
MySQL 45 lecture - learning from the actual battle of geek time MySQL 45 Lecture Notes - 04 | easy to understand index (Part 1)
Design of non main lamp: how to make intelligent lighting more "intelligent"?
Detailed collection of common MySQL commands
A better database client management tool than Navicat
P1347 排序(拓扑 + spfa判断环 or 拓扑[内判断环])
Use of UIC in QT
Why is the default of switch followed by break?