MCPcopy Create free account
hub / github.com/Rfym21/Qwen2API / waitForRedisReady

Function waitForRedisReady

src/utils/redis.js:124–165  ·  view source on GitHub ↗
(client)

Source from the content-addressed store, hash-verified

122 */
123const waitForRedisReady = (client) => new Promise((resolve, reject) => {
124 if (!client) {
125 reject(new Error('Redis客户端不存在'))
126 return
127 }
128
129 if (client.status === 'ready') {
130 resolve(client)
131 return
132 }
133
134 const timeout = setTimeout(() => {
135 cleanup()
136 reject(new Error('等待Redis连接恢复超时'))
137 }, REDIS_CONFIG.connectTimeout + REDIS_CONFIG.commandTimeout)
138
139 const cleanup = () => {
140 clearTimeout(timeout)
141 client.off('ready', handleReady)
142 client.off('close', handleClose)
143 client.off('end', handleEnd)
144 }
145
146 const handleReady = () => {
147 cleanup()
148 resolve(client)
149 }
150
151 const handleClose = () => {
152 cleanup()
153 reject(new Error('Redis连接已关闭'))
154 }
155
156 const handleEnd = () => {
157 cleanup()
158 reject(new Error('Redis连接已结束'))
159 }
160
161 client.once('ready', handleReady)
162 client.once('close', handleClose)
163 client.once('end', handleEnd)
164})
165
166/**
167 * 更新活动时间并重置空闲定时器
168 */

Callers 1

connectRedisFunction · 0.85

Calls 1

cleanupFunction · 0.85

Tested by

no test coverage detected