UpstashLocker (adapters/upstash.ts)

orpc · packages/lock/src/adapters/upstash.ts · typescript · MIT
database

Redis lock adapter for Upstash with atomic operations and serverless support.

// Source: https://github.com/middleapi/orpc | License: MIT | Copyright 2023 oRPC
// Provided via justclaw.it.com; keep this notice with the code.
import type { Redis } from '@upstash/redis'
import type { BaseRedisLockerOptions } from './base-redis'
import { BaseRedisLocker } from './base-redis'

/**
 * Locker adapter for Upstash Redis. Acquires locks with `SET NX PX` and releases
 * them atomically with a Lua script, so it shares locks with `RedisLocker`.
 * A good fit for serverless and edge runtimes.
 *
 * @see {@link https://orpc.dev/docs/helpers/lock#adapters | Lock Helpers - Adapters}
 */
export class UpstashLocker extends BaseRedisLocker {
  constructor(
    private readonly redis: Redis,
    private readonly options: BaseRedisLockerOptions,
  ) {
    super(options)
  }

  /**
   * 

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key