Skip to content

Commit

Permalink
Merge pull request #1087 from hackclub/server-only
Browse files Browse the repository at this point in the history
Make redis lock server-only
  • Loading branch information
maxwofford authored Jan 9, 2025
2 parents 6e37582 + 62e6234 commit 52f7e3d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/redis-lock.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
'use server'
import 'server-only'

import { kv } from '@vercel/kv'
import { v4 as uuidv4 } from 'uuid'

const LOCK_TIMEOUT = 30 * 1000 // 30 seconds

export async function aquireLock(key: string): Promise<string | null> {
async function aquireLock(key: string): Promise<string | null> {
const lockKey = `lock:${key}`
const lockValue = uuidv4()
const acquired = await kv.set(lockKey, lockValue, {
Expand All @@ -14,7 +15,7 @@ export async function aquireLock(key: string): Promise<string | null> {
return acquired ? lockValue : null
}

export async function releaseLock(
async function releaseLock(
lockKey: string,
lockValue: string,
): Promise<void> {
Expand Down

0 comments on commit 52f7e3d

Please sign in to comment.