gpt4 book ai didi

node.js - 在锁定 key 时获取异常 redis-lock nodejs

转载 作者:IT王子 更新时间:2023-10-29 06:13:16 27 4
gpt4 key购买 nike

当尝试如下锁定哈希键时出现异常:

我指的是以下文档:

https://redis.io/topics/distlock

https://github.com/mike-marcacci/node-redlock

var redis = require('redis');
var Redlock = require('redlock');
var redisClient = redis.createClient(settings.redisport, settings.redishost);
var redlock = new Redlock(
// you should have one client for each independent redis node
// or cluster
[redisClient],
{
// the expected clock drift; for more details
// see http://redis.io/topics/distlock
driftFactor: 0.01, // time in ms

// the max number of times Redlock will attempt
// to lock a resource before erroring
retryCount: 10,

// the time in ms between attempts
retryDelay: 200, // time in ms

// the max time in ms randomly added to retries
// to improve performance under high contention
// see https://www.awsarchitectureblog.com/2015/03/backoff.html
retryJitter: 200 // time in ms
}
);

redlock.lock([Key], settings.lockttl).then(function (lock) {
return lock.unlock();
}).catch(function (err) {

return lock.unlock();
});


ERR Error running script (call to f_cf0e94b2e9ffc7e04395cf88f7583fc309985910): @user_script:1: WRONGTYPE Operation against a key holding the wrong kind of value
Exceeded 10 attempts to lock the resource "Room:1111".
Unhandled rejection ReferenceError: lock is not defined
at app.js:559:17
at tryCatcher (bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (bluebird\js\release\promise.js:512:31)
at Promise._settlePromise (bluebird\js\release\promise.js:569:18)
at Promise._settlePromise0 (bluebird\js\release\promise.js:614:10)
at Promise._settlePromises (bluebird\js\release\promise.js:689:18)
at Async._drainQueue (bluebird\js\release\async.js:133:16)
at Async._drainQueues (bluebird\js\release\async.js:143:10)
at Immediate.Async.drainQueues (bluebird\js\release\async.js:17:14)
at runCallback (timers.js:781:20)
at tryOnImmediate (timers.js:743:5)
at processImmediate [as _immediateCallback] (timers.js:714:5)

请指出我的代码中有什么问题。

最佳答案

没关系,这是我的错误。我错过了在 key 前添加 'locks:' 前缀。

如果有人遇到问题,可以引用这个,顺便说一下,文档中没有提到前缀 'locks:' to key。

关于node.js - 在锁定 key 时获取异常 redis-lock nodejs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46520212/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com