bun-types
Version:
Type definitions and documentation for Bun, an incredibly fast JavaScript runtime
1,253 lines (1,144 loc) • 135 kB
TypeScript
declare module "bun" {
export interface RedisOptions {
/**
* Connection timeout in milliseconds
* @default 10000
*/
connectionTimeout?: number;
/**
* Idle timeout in milliseconds
* @default 0 (no timeout)
*/
idleTimeout?: number;
/**
* Whether to automatically reconnect
* @default true
*/
autoReconnect?: boolean;
/**
* Maximum number of reconnection attempts
* @default 10
*/
maxRetries?: number;
/**
* Whether to queue commands when disconnected
* @default true
*/
enableOfflineQueue?: boolean;
/**
* TLS options
* Can be a boolean or an object with TLS options
*/
tls?: boolean | Bun.TLSOptions;
/**
* Whether to enable auto-pipelining
* @default true
*/
enableAutoPipelining?: boolean;
}
export namespace RedisClient {
type KeyLike = string | ArrayBufferView | Blob;
type StringPubSubListener = (message: string, channel: string) => void;
// Buffer subscriptions are not yet implemented
// type BufferPubSubListener = (message: Uint8Array<ArrayBuffer>, channel: string) => void;
}
export class RedisClient {
/**
* Creates a new Redis client
*
* @param url URL to connect to, defaults to `process.env.VALKEY_URL`,
* `process.env.REDIS_URL`, or `"valkey://localhost:6379"`
* @param options Additional options
*
* @example
* ```ts
* const redis = new RedisClient();
* await redis.set("hello", "world");
* console.log(await redis.get("hello"));
* ```
*/
constructor(url?: string, options?: RedisOptions);
/**
* Whether the client is connected to the Redis server
*/
readonly connected: boolean;
/**
* Amount of data buffered in bytes
*/
readonly bufferedAmount: number;
/**
* Callback fired when the client connects to the Redis server
*/
onconnect: ((this: RedisClient) => void) | null;
/**
* Callback fired when the client disconnects from the Redis server
*
* @param error The error that caused the disconnection
*/
onclose: ((this: RedisClient, error: Error) => void) | null;
/**
* Connect to the Redis server
*
* @returns A promise that resolves when connected
*/
connect(): Promise<void>;
/**
* Disconnect from the Redis server
*/
close(): void;
/**
* Send a raw command to the Redis server
* @param command The command to send
* @param args The arguments to the command
* @returns A promise that resolves with the command result
*/
send(command: string, args: string[]): Promise<any>;
/**
* Get the value of a key
* @param key The key to get
* @returns Promise that resolves with the key's value as a string, or null if the key doesn't exist
*/
get(key: RedisClient.KeyLike): Promise<string | null>;
/**
* Get the value of a key as a Uint8Array
* @param key The key to get
* @returns Promise that resolves with the key's value as a Uint8Array, or null if the key doesn't exist
*/
getBuffer(key: RedisClient.KeyLike): Promise<Uint8Array<ArrayBuffer> | null>;
/**
* Set key to hold the string value
* @param key The key to set
* @param value The value to set
* @returns Promise that resolves with "OK" on success
*/
set(key: RedisClient.KeyLike, value: RedisClient.KeyLike): Promise<"OK">;
/**
* Set key to hold the string value with expiration
* @param key The key to set
* @param value The value to set
* @param ex Set the specified expire time, in seconds
* @returns Promise that resolves with "OK" on success
*/
set(key: RedisClient.KeyLike, value: RedisClient.KeyLike, ex: "EX", seconds: number): Promise<"OK">;
/**
* Set key to hold the string value with expiration
* @param key The key to set
* @param value The value to set
* @param px Set the specified expire time, in milliseconds
* @returns Promise that resolves with "OK" on success
*/
set(key: RedisClient.KeyLike, value: RedisClient.KeyLike, px: "PX", milliseconds: number): Promise<"OK">;
/**
* Set key to hold the string value with expiration at a specific Unix
* timestamp
* @param key The key to set
* @param value The value to set
* @param exat Set the specified Unix time at which the key will expire, in
* seconds
* @returns Promise that resolves with "OK" on success
*/
set(key: RedisClient.KeyLike, value: RedisClient.KeyLike, exat: "EXAT", timestampSeconds: number): Promise<"OK">;
/**
* Set key to hold the string value with expiration at a specific Unix timestamp
* @param key The key to set
* @param value The value to set
* @param pxat Set the specified Unix time at which the key will expire, in milliseconds
* @returns Promise that resolves with "OK" on success
*/
set(
key: RedisClient.KeyLike,
value: RedisClient.KeyLike,
pxat: "PXAT",
timestampMilliseconds: number,
): Promise<"OK">;
/**
* Set key to hold the string value only if key does not exist
* @param key The key to set
* @param value The value to set
* @param nx Only set the key if it does not already exist
* @returns Promise that resolves with "OK" on success, or null if the key
* already exists
*/
set(key: RedisClient.KeyLike, value: RedisClient.KeyLike, nx: "NX"): Promise<"OK" | null>;
/**
* Set key to hold the string value only if key already exists
* @param key The key to set
* @param value The value to set
* @param xx Only set the key if it already exists
* @returns Promise that resolves with "OK" on success, or null if the key
* does not exist
*/
set(key: RedisClient.KeyLike, value: RedisClient.KeyLike, xx: "XX"): Promise<"OK" | null>;
/**
* Set key to hold the string value and return the old value
* @param key The key to set
* @param value The value to set
* @param get Return the old string stored at key, or null if key did not
* exist
* @returns Promise that resolves with the old value, or null if key did not
* exist
*/
set(key: RedisClient.KeyLike, value: RedisClient.KeyLike, get: "GET"): Promise<string | null>;
/**
* Set key to hold the string value and retain the time to live
* @param key The key to set
* @param value The value to set
* @param keepttl Retain the time to live associated with the key
* @returns Promise that resolves with "OK" on success
*/
set(key: RedisClient.KeyLike, value: RedisClient.KeyLike, keepttl: "KEEPTTL"): Promise<"OK">;
/**
* Set key to hold the string value with various options
* @param key The key to set
* @param value The value to set
* @param options Array of options (EX, PX, EXAT, PXAT, NX, XX, KEEPTTL, GET)
* @returns Promise that resolves with "OK" on success, null if NX/XX condition not met, or the old value if GET is specified
*/
set(key: RedisClient.KeyLike, value: RedisClient.KeyLike, ...options: string[]): Promise<"OK" | string | null>;
/**
* Delete a key(s)
* @param keys The keys to delete
* @returns Promise that resolves with the number of keys removed
*/
del(...keys: RedisClient.KeyLike[]): Promise<number>;
/**
* Increment the integer value of a key by one
* @param key The key to increment
* @returns Promise that resolves with the new value
*/
incr(key: RedisClient.KeyLike): Promise<number>;
/**
* Increment the integer value of a key by the given amount
* @param key The key to increment
* @param increment The amount to increment by
* @returns Promise that resolves with the new value after incrementing
*/
incrby(key: RedisClient.KeyLike, increment: number): Promise<number>;
/**
* Increment the float value of a key by the given amount
* @param key The key to increment
* @param increment The amount to increment by (can be a float)
* @returns Promise that resolves with the new value as a string after incrementing
*/
incrbyfloat(key: RedisClient.KeyLike, increment: number | string): Promise<string>;
/**
* Decrement the integer value of a key by one
* @param key The key to decrement
* @returns Promise that resolves with the new value
*/
decr(key: RedisClient.KeyLike): Promise<number>;
/**
* Decrement the integer value of a key by the given amount
* @param key The key to decrement
* @param decrement The amount to decrement by
* @returns Promise that resolves with the new value after decrementing
*/
decrby(key: RedisClient.KeyLike, decrement: number): Promise<number>;
/**
* Determine if a key exists
* @param key The key to check
* @returns Promise that resolves with true if the key exists, false
* otherwise
*/
exists(key: RedisClient.KeyLike): Promise<boolean>;
/**
* Set a key's time to live in seconds
* @param key The key to set the expiration for
* @param seconds The number of seconds until expiration
* @returns Promise that resolves with 1 if the timeout was set, 0 if not
*/
expire(key: RedisClient.KeyLike, seconds: number): Promise<number>;
/**
* Set the expiration for a key as a Unix timestamp (in seconds)
* @param key The key to set expiration on
* @param timestamp Unix timestamp in seconds when the key should expire
* @returns Promise that resolves with 1 if timeout was set, 0 if key does not exist
*/
expireat(key: RedisClient.KeyLike, timestamp: number): Promise<number>;
/**
* Set a key's time to live in milliseconds
* @param key The key to set the expiration for
* @param milliseconds The number of milliseconds until expiration
* @returns Promise that resolves with 1 if the timeout was set, 0 if the key does not exist
*/
pexpire(key: RedisClient.KeyLike, milliseconds: number): Promise<number>;
/**
* Get the time to live for a key in seconds
* @param key The key to get the TTL for
* @returns Promise that resolves with the TTL, -1 if no expiry, or -2 if
* key doesn't exist
*/
ttl(key: RedisClient.KeyLike): Promise<number>;
/**
* Set the value of a hash field or multiple fields
* @param key The hash key
* @param fields Object/Record with field-value pairs
* @returns Promise that resolves with the number of fields that were added
*/
hset(key: RedisClient.KeyLike, fields: Record<string | number, RedisClient.KeyLike | number>): Promise<number>;
/**
* Set the value of a hash field or multiple fields (variadic)
* @param key The hash key
* @param field The field name
* @param value The value to set
* @param rest Additional field-value pairs
* @returns Promise that resolves with the number of fields that were added
*/
hset(
key: RedisClient.KeyLike,
field: RedisClient.KeyLike,
value: RedisClient.KeyLike,
...rest: RedisClient.KeyLike[]
): Promise<number>;
/**
* Set the value of a hash field, only if the field does not exist
* @param key The hash key
* @param field The field to set
* @param value The value to set
* @returns Promise that resolves with true if field was set, false if field already exists
*/
hsetnx(key: RedisClient.KeyLike, field: RedisClient.KeyLike, value: RedisClient.KeyLike): Promise<boolean>;
/**
* Get and delete one or more hash fields (Redis 8.0.0+)
* Syntax: HGETDEL key FIELDS numfields field [field ...]
* @param key The hash key
* @param fieldsKeyword Must be the literal string "FIELDS"
* @param numfields Number of fields to follow
* @param fields The field names to get and delete
* @returns Promise that resolves with array of field values (null for non-existent fields)
* @example redis.hgetdel("mykey", "FIELDS", 2, "field1", "field2")
*/
hgetdel(
key: RedisClient.KeyLike,
fieldsKeyword: "FIELDS",
numfields: number,
...fields: RedisClient.KeyLike[]
): Promise<Array<string | null>>;
/**
* Get hash field values with expiration options (Redis 8.0.0+)
* Syntax: HGETEX key [EX seconds | PX milliseconds | EXAT unix-time-seconds | PXAT unix-time-milliseconds | PERSIST] FIELDS numfields field [field ...]
* @example redis.hgetex("mykey", "FIELDS", 1, "field1")
* @example redis.hgetex("mykey", "EX", 10, "FIELDS", 1, "field1")
* @example redis.hgetex("mykey", "PX", 5000, "FIELDS", 2, "field1", "field2")
* @example redis.hgetex("mykey", "PERSIST", "FIELDS", 1, "field1")
*/
//prettier-ignore
hgetex(key: RedisClient.KeyLike, fieldsKeyword: "FIELDS", numfields: number, ...fields: RedisClient.KeyLike[]): Promise<Array<string | null>>;
//prettier-ignore
hgetex(key: RedisClient.KeyLike, ex: "EX", seconds: number, fieldsKeyword: "FIELDS", numfields: number, ...fields: RedisClient.KeyLike[]): Promise<Array<string | null>>;
//prettier-ignore
hgetex(key: RedisClient.KeyLike, px: "PX", milliseconds: number, fieldsKeyword: "FIELDS", numfields: number, ...fields: RedisClient.KeyLike[]): Promise<Array<string | null>>;
//prettier-ignore
hgetex(key: RedisClient.KeyLike, exat: "EXAT", unixTimeSeconds: number, fieldsKeyword: "FIELDS", numfields: number, ...fields: RedisClient.KeyLike[]): Promise<Array<string | null>>;
//prettier-ignore
hgetex(key: RedisClient.KeyLike, pxat: "PXAT", unixTimeMilliseconds: number, fieldsKeyword: "FIELDS", numfields: number, ...fields: RedisClient.KeyLike[]): Promise<Array<string | null>>;
//prettier-ignore
hgetex(key: RedisClient.KeyLike, persist: "PERSIST", fieldsKeyword: "FIELDS", numfields: number, ...fields: RedisClient.KeyLike[]): Promise<Array<string | null>>;
/**
* Set hash fields with expiration options (Redis 8.0.0+)
* Syntax: HSETEX key [FNX | FXX] [EX seconds | PX milliseconds | EXAT unix-time-seconds | PXAT unix-time-milliseconds | KEEPTTL] FIELDS numfields field value [field value ...]
* @example redis.hsetex("mykey", "FIELDS", 1, "field1", "value1")
* @example redis.hsetex("mykey", "EX", 10, "FIELDS", 1, "field1", "value1")
* @example redis.hsetex("mykey", "FNX", "EX", 10, "FIELDS", 1, "field1", "value1")
*/
//prettier-ignore
hsetex(key: RedisClient.KeyLike, fieldsKeyword: "FIELDS", numfields: number, ...fieldValues: RedisClient.KeyLike[]): Promise<number>;
//prettier-ignore
hsetex(key: RedisClient.KeyLike, fnx: "FNX", fieldsKeyword: "FIELDS", numfields: number, ...fieldValues: RedisClient.KeyLike[]): Promise<number>;
//prettier-ignore
hsetex(key: RedisClient.KeyLike, fxx: "FXX", fieldsKeyword: "FIELDS", numfields: number, ...fieldValues: RedisClient.KeyLike[]): Promise<number>;
//prettier-ignore
hsetex(key: RedisClient.KeyLike, ex: "EX", seconds: number, fieldsKeyword: "FIELDS", numfields: number, ...fieldValues: RedisClient.KeyLike[]): Promise<number>;
//prettier-ignore
hsetex(key: RedisClient.KeyLike, px: "PX", milliseconds: number, fieldsKeyword: "FIELDS", numfields: number, ...fieldValues: RedisClient.KeyLike[]): Promise<number>;
//prettier-ignore
hsetex(key: RedisClient.KeyLike, exat: "EXAT", unixTimeSeconds: number, fieldsKeyword: "FIELDS", numfields: number, ...fieldValues: RedisClient.KeyLike[]): Promise<number>;
//prettier-ignore
hsetex(key: RedisClient.KeyLike, pxat: "PXAT", unixTimeMilliseconds: number, fieldsKeyword: "FIELDS", numfields: number, ...fieldValues: RedisClient.KeyLike[]): Promise<number>;
//prettier-ignore
hsetex(key: RedisClient.KeyLike, keepttl: "KEEPTTL", fieldsKeyword: "FIELDS", numfields: number, ...fieldValues: RedisClient.KeyLike[]): Promise<number>;
//prettier-ignore
hsetex(key: RedisClient.KeyLike, fnx: "FNX", ex: "EX", seconds: number, fieldsKeyword: "FIELDS", numfields: number, ...fieldValues: RedisClient.KeyLike[]): Promise<number>;
//prettier-ignore
hsetex(key: RedisClient.KeyLike, fnx: "FNX", px: "PX", milliseconds: number, fieldsKeyword: "FIELDS", numfields: number, ...fieldValues: RedisClient.KeyLike[]): Promise<number>;
//prettier-ignore
hsetex(key: RedisClient.KeyLike, fnx: "FNX", exat: "EXAT", unixTimeSeconds: number, fieldsKeyword: "FIELDS", numfields: number, ...fieldValues: RedisClient.KeyLike[]): Promise<number>;
//prettier-ignore
hsetex(key: RedisClient.KeyLike, fnx: "FNX", pxat: "PXAT", unixTimeMilliseconds: number, fieldsKeyword: "FIELDS", numfields: number, ...fieldValues: RedisClient.KeyLike[]): Promise<number>;
//prettier-ignore
hsetex(key: RedisClient.KeyLike, fnx: "FNX", keepttl: "KEEPTTL", fieldsKeyword: "FIELDS", numfields: number, ...fieldValues: RedisClient.KeyLike[]): Promise<number>;
//prettier-ignore
hsetex(key: RedisClient.KeyLike, fxx: "FXX", ex: "EX", seconds: number, fieldsKeyword: "FIELDS", numfields: number, ...fieldValues: RedisClient.KeyLike[]): Promise<number>;
//prettier-ignore
hsetex(key: RedisClient.KeyLike, fxx: "FXX", px: "PX", milliseconds: number, fieldsKeyword: "FIELDS", numfields: number, ...fieldValues: RedisClient.KeyLike[]): Promise<number>;
//prettier-ignore
hsetex(key: RedisClient.KeyLike, fxx: "FXX", exat: "EXAT", unixTimeSeconds: number, fieldsKeyword: "FIELDS", numfields: number, ...fieldValues: RedisClient.KeyLike[]): Promise<number>;
//prettier-ignore
hsetex(key: RedisClient.KeyLike, fxx: "FXX", pxat: "PXAT", unixTimeMilliseconds: number, fieldsKeyword: "FIELDS", numfields: number, ...fieldValues: RedisClient.KeyLike[]): Promise<number>;
//prettier-ignore
hsetex(key: RedisClient.KeyLike, fxx: "FXX", keepttl: "KEEPTTL", fieldsKeyword: "FIELDS", numfields: number, ...fieldValues: RedisClient.KeyLike[]): Promise<number>;
/**
* Set expiration for hash fields (Redis 7.4+)
* Syntax: HEXPIRE key seconds [NX | XX | GT | LT] FIELDS numfields field [field ...]
* @returns Array where each element is: -2 (field doesn't exist), 0 (condition not met), 1 (expiration set), 2 (field deleted)
* @example redis.hexpire("mykey", 10, "FIELDS", 1, "field1")
* @example redis.hexpire("mykey", 10, "NX", "FIELDS", 2, "field1", "field2")
*/
hexpire(
key: RedisClient.KeyLike,
seconds: number,
fieldsKeyword: "FIELDS",
numfields: number,
...fields: RedisClient.KeyLike[]
): Promise<number[]>;
hexpire(
key: RedisClient.KeyLike,
seconds: number,
condition: "NX" | "XX" | "GT" | "LT",
fieldsKeyword: "FIELDS",
numfields: number,
...fields: RedisClient.KeyLike[]
): Promise<number[]>;
/**
* Set expiration for hash fields using Unix timestamp in seconds (Redis 7.4+)
* Syntax: HEXPIREAT key unix-time-seconds [NX | XX | GT | LT] FIELDS numfields field [field ...]
* @returns Array where each element is: -2 (field doesn't exist), 0 (condition not met), 1 (expiration set), 2 (field deleted)
* @example redis.hexpireat("mykey", 1735689600, "FIELDS", 1, "field1")
*/
hexpireat(
key: RedisClient.KeyLike,
unixTimeSeconds: number,
fieldsKeyword: "FIELDS",
numfields: number,
...fields: RedisClient.KeyLike[]
): Promise<number[]>;
hexpireat(
key: RedisClient.KeyLike,
unixTimeSeconds: number,
condition: "NX" | "XX" | "GT" | "LT",
fieldsKeyword: "FIELDS",
numfields: number,
...fields: RedisClient.KeyLike[]
): Promise<number[]>;
/**
* Get expiration time of hash fields as Unix timestamp in seconds (Redis 7.4+)
* Syntax: HEXPIRETIME key FIELDS numfields field [field ...]
* @returns Array where each element is: -2 (field doesn't exist), -1 (no expiration), Unix timestamp in seconds
* @example redis.hexpiretime("mykey", "FIELDS", 2, "field1", "field2")
*/
hexpiretime(
key: RedisClient.KeyLike,
fieldsKeyword: "FIELDS",
numfields: number,
...fields: RedisClient.KeyLike[]
): Promise<number[]>;
/**
* Remove expiration from hash fields (Redis 7.4+)
* Syntax: HPERSIST key FIELDS numfields field [field ...]
* @returns Array where each element is: -2 (field doesn't exist), -1 (no expiration), 1 (expiration removed)
* @example redis.hpersist("mykey", "FIELDS", 1, "field1")
*/
hpersist(
key: RedisClient.KeyLike,
fieldsKeyword: "FIELDS",
numfields: number,
...fields: RedisClient.KeyLike[]
): Promise<number[]>;
/**
* Set expiration for hash fields in milliseconds (Redis 7.4+)
* Syntax: HPEXPIRE key milliseconds [NX | XX | GT | LT] FIELDS numfields field [field ...]
* @returns Array where each element is: -2 (field doesn't exist), 0 (condition not met), 1 (expiration set), 2 (field deleted)
* @example redis.hpexpire("mykey", 10000, "FIELDS", 1, "field1")
*/
hpexpire(
key: RedisClient.KeyLike,
milliseconds: number,
fieldsKeyword: "FIELDS",
numfields: number,
...fields: RedisClient.KeyLike[]
): Promise<number[]>;
hpexpire(
key: RedisClient.KeyLike,
milliseconds: number,
condition: "NX" | "XX" | "GT" | "LT",
fieldsKeyword: "FIELDS",
numfields: number,
...fields: RedisClient.KeyLike[]
): Promise<number[]>;
/**
* Set expiration for hash fields using Unix timestamp in milliseconds (Redis 7.4+)
* Syntax: HPEXPIREAT key unix-time-milliseconds [NX | XX | GT | LT] FIELDS numfields field [field ...]
* @returns Array where each element is: -2 (field doesn't exist), 0 (condition not met), 1 (expiration set), 2 (field deleted)
* @example redis.hpexpireat("mykey", 1735689600000, "FIELDS", 1, "field1")
*/
hpexpireat(
key: RedisClient.KeyLike,
unixTimeMilliseconds: number,
fieldsKeyword: "FIELDS",
numfields: number,
...fields: RedisClient.KeyLike[]
): Promise<number[]>;
hpexpireat(
key: RedisClient.KeyLike,
unixTimeMilliseconds: number,
condition: "NX" | "XX" | "GT" | "LT",
fieldsKeyword: "FIELDS",
numfields: number,
...fields: RedisClient.KeyLike[]
): Promise<number[]>;
/**
* Get expiration time of hash fields as Unix timestamp in milliseconds (Redis 7.4+)
* Syntax: HPEXPIRETIME key FIELDS numfields field [field ...]
* @returns Array where each element is: -2 (field doesn't exist), -1 (no expiration), Unix timestamp in milliseconds
* @example redis.hpexpiretime("mykey", "FIELDS", 2, "field1", "field2")
*/
hpexpiretime(
key: RedisClient.KeyLike,
fieldsKeyword: "FIELDS",
numfields: number,
...fields: RedisClient.KeyLike[]
): Promise<number[]>;
/**
* Get TTL of hash fields in milliseconds (Redis 7.4+)
* Syntax: HPTTL key FIELDS numfields field [field ...]
* @returns Array where each element is: -2 (field doesn't exist), -1 (no expiration), TTL in milliseconds
* @example redis.hpttl("mykey", "FIELDS", 2, "field1", "field2")
*/
hpttl(
key: RedisClient.KeyLike,
fieldsKeyword: "FIELDS",
numfields: number,
...fields: RedisClient.KeyLike[]
): Promise<number[]>;
/**
* Get TTL of hash fields in seconds (Redis 7.4+)
* Syntax: HTTL key FIELDS numfields field [field ...]
* @returns Array where each element is: -2 (field doesn't exist), -1 (no expiration), TTL in seconds
* @example redis.httl("mykey", "FIELDS", 2, "field1", "field2")
*/
httl(
key: RedisClient.KeyLike,
fieldsKeyword: "FIELDS",
numfields: number,
...fields: RedisClient.KeyLike[]
): Promise<number[]>;
/**
* Set multiple hash fields to multiple values
*
* @deprecated Use {@link hset} instead. Since Redis 4.0.0, `HSET` supports multiple field-value pairs.
*
* @param key The hash key
* @param fields Object/Record with field-value pairs
* @returns Promise that resolves with "OK"
*/
hmset(key: RedisClient.KeyLike, fields: Record<string | number, RedisClient.KeyLike | number>): Promise<"OK">;
/**
* Set multiple hash fields to multiple values (variadic)
*
* @deprecated Use {@link hset} instead. Since Redis 4.0.0, `HSET` supports multiple field-value pairs.
*
* @param key The hash key
* @param field The field name
* @param value The value to set
* @param rest Additional field-value pairs
* @returns Promise that resolves with "OK"
*/
hmset(
key: RedisClient.KeyLike,
field: RedisClient.KeyLike,
value: RedisClient.KeyLike,
...rest: RedisClient.KeyLike[]
): Promise<"OK">;
/**
* Set multiple hash fields to multiple values (array syntax, backward compat)
*
* @deprecated Use {@link hset} instead. Since Redis 4.0.0, `HSET` supports multiple field-value pairs.
*
* @param key The hash key
* @param fieldValues An array of alternating field names and values
* @returns Promise that resolves with "OK"
*/
hmset(key: RedisClient.KeyLike, fieldValues: RedisClient.KeyLike[]): Promise<"OK">;
/**
* Get the value of a hash field
* @param key The hash key
* @param field The field to get
* @returns Promise that resolves with the field value or null if the field doesn't exist
*/
hget(key: RedisClient.KeyLike, field: RedisClient.KeyLike): Promise<string | null>;
/**
* Get the values of all the given hash fields
* @param key The hash key
* @param fields The fields to get
* @returns Promise that resolves with an array of values
*/
hmget(key: RedisClient.KeyLike, ...fields: string[]): Promise<Array<string | null>>;
/**
* Get the values of all the given hash fields
* @param key The hash key
* @param fields The fields to get
* @returns Promise that resolves with an array of values
*/
hmget(key: RedisClient.KeyLike, fields: string[]): Promise<Array<string | null>>;
/**
* Delete one or more hash fields
* @param key The hash key
* @param field The field to delete
* @param rest Additional fields to delete
* @returns Promise that resolves with the number of fields that were removed
*/
hdel(key: RedisClient.KeyLike, field: RedisClient.KeyLike, ...rest: RedisClient.KeyLike[]): Promise<number>;
/**
* Determine if a hash field exists
* @param key The hash key
* @param field The field to check
* @returns Promise that resolves with true if the field exists, false otherwise
*/
hexists(key: RedisClient.KeyLike, field: RedisClient.KeyLike): Promise<boolean>;
/**
* Get one or multiple random fields from a hash
* @param key The hash key
* @returns Promise that resolves with a random field name, or null if the hash doesn't exist
*/
hrandfield(key: RedisClient.KeyLike): Promise<string | null>;
/**
* Get one or multiple random fields from a hash
* @param key The hash key
* @param count The number of fields to return (positive for unique fields, negative for potentially duplicate fields)
* @returns Promise that resolves with an array of random field names
*/
hrandfield(key: RedisClient.KeyLike, count: number): Promise<string[]>;
/**
* Get one or multiple random fields with values from a hash
* @param key The hash key
* @param count The number of fields to return
* @param withValues Literal "WITHVALUES" to include values
* @returns Promise that resolves with an array of alternating field names and values
*/
hrandfield(key: RedisClient.KeyLike, count: number, withValues: "WITHVALUES"): Promise<[string, string][]>;
/**
* Incrementally iterate hash fields and values
* @param key The hash key
* @param cursor The cursor value (0 to start iteration)
* @returns Promise that resolves with [next_cursor, [field1, value1, field2, value2, ...]]
*/
hscan(key: RedisClient.KeyLike, cursor: number | string): Promise<[string, string[]]>;
/**
* Incrementally iterate hash fields and values with pattern matching
* @param key The hash key
* @param cursor The cursor value (0 to start iteration)
* @param match Literal "MATCH"
* @param pattern Pattern to match field names against
* @returns Promise that resolves with [next_cursor, [field1, value1, field2, value2, ...]]
*/
hscan(
key: RedisClient.KeyLike,
cursor: number | string,
match: "MATCH",
pattern: string,
): Promise<[string, string[]]>;
/**
* Incrementally iterate hash fields and values with count limit
* @param key The hash key
* @param cursor The cursor value (0 to start iteration)
* @param count Literal "COUNT"
* @param limit Maximum number of fields to return per call
* @returns Promise that resolves with [next_cursor, [field1, value1, field2, value2, ...]]
*/
hscan(
key: RedisClient.KeyLike,
cursor: number | string,
count: "COUNT",
limit: number,
): Promise<[string, string[]]>;
/**
* Incrementally iterate hash fields and values with pattern and count
* @param key The hash key
* @param cursor The cursor value (0 to start iteration)
* @param match Literal "MATCH"
* @param pattern Pattern to match field names against
* @param count Literal "COUNT"
* @param limit Maximum number of fields to return per call
* @returns Promise that resolves with [next_cursor, [field1, value1, field2, value2, ...]]
*/
hscan(
key: RedisClient.KeyLike,
cursor: number | string,
match: "MATCH",
pattern: string,
count: "COUNT",
limit: number,
): Promise<[string, string[]]>;
/**
* Check if a value is a member of a set
* @param key The set key
* @param member The member to check
* @returns Promise that resolves with true if the member exists, false
* otherwise
*/
sismember(key: RedisClient.KeyLike, member: string): Promise<boolean>;
/**
* Add one or more members to a set
* @param key The set key
* @param members The members to add
* @returns Promise that resolves with the number of members added
*/
sadd(key: RedisClient.KeyLike, ...members: string[]): Promise<number>;
/**
* Remove one or more members from a set
* @param key The set key
* @param members The members to remove
* @returns Promise that resolves with the number of members removed
*/
srem(key: RedisClient.KeyLike, ...members: string[]): Promise<number>;
/**
* Move a member from one set to another
* @param source The source set key
* @param destination The destination set key
* @param member The member to move
* @returns Promise that resolves with true if the element was moved, false if it wasn't a member of source
*/
smove(source: RedisClient.KeyLike, destination: RedisClient.KeyLike, member: string): Promise<boolean>;
/**
* Get all the members in a set
* @param key The set key
* @returns Promise that resolves with an array of all members
*/
smembers(key: RedisClient.KeyLike): Promise<string[]>;
/**
* Get a random member from a set
* @param key The set key
* @returns Promise that resolves with a random member, or null if the set
* is empty
*/
srandmember(key: RedisClient.KeyLike): Promise<string | null>;
/**
* Get count random members from a set
* @param key The set key
* @returns Promise that resolves with an array of up to count random members, or null if the set
* doesn't exist
*/
srandmember(key: RedisClient.KeyLike, count: number): Promise<string[] | null>;
/**
* Remove and return a random member from a set
* @param key The set key
* @returns Promise that resolves with the removed member, or null if the
* set is empty
*/
spop(key: RedisClient.KeyLike): Promise<string | null>;
/**
* Remove and return count members from the set
* @param key The set key
* @returns Promise that resolves with the removed members, or null if the
* set is empty
*/
spop(key: RedisClient.KeyLike, count: number): Promise<string[] | null>;
/**
* Post a message to a shard channel
* @param channel The shard channel name
* @param message The message to publish
* @returns Promise that resolves with the number of clients that received the message
*/
spublish(channel: RedisClient.KeyLike, message: string): Promise<number>;
/**
* Store the difference of multiple sets in a key
* @param destination The destination key to store the result
* @param key The first set key
* @param keys Additional set keys to subtract from the first set
* @returns Promise that resolves with the number of elements in the resulting set
*/
sdiffstore(
destination: RedisClient.KeyLike,
key: RedisClient.KeyLike,
...keys: RedisClient.KeyLike[]
): Promise<number>;
/**
* Check if multiple members are members of a set
* @param key The set key
* @param member The first member to check
* @param members Additional members to check
* @returns Promise that resolves with an array of 1s and 0s indicating membership
*/
smismember(
key: RedisClient.KeyLike,
member: RedisClient.KeyLike,
...members: RedisClient.KeyLike[]
): Promise<number[]>;
/**
* Incrementally iterate over a set
* @param key The set key
* @param cursor The cursor value
* @param args Additional SSCAN options (MATCH pattern, COUNT hint)
* @returns Promise that resolves with a tuple [cursor, members[]]
*/
sscan(key: RedisClient.KeyLike, cursor: number | string, ...args: (string | number)[]): Promise<[string, string[]]>;
/**
* Increment the integer value of a hash field by the given number
* @param key The hash key
* @param field The field to increment
* @param increment The amount to increment by
* @returns Promise that resolves with the new value
*/
hincrby(key: RedisClient.KeyLike, field: string, increment: string | number): Promise<number>;
/**
* Increment the float value of a hash field by the given amount
* @param key The hash key
* @param field The field to increment
* @param increment The amount to increment by
* @returns Promise that resolves with the new value as a string
*/
hincrbyfloat(key: RedisClient.KeyLike, field: string, increment: string | number): Promise<string>;
/**
* Get all the fields and values in a hash
* @param key The hash key
* @returns Promise that resolves with an object containing all fields and values, or empty object if key does not exist
*/
hgetall(key: RedisClient.KeyLike): Promise<Record<string, string>>;
/**
* Get all field names in a hash
* @param key The hash key
* @returns Promise that resolves with an array of field names
*/
hkeys(key: RedisClient.KeyLike): Promise<string[]>;
/**
* Get the number of fields in a hash
* @param key The hash key
* @returns Promise that resolves with the number of fields
*/
hlen(key: RedisClient.KeyLike): Promise<number>;
/**
* Get the string length of the value stored in a hash field
* @param key The hash key
* @param field The field name
* @returns Promise that resolves with the length of the string value, or 0 if the field doesn't exist
*/
hstrlen(key: RedisClient.KeyLike, field: string): Promise<number>;
/**
* Get all values in a hash
* @param key The hash key
* @returns Promise that resolves with an array of values
*/
hvals(key: RedisClient.KeyLike): Promise<string[]>;
/**
* Find all keys matching the given pattern
* @param pattern The pattern to match
* @returns Promise that resolves with an array of matching keys
*/
keys(pattern: string): Promise<string[]>;
/**
* Blocking pop from head of one or more lists
*
* Blocks until an element is available in one of the lists or the timeout expires.
* Checks keys in order and pops from the first non-empty list.
*
* @param args Keys followed by timeout in seconds (can be fractional, 0 = block indefinitely)
* @returns Promise that resolves with [key, element] or null on timeout
*
* @example
* ```ts
* // Block for up to 1 second
* const result = await redis.blpop("mylist", 1.0);
* if (result) {
* const [key, element] = result;
* console.log(`Popped ${element} from ${key}`);
* }
*
* // Block indefinitely (timeout = 0)
* const result2 = await redis.blpop("list1", "list2", 0);
* ```
*/
blpop(...args: (RedisClient.KeyLike | number)[]): Promise<[string, string] | null>;
/**
* Blocking pop from tail of one or more lists
*
* Blocks until an element is available in one of the lists or the timeout expires.
* Checks keys in order and pops from the first non-empty list.
*
* @param args Keys followed by timeout in seconds (can be fractional, 0 = block indefinitely)
* @returns Promise that resolves with [key, element] or null on timeout
*
* @example
* ```ts
* // Block for up to 1 second
* const result = await redis.brpop("mylist", 1.0);
* if (result) {
* const [key, element] = result;
* console.log(`Popped ${element} from ${key}`);
* }
*
* // Block indefinitely (timeout = 0)
* const result2 = await redis.brpop("list1", "list2", 0);
* ```
*/
brpop(...args: (RedisClient.KeyLike | number)[]): Promise<[string, string] | null>;
/**
* Blocking move from one list to another
*
* Atomically moves an element from source to destination list, blocking until an element is available
* or the timeout expires. Allows specifying which end to pop from (LEFT/RIGHT) and which end to push to (LEFT/RIGHT).
*
* @param source Source list key
* @param destination Destination list key
* @param from Direction to pop from source: "LEFT" or "RIGHT"
* @param to Direction to push to destination: "LEFT" or "RIGHT"
* @param timeout Timeout in seconds (can be fractional, 0 = block indefinitely)
* @returns Promise that resolves with the moved element or null on timeout
*
* @example
* ```ts
* // Move from right of source to left of destination (like BRPOPLPUSH)
* const element = await redis.blmove("mylist", "otherlist", "RIGHT", "LEFT", 1.0);
* if (element) {
* console.log(`Moved element: ${element}`);
* }
*
* // Move from left to left
* await redis.blmove("list1", "list2", "LEFT", "LEFT", 0.5);
* ```
*/
blmove(
source: RedisClient.KeyLike,
destination: RedisClient.KeyLike,
from: "LEFT" | "RIGHT",
to: "LEFT" | "RIGHT",
timeout: number,
): Promise<string | null>;
/**
* Blocking pop multiple elements from lists
*
* Blocks until an element is available from one of the specified lists or the timeout expires.
* Can pop from the LEFT or RIGHT end and optionally pop multiple elements at once using COUNT.
*
* @param timeout Timeout in seconds (can be fractional, 0 = block indefinitely)
* @param numkeys Number of keys that follow
* @param args Keys, direction ("LEFT" or "RIGHT"), and optional COUNT modifier
* @returns Promise that resolves with [key, [elements]] or null on timeout
*
* @example
* ```ts
* // Pop from left end of first available list, wait 1 second
* const result = await redis.blmpop(1.0, 2, "list1", "list2", "LEFT");
* if (result) {
* const [key, elements] = result;
* console.log(`Popped from ${key}: ${elements.join(", ")}`);
* }
*
* // Pop 3 elements from right end
* const result2 = await redis.blmpop(0.5, 1, "mylist", "RIGHT", "COUNT", 3);
* // Returns: ["mylist", ["elem1", "elem2", "elem3"]] or null if timeout
* ```
*/
blmpop(timeout: number, numkeys: number, ...args: (string | number)[]): Promise<[string, string[]] | null>;
/**
* Blocking right pop from source and left push to destination
*
* Atomically pops an element from the tail of source list and pushes it to the head of destination list,
* blocking until an element is available or the timeout expires. This is the blocking version of RPOPLPUSH.
*
* @param source Source list key
* @param destination Destination list key
* @param timeout Timeout in seconds (can be fractional, 0 = block indefinitely)
* @returns Promise that resolves with the moved element or null on timeout
*
* @example
* ```ts
* // Block for up to 1 second
* const element = await redis.brpoplpush("tasks", "processing", 1.0);
* if (element) {
* console.log(`Processing task: ${element}`);
* } else {
* console.log("No tasks available");
* }
*
* // Block indefinitely (timeout = 0)
* const task = await redis.brpoplpush("queue", "active", 0);
* ```
*/
brpoplpush(source: RedisClient.KeyLike, destination: RedisClient.KeyLike, timeout: number): Promise<string | null>;
/**
* Get element at index from a list
* @param key The list key
* @param index Zero-based index (negative indexes count from the end, -1 is last element)
* @returns Promise that resolves with the element at index, or null if index is out of range
*
* @example
* ```ts
* await redis.lpush("mylist", "three", "two", "one");
* console.log(await redis.lindex("mylist", 0)); // "one"
* console.log(await redis.lindex("mylist", -1)); // "three"
* console.log(await redis.lindex("mylist", 5)); // null
* ```
*/
lindex(key: RedisClient.KeyLike, index: number): Promise<string | null>;
/**
* Get the length of a list
* @param key The list key
* @returns Promise that resolves with the length of the list
*/
llen(key: RedisClient.KeyLike): Promise<number>;
/**
* Atomically pop an element from a source list and push it to a destination list
*
* Pops an element from the source list (from LEFT or RIGHT) and pushes it
* to the destination list (to LEFT or RIGHT).
*
* @param source The source list key
* @param destination The destination list key
* @param from Direction to pop from source: "LEFT" (head) or "RIGHT" (tail)
* @param to Direction to push to destination: "LEFT" (head) or "RIGHT" (tail)
* @returns Promise that resolves with the element moved, or null if the source list is empty
*
* @example
* ```ts
* await redis.lpush("source", "a", "b", "c");
* const result1 = await redis.lmove("source", "dest", "LEFT", "RIGHT");
* // result1: "c" (popped from head of source, pushed to tail of dest)
*
* const result2 = await redis.lmove("source", "dest", "RIGHT", "LEFT");
* // result2: "a" (popped from tail of source, pushed to head of dest)
* ```
*/
lmove(
source: RedisClient.KeyLike,
destination: RedisClient.KeyLike,
from: "LEFT" | "RIGHT",
to: "LEFT" | "RIGHT",
): Promise<string | null>;
/**
* Remove and get the first element in a list
* @param key The list key
* @returns Promise that resolves with the first element, or null if the list is empty
*/
lpop(key: RedisClient.KeyLike): Promise<string | null>;
/**
* Remove and get the first count elements in a list
* @param key The list key
* @returns Promise that resolves with a list of elements, or null if the list doesn't exist
*/
lpop(key: RedisClient.KeyLike, count: number): Promise<string[] | null>;
/**
* Find the position(s) of an element in a list
*
* Returns the index of matching elements inside a Redis list.
* By default, returns the index of the first match. Use RANK to find the nth occurrence,
* COUNT to get multiple positions, and MAXLEN to limit the search.
*
* @param key The list key
* @param element The element to search for
* @param options Optional arguments: "RANK", rank, "COUNT", num, "MAXLEN", len
* @returns Promise that resolves with the index (number), an array of indices (number[]),
* or null if element is not found. Returns array when COUNT option is used.
*
* @example
* ```ts
* await redis.lpush("mylist", "a", "b", "c", "b", "d");
* const pos1 = await redis.lpos("mylist", "b");
* // pos1: 1 (first occurrence of "b")
*
* const pos2 = await redis.lpos("mylist", "b", "RANK", 2);
* // pos2: 3 (second occurrence of "b")
*
* const positions = await redis.lpos("mylist", "b", "COUNT", 0);
* // positions: [1, 3] (all occurrences of "b")
*
* const pos3 = await redis.lpos("mylist", "x");
* // pos3: null (element not found)
* ```
*/
lpos(
key: RedisClient.KeyLike,
element: RedisClient.KeyLike,
...options: (string | number)[]
): Promise<number | number[] | null>;
/**
* Pop one or more elements from one or more lists
*
* Pops elements from the first non-empty list in the specified order (LEFT = from head, RIGHT = from tail).
* Optionally specify COUNT to pop multiple elements at once.
*
* @param numkeys The number of keys that follow
* @param args Keys followed by LEFT or RIGHT, optionally followed by "COUNT" and count value
* @returns Promise that resolves with [key, [elements]] or null if all lists are empty
*
* @example
* ```ts
* await redis.lpush("list1", "a", "b", "c");
* const result1 = await redis.lmpop(1, "list1", "LEFT");
* // result1: ["list1", ["c"]]
*
* const result2 = await redis.lmpop(1, "list1", "RIGHT", "COUNT", 2);
* // result2: ["list1", ["a", "b"]]
*
* const result3 = await redis.lmpop(2, "emptylist", "list1", "LEFT");
* // result3: null (if both lists are empty)
* ```
*/
lmpop(numkeys: number, ...args: (string | number)[]): Promise<[string, string[]] | null>;
/**
* Get a range of elements from a list
* @param key The list key
* @param start Zero-based start index (negative indexes count from the end)
* @param stop Zero-based stop index (negative indexes count from the end)
* @returns Promise that resolves with array of elements in the specified range
*
* @example
* ```ts
* await redis.lpush("mylist", "three", "two", "one");
* console.log(await redis.lrange("mylist", 0, -1)); // ["one", "two", "three"]
* console.log(await redis.lrange("mylist", 0, 1)); // ["one", "two"]
* console.log(await redis.lrange("mylist", -2, -1)); // ["two", "three"]
* ```
*/
lrange(key: RedisClient.KeyLike, start: number, stop: number): Promise<string[]>;
/**
* Set element at index in a list
* @param key The list key
* @param index Zero-based index (negative indexes count from the end)
* @param element The value to set
* @returns Promise that resolves with "OK" on success
*
* @example
* ```ts
* await redis.lpush("mylist", "three", "two", "one");
* await redis.lset("mylist", 0, "zero");
* console.log(await redis.lrange("mylist", 0, -1)); // ["zero", "two", "three"]
* await redis.lset("mylist", -1, "last");
* console.log(await redis.lrange("mylist", 0, -1)); // ["zero", "two", "last"]
* ```
*/
lset(key: RedisClient.KeyLike, index: number, element: RedisClient.KeyLike): Promise<string>;
/**
* Remove the expiration from a key
* @param key The key to persist
* @returns Promise that resolves with 1 if the timeout was removed, 0 if
* the key doesn't exist or has no timeout
*/
persist(key: RedisClient.KeyLike): Promise<number>;
/**
* Set the expiration for a key as a Unix timestamp in milliseconds
* @param key The key to set expiration on
* @param millisecondsTimestamp Unix timestamp in milliseconds when the key should expire
* @returns Promise that resolves with 1 if timeout was set, 0 if key does not exist
*/
pexpireat(key: RedisClient.KeyLike, millisecondsTimestamp: number): Promise<number>;
/**
* Get the expiration time of a key as a UNIX timestamp in milliseconds
* @param key The key to check
* @returns Promise that resolves with the timestamp, or -1 if the key has
* no expiration, or -2 if the key doesn't exist
*/
pexpiretime(key: RedisClient.KeyLike): Promise<number>;
/**
* Get the time to live for a key in milliseconds
* @param key The key to check
* @returns Promise that resolves with the TTL in milliseconds, or -1 if the
* key has no expiration, or -2 if the key doesn't exist
*/
pttl(key: RedisClient.KeyLike): Promise<number>;
/**
* Return a random key from the keyspace
*
* Returns a random key from the currently selected database.
*
* @returns Promise that resolves with a random key name, or null if the
* databas