Vana SDK - v2.2.2
    Preparing search index...

    Class RedisAtomicStore

    Redis-backed implementation of IAtomicStore.

    This implementation uses Redis's native atomic operations:

    • INCR for atomic counter increments
    • SET NX EX for distributed locking
    • Lua script for safe lock release

    Redis is ideal for this use case because:

    • All operations are atomic by design
    • Built-in TTL support for automatic cleanup
    • High performance (sub-millisecond operations)
    • Battle-tested in production environments
    import Redis from 'ioredis';
    import { RedisAtomicStore } from '@opendatalabs/vana-sdk/node';

    const redis = new Redis(process.env.REDIS_URL);
    const atomicStore = new RedisAtomicStore({
    redis: redis
    });

    const vana = Vana({
    walletClient,
    atomicStore,
    operationStore
    });

    Implements

    • IAtomicStoreWithNonceSupport
    Index

    Methods

    • Acquires a distributed lock using SET NX EX.

      Parameters

      • key: string
      • ttlSeconds: number

      Returns Promise<string | null>

    • Releases a lock using a Lua script for atomicity.

      Parameters

      • key: string
      • lockId: string

      Returns Promise<void>

    • Sets a value with TTL for automatic expiration.

      Parameters

      • key: string
      • value: string
      • ttlSeconds: number

      Returns Promise<void>

    • Executes a Lua script atomically.

      Parameters

      • script: string

        The Lua script to execute

      • keys: string[]

        Array of keys (will be prefixed)

      • args: string[]

        Array of arguments

      Returns Promise<any>

      The script's return value

      This provides generic script execution for complex atomic operations. Keys passed to the script will be automatically prefixed.

    • Atomically assigns a nonce using Vana App's battle-tested logic.

      Parameters

      • key: string

        The key for storing the last used nonce

      • pendingCount: number

        The current pending transaction count from blockchain

      Returns Promise<number>

      The assigned nonce

      This is a Redis-specific optimization that uses a Lua script for atomic nonce assignment with gap prevention. This method is called by DistributedNonceManager when it detects a Redis store.

      Ported from apps/web/app/api/relay/route.ts (Vana App production code) DO NOT MODIFY without thorough testing in production environment.