当前位置:网站首页>go Redis 管道(pipeline)运用
go Redis 管道(pipeline)运用
2022-07-21 17:48:00 【IT工作者】
Redis在进行大批量操作时,为了提高运行效率,往往会采用pipe,今天实测对比了一下管道的运行效率,还是挺惊人的.
package main
import (
"flag"
"fmt"
"github.com/go-redis/redis/v8"
"context"
"time"
)
func main() {
var pipucot int = 1
flag.IntVar(&pipucot, "pc", 1000, "pip批量处理个数")
flag.Parse()
rdb := redis.NewClient(&redis.Options{
Addr:"192.168.1.101:6379",
})
ctx := context.Background()
pip := rdb.Pipeline()
t := time.Now()
cmdcot := 100000
for k:=1;k<cmdcot;k++{
key:= fmt.Sprint("keypip%d", k)
err := pip.Set(ctx, key, k, 0).Err()
if err != nil {
panic(err)
}
if k%pipucot==0{
pip.Exec(ctx)
}
}
println("pip use time:", time.Since(t).Milliseconds())
t1 := time.Now()
for k:=1;k<cmdcot;k++{
key:= fmt.Sprint("key%d", k)
err := rdb.Set(ctx, key, k, 0).Err()
if err != nil {
panic(err)
}
}
println("no pip use time:", time.Since(t1).Milliseconds())
}
边栏推荐
- LeetCode83 && LeetCode82: 删除排序链表中的重复元素
- How to create threads
- Leetcode-12: integer to Roman numeral
- About the plaintext syntax of vditor Publishing
- The pit trodden by real people tells you to avoid the 10 mistakes that novices in automated testing often make
- 履约系统退餐流程方案设计
- A custom control for picture selection
- 导入头文件到pch 出错
- Custom view - click bubble effect
- 前辈的前后台分离介绍
猜你喜欢
flex布局
关于在RecyclerView中使用UniversalImageLoader加载图片刷新数据时引起的闪烁问题
栈和队列常见oj题
Scheme design of meal return process of performance system
NodeJS使用Express框架进行POST请求报“BadRequestError:request aborted”
How to create threads
Ctrip spark multi tenant query service evolution, Apache Kyuubi can be expected in the future
solo 文章 推送到社区端失败
A method of keeping the original scale of OpenGL map
“万物互联,使能千行百业”,2022开放原子全球开源峰会OpenAtom OpenHarmony分论坛即将开幕
随机推荐
Guan Zhengxiong: implement QA generation algorithm based on pre training model and intelligent operation and maintenance
Is it safe to open an account at Huatai Securities? Where is it more reliable
Some notes of MySQL
Module build failed: Error: Plugin/Preset files are not allowed to export objects, only functions.
Parallelism and concurrency
UISwitch OFF状态下默认颜色设置
华泰证券在哪开户安全,手机可以吗
关于 vditor 发布 plaintext 语法问题
履约系统退餐流程方案设计
获取 (对象数组 / 数组) 的(最小 / 最大值)
ArrayList源码解析
并行与并发
A method of keeping the original scale of OpenGL map
河北专接本C语言程序第一天 求1-100内的所有素数
Server memory failure prediction can actually do this!
C语言——程序环境和预处理
用unshift向对象数组中添加一个元素
Thinking of data storage scheme based on sub database and sub table
Good wheel collection: an image loading library STB that supports almost all popular formats_ image. h
Single cell paper record (Part18) -- spectral clustering based on learning similarity matrix