You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@AJackTi
I have resolved this issue with these changes. The key is to overwrite release method and check if lock expired.
importRedlockfrom'redlock'import{redis}from'../storage/redis'exportconstredlock=newRedlock([redis],{// The expected clock drift; for more details see:// http://redis.io/topics/distlockdriftFactor: 0.01,// multiplied by lock ttl to determine drift time// The max number of times Redlock will attempt to lock a resource// before erroring.retryCount: 30,// the time in ms between attemptsretryDelay: 2000,// 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.htmlretryJitter: 200,// time in ms// The minimum remaining time on a lock before an extension is automatically// attempted with the `using` API.automaticExtensionThreshold: 500,// time in ms})// Save the original acquire methodconstoriginalAcquire=Redlock.prototype.acquire// Override the release method for all lock instancesRedlock.prototype.acquire=asyncfunction(...args){constduration=args[1]// this is a duration value// use the duration to create additional settingsargs[2]={retryCount: Math.ceil((duration/2_000)*1.5),retryDelay: 2_000,
...args[2],}returnoriginalAcquire.apply(this,args)// Call the original release method}// Save the original release methodconstoriginalRelease=Redlock.prototype.release// Override the release method for all lock instancesRedlock.prototype.release=asyncfunction(...args){constnow=newDate().getTime()if(args[0]&&args[0].expiration>now){// Check if the lock still existsreturnoriginalRelease.apply(this,args)// Call the original release method}return{attempts: [],}}
My package's version:
redlock: 5.0.0-beta.2
ioredis: 5.4.1
redis server: 7.4.0
node: v22.6.0
My code:
My docker-compose file to run redis sentinels:
When I run curl:
I got the error message:
Please help me. I spent several days trying to address this, and my task’s deadline is approaching. I really need your help.
The text was updated successfully, but these errors were encountered: