with-redlock
v0.2.6
Published
Lock an operation with redis. Uses a very simple implementation with a lock key and a result key. Use this function when multiple processes are attempting to do the same operation.
Downloads
1,025
Readme
with-redlock
Lock an operation with redis. Uses a very simple implementation with a lock key and a result key. Use this function when multiple processes are attempting to do the same operation.
Install via Yarn:
yarn add with-redlockInstall via npm:
npm install --save with-redlockUsage
import { createLogger, type Logger } from '@redwoodjs/api/logger'
import IORedis from 'ioredis'
import { deleteTable } from '.'
import { withRedLock } from 'with-redlock'
const logger = createLogger({})
const redisClient = new IORedis()
const deleteTableWithLock = (tableId: number) => {
return withRedLock({
redisClient,
resource: `deleteTableWithLock:${tableId}`,
task: async () => {
const result = await deleteTable(tableId)
return result
},
logger,
})
}Contributing
We welcome issues and pull requests!
