添加 DoWithCancel
作者: ghost创建于 2018年6月27日更新于 2019年7月21日
标签EnhancementHelp wanted
在 Redis [CLIENT UNBLOCK] 命令后添加 DoWesCancel 帮助器功能(https://GitHub.com/antirez/Redis/committs/client-unblock)发布.
/ DoWithCancel 执行 cmd 有参数。 如果取消上下文,则
// doWithCancel 解锁 c 通过使用一个执行 CLIENT UNBLOCK 命令
/ 连接从获取函数返回 。 示例
/ 请检查url=值 (帮助).
// 结果, 错误: = Redis. Values (Redis. DoWith Cancel (c, ctx, pool.). 获取,"BRPOP","键","0").
func DoWithCancel(c Conn, ctx 上下文). 背景, 获取 func( ) Conn, cmd 字符串, args... interface {} (interface , 错误) {
id, 错误 : = Redis. Int(Redis.Do("CLIENT","ID"))
如果错误 ! = 无 {
返回错误
{\fn黑体\fs22\bord1\shad0\3aHBE\4aH00\fscx67\fscy66\2cHFFFFFF\3cH808080}你觉得呢?
停止 := make(chan struct) :
等待 := make(chan struct ) 时间轴:
开始 func () {
延迟关闭(等)
选择{
大小写 < stop:
大小写 <-ctx.Done ():
//TODO:避免陷入僵局. 如果参数c来自与 Wait = 真实的池中,则得到参数
/ 是从同一个池中取出 Get() 的方法, 那么下面的一行会导致僵局 。
c:= 获得()
c. 关闭( )
,错误:= c.Do ("CLIENT","UNBLOCK", id)
// TODO: 处理错误, 可能通过关闭参数 c 的网络连接
{\fn黑体\fs22\bord1\shad0\3aHBE\4aH00\fscx67\fscy66\2cHFFFFFF\3cH808080}你觉得呢?
• ()
r, 错误 := c.Do(cmd, args...)
关闭( 停止)
< 等待时
返回 r, 错误
{\fn黑体\fs22\bord1\shad0\3aHBE\4aH00\fscx67\fscy66\2cHFFFFFF\3cH808080}你觉得呢?为了减少额外的绕行到服务器,在低级连接中缓存结果fo CLIENT ID命令.
func (c *conn) DoWith Timeout (已读) 暂停时间。 持续时间, cmd 字符串, args... interface {} (interface , 错误) {
. . . . . . . .
===============================================================================================================================================================================================================================================================
如果为 ClientIDCmd = \ c. clientID!= 无 {
返回 c. 客户身份, 无
{\fn黑体\fs22\bord1\shad0\3aHBE\4aH00\fscx67\fscy66\2cHFFFFFF\3cH808080}你觉得呢?
. . . . . . . .
如果这是 ClientIDCmd 错误=====
c. 客户ID = 答复
{\fn黑体\fs22\bord1\shad0\3aHBE\4aH00\fscx67\fscy66\2cHFFFFFF\3cH808080}你觉得呢?
. . . . . . . .
{\fn黑体\fs22\bord1\shad0\3aHBE\4aH00\fscx67\fscy66\2cHFFFFFF\3cH808080}你觉得呢?EDIT:在低级连接中将客户端ID缓存的一个替代方案是使用应用程序指令的管道CLIENTID. 这种方法将执行工作本地化,使之符合这一职能,对业绩的影响不大.
内容来源: gomodule/redigo