获取locking关键字redis-lock nodejs的例外情况

当试图locking哈希键如下获得一个例外:

我指的是以下文档:

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) 

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

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

如果任何人遇到问题,那么可以通过文档中未提及的关于前缀'locks:'的方式来引用这个关键字。