WAIT numslaves timeout

本文涉及的产品
云数据库 Redis 版,社区版 2GB
推荐场景:
搭建游戏排行榜
简介:

此命令阻塞当前客户端,直到所有以前的写命令都成功的传输和指定的slaves确认。如果超时,指定以毫秒为单位,即使指定的slaves还没有到达,命令任然返回。

命令始终返回之前写命令发送的slaves的数量,无论是在指定slaves的情况还是达到超时。

注意点:

  1. 当’WAIT’返回时,所有之前的写命令保证接收由WAIT返回的slaves的数量。
  2. 如果命令呗当做事务的一部分发送,该命令不阻塞,而是只尽快返回先前写命令的slaves的数量。
  3. 如果timeout是0那意味着永远阻塞。
  4. 由于WAIT返回的是在失败和成功的情况下的slaves的数量。客户端应该检查返回的slaves的数量是等于或更大的复制水平。

一致性(Consistency and WAIT)

Note that WAIT does not make Redis a strongly consistent store: while synchronous replication is part of a replicated state machine, it is not the only thing needed. However in the context of Sentinel or Redis Cluster failover, WAITimproves the real world data safety.

Specifically if a given write is transferred to one or more slaves, it is more likely (but not guaranteed) that if the master fails, we’ll be able to promote, during a failover, a slave that received the write: both Sentinel and Redis Cluster will do a best-effort attempt to promote the best slave among the set of available slaves.

However this is just a best-effort attempt so it is possible to still lose a write synchronously replicated to multiple slaves.

Implementation details

Since the introduction of partial resynchronization with slaves (PSYNC feature) Redis slaves asynchronously ping their master with the offset they already processed in the replication stream. This is used in multiple ways:

  1. Detect timed out slaves.
  2. Perform a partial resynchronization after a disconnection.
  3. Implement WAIT.

In the specific case of the implementation of WAIT, Redis remembers, for each client, the replication offset of the produced replication stream when a given write command was executed in the context of a given client. When WAIT is called Redis checks if the specified number of slaves already acknowledged this offset or a greater one.

@return

@integer-reply: The command returns the number of slaves reached by all the writes performed in the context of the current connection.

@examples

> SET foo bar
OK
> WAIT 1 0
(integer) 1
> WAIT 2 1000
(integer) 1

In the following example the first call to WAIT does not use a timeout and asks for the write to reach 1 slave. It returns with success. In the second attempt instead we put a timeout, and ask for the replication of the write to two slaves. Since there is a single slave available, after one second WAIT unblocks and returns 1, the number of slaves reached.






本文作者:陈群
本文来自云栖社区合作伙伴rediscn,了解相关信息可以关注redis.cn网站。
相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
云数据库 Redis 版使用教程
云数据库Redis版是兼容Redis协议标准的、提供持久化的内存数据库服务,基于高可靠双机热备架构及可无缝扩展的集群架构,满足高读写性能场景及容量需弹性变配的业务需求。 产品详情:https://www.aliyun.com/product/kvstore     ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库 ECS 实例和一台目标数据库 RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
目录
相关文章
|
22天前
|
API
wait-nofity
wait-nofity
19 0
|
8月前
|
存储 缓存 安全
|
4月前
|
关系型数据库 MySQL Java
MySQL中wait_timeout与interactive_timeout详解
MySQL中wait_timeout与interactive_timeout详解
96 0
|
4月前
|
网络协议 Cloud Native
为什么需要 TIME_WAIT 状态
为什么需要 TIME_WAIT 状态
为什么需要 TIME_WAIT 状态
|
5月前
|
消息中间件 网络协议 Java
深入剖析阻塞式socket的timeout
深入剖析阻塞式socket的timeout
|
9月前
|
SQL 关系型数据库 MySQL
Lock wait timeout exceeded; try restarting transaction解决方案
在测试程序时,打的断点怎么都跳不进去,console一直报 “Lock wait timeout exceeded; try restarting transaction”
287 0
|
监控
实践解读CLOSE_WAIT和TIME_WAIT
实践解读CLOSE_WAIT和TIME_WAIT
258 0
实践解读CLOSE_WAIT和TIME_WAIT
|
Oracle 关系型数据库 数据库
innodb_lock_wait_timeout参数的了解
前言:在管理ORACLE的工作中,经常发现因为锁等待的原因导致应用宕机了。Mysql考虑到自身的性能和架构等因素,InnoDB数据库引擎增加了参数innodb_lock_wait_timeout,避免在资源有限的情况下产生太多的锁等待; 一、innodb_...
3008 0
|
关系型数据库 MySQL 数据库
interactive_timeout和wait_timeout的关系
interactive_timeout = 28800 wait_timeout = 28800 #这两个参数默认都是28800s,即8个小时; interactive_timeout指的是mysql在关闭一个交互的连接之前所要等待的秒数 wait_timeout指的是mysql在关闭一个非交互的连接之前所要等待的秒数 通过mysql客户端连接数据库是交互式连接,通过jdbc连接数据库是非交互式连接 (1)session级别修改interactive_timeout=10,wait_timeout默认不变。
2191 0
|
SQL Oracle 关系型数据库
MySQL:参数wait_timeout和interactive_timeout以及空闲超时的实现
水平有限,如果有误请指出源码版本:percona 5.7.22 一、参数意思 这里简单解释一下两个参数含义如下: interactive_timeout:The number of seconds the server waits for activity on an interactive .
2067 0