import type { LockOptions } from './redis-lock.service'; import { RedisLockService } from './redis-lock.service'; import { type KeyTemplateOptions } from './template-utils'; /** * Set global LockService instance * Called by RedisLockModule during initialization */ export declare function setLockService(lockService: RedisLockService): void; /** * Get global LockService instance */ export declare function getLockService(): RedisLockService | null; /** * Method decorator that wraps the method execution with a distributed Redis lock * * This decorator automatically acquires a lock before executing the method * and releases it afterwards. If the lock cannot be acquired, the method * execution is skipped and returns null (or the value specified in skipReturnValue). * * @param lockKey - The Redis lock key (required) * @param options - Lock options * * @example * ```typescript * @Injectable() * class MyService { * @UseRedisLock('my-task', { ttl: 60000 }) * async processTask() { * // This will only execute if the lock is acquired * } * } * ``` */ export declare function UseRedisLock(lockKey: string, options?: LockOptions & { skipReturnValue?: any; }): MethodDecorator; /** * Simplified decorator for methods that should skip execution if lock cannot be acquired * Returns false when skipped, true when executed successfully * * @param lockKey - The Redis lock key (required) * @param ttl - Lock TTL in milliseconds (default: 300000 / 5 minutes) * * @example * ```typescript * @Injectable() * class MyScheduler { * @Cron('0 * * * *') * @UseRedisLockOrSkip('hourly-task', 3600000) * async hourlyTask() { * // This will only execute on one instance * } * } * ``` */ export declare function UseRedisLockOrSkip(lockKey: string, ttl?: number): MethodDecorator; /** * Smart decorator that auto-generates lock key from class and method name * Lock key format: ClassName:methodName * * This decorator is useful for simple cases where you don't need custom lock keys. * * @param options - Lock options * * @example * ```typescript * @Injectable() * class MyService { * // Lock key will be auto-generated as "MyService:processData" * @UseRedisLockSmart({ ttl: 60000 }) * async processData() { * // Business logic * } * * // With strategy * @UseRedisLockSmart({ * ttl: 120000, * strategy: LockStrategy.WAIT, * waitTimeout: 60000, * }) * async generateReport() { * // Business logic * } * } * ``` */ export declare function UseRedisLockSmart(options?: LockOptions & { skipReturnValue?: any; }): MethodDecorator; /** * Smart decorator for simple skip-on-busy scenarios with auto-generated lock key * Lock key format: ClassName:methodName * * @param ttl - Lock TTL in milliseconds (default: 300000 / 5 minutes) * * @example * ```typescript * @Injectable() * class MyScheduler { * @Cron('0 * * * *') * @UseRedisLockOrSkipSmart(3600000) // 1 hour TTL * async hourlyTask() { * // Lock key: "MyScheduler:hourlyTask" * } * * @Cron('0 0 * * *') * @UseRedisLockOrSkipSmart() // Default 5 minutes TTL * async dailyTask() { * // Lock key: "MyScheduler:dailyTask" * } * } * ``` */ export declare function UseRedisLockOrSkipSmart(ttl?: number): MethodDecorator; /** * Dynamic Key Decorator Options * Extends LockOptions with template-specific options */ export interface DynamicKeyDecoratorOptions extends LockOptions, KeyTemplateOptions { /** * Value to return when execution is skipped (e.g., due to missing parameter) * @default null */ skipReturnValue?: any; } /** * Method decorator with dynamic key generation from function parameters * * This decorator allows you to specify lock key patterns that extract values * from method parameters using template syntax like `{paramName}` or `{0}`. * * Template Syntax: * - `{userId}` - Named parameter access (requires emitDecoratorMetadata) * - `{0}`, `{1}` - Positional parameter access * - `{user.id}` - Nested property access * - `{items.0.name}` - Array index access * * @param keyTemplate - Template string with placeholders * @param options - Lock and template options * * @example * ```typescript * @Injectable() * class UserService { * // Simple parameter reference * @UseRedisLockWithDynamicKey('{userId}', { ttl: 60000 }) * async updateUser(userId: string, data: any) { * // Lock key: lock:user123 * } * * // Multiple parameters * @UseRedisLockWithDynamicKey('{userId}:{postId}', { ttl: 60000 }) * async updatePost(userId: string, postId: string, data: any) { * // Lock key: lock:user123:post456 * } * * // Nested property access * @UseRedisLockWithDynamicKey('user:{user.id}:profile', { ttl: 60000 }) * async updateProfile(user: UserDto) { * // Lock key: lock:user:user123:profile * } * * // Positional access (works without metadata) * @UseRedisLockWithDynamicKey('payment:{0}:process', { ttl: 60000 }) * async processPayment(paymentId: string) { * // Lock key: lock:payment:pay123:process * } * * // With fallback key * @UseRedisLockWithDynamicKey('{userId}', { * * ttl: 60000, * * onMissingParam: 'fallback', * * fallbackKey: 'default-user-lock' * * }) * async updateUser(userId?: string, data: any) { * // Falls back to 'lock:default-user-lock' if userId is undefined * * } * } * ``` */ export declare function UseRedisLockWithDynamicKey(keyTemplate: string, options?: DynamicKeyDecoratorOptions): MethodDecorator; /** * Simplified dynamic key decorator for methods that should skip execution if lock cannot be acquired * Returns false when skipped, true when executed successfully * * @param keyTemplate - Template string with placeholders * @param ttl - Lock TTL in milliseconds (default: 300000 / 5 minutes) * * @example * ```typescript * @Injectable() * class MyScheduler { * @Cron('0 * * * *') * @UseRedisLockWithDynamicKeyOrSkip('user:{userId}:task', 3600000) * async hourlyTask(userId: string) { * // Lock key: lock:user:user123:task * // This will only execute on one instance * * } * } * ``` */ export declare function UseRedisLockWithDynamicKeyOrSkip(keyTemplate: string, ttl?: number): MethodDecorator; /** * Smart dynamic key decorator with auto-generated fallback key * Uses the template for normal operation, but falls back to ClassName:methodName * if parameter resolution fails * * @param keyTemplate - Template string with placeholders * @param options - Lock options (template options are set to use fallback) * * @example * ```typescript * @Injectable() * class MyService { * @UseRedisLockWithDynamicKeySmart('{userId}', { ttl: 60000 }) * async processData(userId: string) { * // Lock key: lock:user123 * // Falls back to lock:MyService:processData if userId is undefined * * } * } * ``` */ export declare function UseRedisLockWithDynamicKeySmart(keyTemplate: string, options?: Omit): MethodDecorator;