当前位置:网站首页>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))
}边栏推荐
- Solve "sub number integer", "jump happily", "turn on the light"
- Error: eacces: permission denied, access to "/usr/lib/node_modules"
- Node. JS accessing PostgreSQL database through ODBC
- Simple introduction to ENSP
- 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
- Design of non main lamp: how to make intelligent lighting more "intelligent"?
- 量子三体问题: Landau Fall
- The 29 year old programmer in Shanghai was sentenced to 10 months for "deleting the database and running away" on the day of his resignation!
- 你的 Sleep 服务会梦到服务网格外的 bookinfo 吗
- P1042 [noip2003 popularization group] Table Tennis
猜你喜欢

Téléchargement par navigateur
![2022 zero code / low code development white paper [produced by partner cloud] with download](/img/46/92c51090e0c476df3bcffd2d11fb6d.png)
2022 zero code / low code development white paper [produced by partner cloud] with download

Qt新项目_MyNotepad++
![[Blue Bridge Cup] children's worship circle](/img/ad/5af4fe76ad5d1426bc460904d7f049.jpg)
[Blue Bridge Cup] children's worship circle

Drawing Nyquist diagram with MATLAB

Integral link, inertia link and proportion link in Simulink

Error function ERF
![Unity small map production [2]](/img/d6/9d6556d37525b9986b74133f2a7aaa.jpg)
Unity small map production [2]

Origin plots thermogravimetric TG and differential thermogravimetric DTG curves

MySQL45讲——学习极客时间MySQL实战45讲笔记—— 04 | 深入浅出索引(上)
随机推荐
[技术发展-22]:网络与通信技术的应用与发展快速概览-2- 通信技术
故事点 vs. 人天
Engineers who can't read device manuals are not good cooks
Story points vs. human days
Solve "sub number integer", "jump happily", "turn on the light"
【模板】最长公共子序列 (【DP or 贪心】板子)
How to set QT manual layout
OpenFOAM:lduMatrix&lduAddressing
SystemServer进程
Just 1000 fans, record it
ArrayList and LinkedList
I did it with two lines of code. As a result, my sister had a more ingenious way
Unity small map production [2]
Why is the default of switch followed by break?
Qt新项目_MyNotepad++
Development skills of rxjs observable custom operator
The 29 year old programmer in Shanghai was sentenced to 10 months for "deleting the database and running away" on the day of his resignation!
MySQL 45 lecture - learning the actual battle of MySQL in Geek time 45 Lecture Notes - 05 | easy to understand index (Part 2)
【虹科技术分享】如何测试 DNS 服务器:DNS 性能和响应时间测试
Pointer from entry to advanced (1)