在锁定钥匙redis-lock nodejs方面得到例外



试图锁定哈希键时,请以下例外:

我正在引用以下文档:

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 (bluebirdjsreleaseutil.js:16:23)
    at Promise._settlePromiseFromHandler (bluebirdjsreleasepromise.js:512:31)
    at Promise._settlePromise (bluebirdjsreleasepromise.js:569:18)
    at Promise._settlePromise0 (bluebirdjsreleasepromise.js:614:10)
    at Promise._settlePromises (bluebirdjsreleasepromise.js:689:18)
    at Async._drainQueue (bluebirdjsreleaseasync.js:133:16)
    at Async._drainQueues (bluebirdjsreleaseasync.js:143:10)
    at Immediate.Async.drainQueues (bluebirdjsreleaseasync.js:17:14)
    at runCallback (timers.js:781:20)
    at tryOnImmediate (timers.js:743:5)
    at processImmediate [as _immediateCallback] (timers.js:714:5)

请建议我的代码中有什么问题。

没关系,这是我的错误。我错过了前缀'锁:'到键。

如果有人努力解决问题,则可以将其引用,顺便说一句,在文档中,尚未提及有关prefix '锁的方式:'键。

相关内容

最新更新