redis管道 -redis pipeline -redis pipelining

redis管道

文档

  1. redis单机安装
  2. redis常用的五种数据类型
  3. redis数据类型-位图bitmap
  4. redis数据类型-基数统计HyperLogLog
  5. redis数据类型-地理空间GEO
  6. redis数据类型-流Stream
  7. redis数据类型-位域bitfield
  8. redis持久化-RDB
  9. redis持久化-AOF
  10. redis持久化-RDB+AOF混合模式
  11. redis事务

官方文档

  1. 官网操作命令指南页面:https://redis.io/docs/latest/commands/?name=get&group=string
  2. Transactions
  3. Redis pipelining

说明

  1. redis版本:7.0.0

redis管道

官方说明
  1. 官方说明:Redis pipelining

    Redis pipelining

    How to optimize round-trip times by batching Redis commands

    Redis pipelining is a technique for improving performance by issuing multiple commands at once without waiting for the response to each individual command. Pipelining is supported by most Redis clients. This document describes the problem that pipelining is designed to solve and how pipelining works in Redis.

  2. 总结

    1. Redis piplining是一种通过同时发出多个命令而不等待响应每个命令来提高性能的技术。
示例
  1. 官方示例较为复杂,下面是另外的示例

  2. 创建redis-pipe.txt文件,在文件中填写多条redis命令

    set k1 hello
    set k2 123
    hset k3 name zhangsan
    lpush k4 1 2 3 4 5
    set k5 world
    
  3. 执行redis管道命令,同时发出多条命令

    cat ../pipe-data/redis-pipe.txt | ./redis-cli -a 123456 --pipe
    

    响应信息:

    Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    All data transferred. Waiting for the last reply...
    Last reply received from server.
    errors: 0, replies: 5
    
pipeline与原生批量命令对比
  1. 原生的批量命令,例如:msetmget,可以对字符串类型的数据进行批量执行;pipeline支持批量执行多个命令,并且命令可以是不同数据类型
  2. 原生的批量命令,例如:msetmget,是原子性的;pipeline是非原子性的
  3. 原生的批量命令是redis客户端执行一条redis命令;pipeline是批量执行多个redis命令,一般需要结合操作系统的其它命令来实现此功能
pipeline与事务对比
  1. 事务具有原子性;管道不具有原子性
  2. 事务在接收到exec命令才会执行,执行事务时会阻塞其它命令的执行;执行管道中的命令不会阻塞其它命令
使用pipeline的注意事项
  1. 官方说明

    IMPORTANT NOTE: While the client sends commands using pipelining, the server will be forced to queue the replies, using memory. So if you need to send a lot of commands with pipelining, it is better to send them as batches each containing a reasonable number, for instance 10k commands, read the replies, and then send another 10k commands again, and so forth. The speed will be nearly the same, but the additional memory used will be at most the amount needed to queue the replies for these 10k commands.

  2. 总结

    1. pipeline批量执行,不保证原子性,如果执行中指令发生异常,将会继续执行后续的指令
    2. pipeline批量执行的命令数量过大,会占用较大的内存。应控制批量命令的大小,比如一次批量执行10K大小的命令。

你可能感兴趣的:(redis,redis,bootstrap,数据库)