Open akshaydeo opened 4 months ago
Hi! Sorry for confusing README example. Redlock algorythm requires independent nodes, so you need 3+ independent single nodes. Please see https://redis.io/docs/latest/develop/use/patterns/distributed-locks/#the-redlock-algorithm
Setup
docker-compose.yml
My redis connection using ioredis is able to connect and write data to it
redis.ts
When I run
ping()
, I can see the corresponding key being setI initialize a mutex like this
It always results in
Test setup
const timeoutOptions: TimeoutOptions = { lockTimeout: 300, acquireTimeout: 100, refreshInterval: 80, retryInterval: 10 }
async function expectGetAll(key: string, value: string | null) { await expect( Promise.all([client1.get(key), client2.get(key), client3.get(key)]) ).to.become([value, value, value]) }
describe('RedlockMutex', () => { it('should acquire and release lock using cluster', async () => { const mutex = new RedlockMutex(cluster.nodes('master'), 'key') expect(mutex.isAcquired).to.be.false
})
RedlockMutex 1) should acquire and release lock using cluster
0 passing (10s) 1 failing
1) RedlockMutex should acquire and release lock using cluster: Error: Acquire redlock-mutex mutex:key timeout at RedlockMutex.acquire (src/Lock.ts:140:13) at async Context. (test/src/RedlockMutex.test.ts:59:5)
➜ redis-semaphore git:(master) ✗