UNPKG

@valkey/valkey-glide

Version:

General Language Independent Driver for the Enterprise (GLIDE) for Valkey

988 lines 154 kB
/** * Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 */ import { // eslint-disable-line @typescript-eslint/no-unused-vars GlideRecord, GlideString, HashDataType, Score, ElementAndScore } from "./BaseClient"; import { AggregationType, BaseScanOptions, BitFieldGet, // eslint-disable-line @typescript-eslint/no-unused-vars BitFieldSubCommands, // eslint-disable-line @typescript-eslint/no-unused-vars BitOffsetOptions, BitwiseOperation, Boundary, // eslint-disable-line @typescript-eslint/no-unused-vars ExpireOptions, FlushMode, FunctionListOptions, // eslint-disable-line @typescript-eslint/no-unused-vars FunctionRestorePolicy, // eslint-disable-line @typescript-eslint/no-unused-vars GeoAddOptions, // eslint-disable-line @typescript-eslint/no-unused-vars GeoSearchResultOptions, GeoSearchShape, GeoSearchStoreResultOptions, GeoUnit, GeospatialData, HScanOptions, InfoOptions, InsertPosition, KeyWeight, LPosOptions, ListDirection, LolwutOptions, // eslint-disable-line @typescript-eslint/no-unused-vars RangeByIndex, RangeByLex, RangeByScore, RestoreOptions, ScoreFilter, SearchOrigin, SetOptions, SortOptions, StreamAddOptions, StreamClaimOptions, StreamGroupOptions, StreamPendingOptions, StreamReadGroupOptions, StreamReadOptions, StreamTrimOptions, TimeUnit, ZAddOptions, ZScanOptions } from "./Commands"; import { command_request } from "./ProtobufMessage"; /** * Base class encompassing shared commands for both standalone and cluster mode implementations in a transaction. * Transactions allow the execution of a group of commands in a single step. * * Command Response: * An array of command responses is returned by the client exec command, in the order they were given. * Each element in the array represents a command given to the transaction. * The response for each command depends on the executed Valkey command. * Specific response types are documented alongside each method. * * @example * ```typescript * const transaction = new BaseTransaction() * .set("key", "value") * .get("key"); * const result = await client.exec(transaction); * console.log(result); // Output: ['OK', 'value'] * ``` */ export declare class BaseTransaction<T extends BaseTransaction<T>> { /** * @internal */ readonly commands: command_request.Command[]; /** * Array of command indexes indicating commands that need to be converted into a `Set` within the transaction. * @internal */ readonly setCommandsIndexes: number[]; /** * Adds a command to the transaction and returns the transaction instance. * @param command - The command to add. * @param shouldConvertToSet - Indicates if the command should be converted to a `Set`. * @returns The updated transaction instance. */ protected addAndReturn(command: command_request.Command, shouldConvertToSet?: boolean): T; /** Get the value associated with the given key, or null if no such value exists. * @see {@link https://valkey.io/commands/get/|valkey.io} for details. * * @param key - The key to retrieve from the database. * * Command Response - If `key` exists, returns the value of `key`. Otherwise, return null. */ get(key: GlideString): T; /** * Get the value of `key` and optionally set its expiration. `GETEX` is similar to {@link get}. * * @see {@link https://valkey.io/commands/getex/|valkey.io} for more details. * @remarks Since Valkey version 6.2.0. * * @param key - The key to retrieve from the database. * @param options - (Optional) set expiriation to the given key. * "persist" will retain the time to live associated with the key. Equivalent to `PERSIST` in the VALKEY API. * Otherwise, a {@link TimeUnit} and duration of the expire time should be specified. * * Command Response - If `key` exists, returns the value of `key` as a `string`. Otherwise, return `null`. */ getex(key: GlideString, options?: "persist" | { type: TimeUnit; duration: number; }): T; /** * Gets a string value associated with the given `key`and deletes the key. * * @see {@link https://valkey.io/commands/getdel/|valkey.io} for details. * * @param key - The key to retrieve from the database. * * Command Response - If `key` exists, returns the `value` of `key`. Otherwise, return `null`. */ getdel(key: GlideString): T; /** * Returns the substring of the string value stored at `key`, determined by the byte offsets * `start` and `end` (both are inclusive). Negative offsets can be used in order to provide * an offset starting from the end of the string. So `-1` means the last character, `-2` the * penultimate and so forth. If `key` does not exist, an empty string is returned. If `start` * or `end` are out of range, returns the substring within the valid range of the string. * * @see {@link https://valkey.io/commands/getrange/|valkey.io} for details. * * @param key - The key of the string. * @param start - The starting byte offset. * @param end - The ending byte offset. * * Command Response - substring extracted from the value stored at `key`. */ getrange(key: GlideString, start: number, end: number): T; /** Set the given key with the given value. Return value is dependent on the passed options. * @see {@link https://valkey.io/commands/set/|valkey.io} for details. * * @param key - The key to store. * @param value - The value to store with the given key. * @param options - The set options. * * Command Response - If the value is successfully set, return OK. * If `value` isn't set because of `onlyIfExists` or `onlyIfDoesNotExist` conditions, return null. * If `returnOldValue` is set, return the old value as a string. */ set(key: GlideString, value: GlideString, options?: SetOptions): T; /** * Pings the server. * * @see {@link https://valkey.io/commands/ping/|valkey.io} for details. * * @param message - (Optional) A message to include in the PING command. * - If not provided, the server will respond with `"PONG"`. * - If provided, the server will respond with a copy of the message. * * Command Response - `"PONG"` if `message` is not provided, otherwise return a copy of `message`. */ ping(message?: GlideString): T; /** * Gets information and statistics about the server. * * @see {@link https://valkey.io/commands/info/|valkey.io} for details. * * @param sections - (Optional) A list of {@link InfoOptions} values specifying which sections of information to retrieve. * When no parameter is provided, {@link InfoOptions.Default|Default} is assumed. * * Command Response - A string containing the information for the sections requested. */ info(sections?: InfoOptions[]): T; /** * Removes the specified keys. A key is ignored if it does not exist. * * @see {@link https://valkey.io/commands/del/|valkey.io} for details. * * @param keys - A list of keys to be deleted from the database. * * Command Response - The number of keys that were removed. */ del(keys: GlideString[]): T; /** * Serialize the value stored at `key` in a Valkey-specific format and return it to the user. * * @see {@link https://valkey.io/commands/dump/|valkey.io} for details. * @remarks To execute a transaction with a `dump` command, the `exec` command requires `Decoder.Bytes` to handle the response. * * @param key - The `key` to serialize. * * Command Response - The serialized value of the data stored at `key`. If `key` does not exist, `null` will be returned. */ dump(key: GlideString): T; /** * Create a `key` associated with a `value` that is obtained by deserializing the provided * serialized `value` (obtained via {@link dump}). * * @see {@link https://valkey.io/commands/restore/|valkey.io} for details. * @remarks `options.idletime` and `options.frequency` modifiers cannot be set at the same time. * * @param key - The `key` to create. * @param ttl - The expiry time (in milliseconds). If `0`, the `key` will persist. * @param value - The serialized value to deserialize and assign to `key`. * @param options - (Optional) Restore options {@link RestoreOptions}. * * Command Response - Return "OK" if the `key` was successfully restored with a `value`. */ restore(key: GlideString, ttl: number, value: Buffer, options?: RestoreOptions): T; /** * Gets the name of the connection on which the transaction is being executed. * * @see {@link https://valkey.io/commands/client-getname/|valkey.io} for details. * * Command Response - The name of the client connection as a string if a name is set, or null if no name is assigned. */ clientGetName(): T; /** * Rewrites the configuration file with the current configuration. * * @see {@link https://valkey.io/commands/select/|valkey.io} for details. * * Command Response - "OK" when the configuration was rewritten properly. Otherwise, the transaction fails with an error. */ configRewrite(): T; /** * Resets the statistics reported by Valkey using the `INFO` and `LATENCY HISTOGRAM` commands. * * @see {@link https://valkey.io/commands/config-resetstat/|valkey.io} for details. * * Command Response - always "OK". */ configResetStat(): T; /** Retrieve the values of multiple keys. * @see {@link https://valkey.io/commands/mget/|valkey.io} for details. * * @param keys - A list of keys to retrieve values for. * * Command Response - A list of values corresponding to the provided keys. If a key is not found, * its corresponding value in the list will be null. */ mget(keys: GlideString[]): T; /** Set multiple keys to multiple values in a single atomic operation. * @see {@link https://valkey.io/commands/mset/|valkey.io} for details. * * @param keysAndValues - A list of key-value pairs to set. * * Command Response - always "OK". */ mset(keysAndValues: Record<string, GlideString> | GlideRecord<GlideString>): T; /** * Sets multiple keys to values if the key does not exist. The operation is atomic, and if one or * more keys already exist, the entire operation fails. * * @see {@link https://valkey.io/commands/msetnx/|valkey.io} for details. * * @param keysAndValues - A list of key-value pairs to set. * Command Response - `true` if all keys were set. `false` if no key was set. */ msetnx(keysAndValues: Record<string, GlideString> | GlideRecord<GlideString>): T; /** Increments the number stored at `key` by one. If `key` does not exist, it is set to 0 before performing the operation. * @see {@link https://valkey.io/commands/incr/|valkey.io} for details. * * @param key - The key to increment its value. * * Command Response - the value of `key` after the increment. */ incr(key: GlideString): T; /** Increments the number stored at `key` by `amount`. If `key` does not exist, it is set to 0 before performing the operation. * @see {@link https://valkey.io/commands/incrby/|valkey.io} for details. * * @param key - The key to increment its value. * @param amount - The amount to increment. * * Command Response - the value of `key` after the increment. */ incrBy(key: GlideString, amount: number): T; /** Increment the string representing a floating point number stored at `key` by `amount`. * By using a negative amount value, the result is that the value stored at `key` is decremented. * If `key` does not exist, it is set to 0 before performing the operation. * @see {@link https://valkey.io/commands/incrbyfloat/|valkey.io} for details. * * @param key - The key to increment its value. * @param amount - The amount to increment. * * Command Response - the value of `key` after the increment. * */ incrByFloat(key: GlideString, amount: number): T; /** * Returns the current connection ID. * * @see {@link https://valkey.io/commands/client-id/|valkey.io} for details. * * Command Response - The ID of the connection. */ clientId(): T; /** Decrements the number stored at `key` by one. If `key` does not exist, it is set to 0 before performing the operation. * @see {@link https://valkey.io/commands/decr/|valkey.io} for details. * * @param key - The key to decrement its value. * * Command Response - the value of `key` after the decrement. */ decr(key: GlideString): T; /** Decrements the number stored at `key` by `amount`. If `key` does not exist, it is set to 0 before performing the operation. * @see {@link https://valkey.io/commands/decrby/|valkey.io} for details. * * @param key - The key to decrement its value. * @param amount - The amount to decrement. * * Command Response - the value of `key` after the decrement. */ decrBy(key: GlideString, amount: number): T; /** * Perform a bitwise operation between multiple keys (containing string values) and store the result in the * `destination`. * * @see {@link https://valkey.io/commands/bitop/|valkey.io} for details. * * @param operation - The bitwise operation to perform. * @param destination - The key that will store the resulting string. * @param keys - The list of keys to perform the bitwise operation on. * * Command Response - The size of the string stored in `destination`. */ bitop(operation: BitwiseOperation, destination: GlideString, keys: GlideString[]): T; /** * Returns the bit value at `offset` in the string value stored at `key`. `offset` must be greater than or equal * to zero. * * @see {@link https://valkey.io/commands/getbit/|valkey.io} for details. * * @param key - The key of the string. * @param offset - The index of the bit to return. * * Command Response - The bit at the given `offset` of the string. Returns `0` if the key is empty or if the * `offset` exceeds the length of the string. */ getbit(key: GlideString, offset: number): T; /** * Sets or clears the bit at `offset` in the string value stored at `key`. The `offset` is a zero-based index, with * `0` being the first element of the list, `1` being the next element, and so on. The `offset` must be less than * `2^32` and greater than or equal to `0`. If a key is non-existent then the bit at `offset` is set to `value` and * the preceding bits are set to `0`. * * @see {@link https://valkey.io/commands/setbit/|valkey.io} for details. * * @param key - The key of the string. * @param offset - The index of the bit to be set. * @param value - The bit value to set at `offset`. The value must be `0` or `1`. * * Command Response - The bit value that was previously stored at `offset`. */ setbit(key: GlideString, offset: number, value: number): T; /** * Returns the position of the first bit matching the given `bit` value. The optional starting offset * `start` is a zero-based index, with `0` being the first byte of the list, `1` being the next byte and so on. * The offset can also be a negative number indicating an offset starting at the end of the list, with `-1` being * the last byte of the list, `-2` being the penultimate, and so on. * * @see {@link https://valkey.io/commands/bitpos/|valkey.io} for details. * * @param key - The key of the string. * @param bit - The bit value to match. Must be `0` or `1`. * @param options - (Optional) The {@link BitOffsetOptions}. * * Command Response - The position of the first occurrence of `bit` in the binary value of the string held at `key`. * If `start` was provided, the search begins at the offset indicated by `start`. */ bitpos(key: GlideString, bit: number, options?: BitOffsetOptions): T; /** * Reads or modifies the array of bits representing the string that is held at `key` based on the specified * `subcommands`. * * @see {@link https://valkey.io/commands/bitfield/|valkey.io} for details. * * @param key - The key of the string. * @param subcommands - The subcommands to be performed on the binary value of the string at `key`, which could be * any of the following: * * - {@link BitFieldGet} * - {@link BitFieldSet} * - {@link BitFieldIncrBy} * - {@link BitFieldOverflow} * * Command Response - An array of results from the executed subcommands: * * - {@link BitFieldGet} returns the value in {@link BitOffset} or {@link BitOffsetMultiplier}. * - {@link BitFieldSet} returns the old value in {@link BitOffset} or {@link BitOffsetMultiplier}. * - {@link BitFieldIncrBy} returns the new value in {@link BitOffset} or {@link BitOffsetMultiplier}. * - {@link BitFieldOverflow} determines the behavior of the {@link BitFieldSet} and {@link BitFieldIncrBy} * subcommands when an overflow or underflow occurs. {@link BitFieldOverflow} does not return a value and * does not contribute a value to the array response. */ bitfield(key: GlideString, subcommands: BitFieldSubCommands[]): T; /** * Reads the array of bits representing the string that is held at `key` based on the specified `subcommands`. * * @see {@link https://valkey.io/commands/bitfield_ro/|valkey.io} for details. * @remarks Since Valkey version 6.0.0. * * @param key - The key of the string. * @param subcommands - The {@link BitFieldGet} subcommands to be performed. * * Command Response - An array of results from the {@link BitFieldGet} subcommands. * */ bitfieldReadOnly(key: GlideString, subcommands: BitFieldGet[]): T; /** * Reads the configuration parameters of the running server. * Starting from server version 7, command supports multiple parameters. * * @see {@link https://valkey.io/commands/config-get/|valkey.io} for details. * * @param parameters - A list of configuration parameter names to retrieve values for. * * Command Response - A map of values corresponding to the configuration parameters. * */ configGet(parameters: string[]): T; /** * Sets configuration parameters to the specified values. * Starting from server version 7, command supports multiple parameters. * * @see {@link https://valkey.io/commands/config-set/|valkey.io} for details. * * @param parameters - A map consisting of configuration parameters and their respective values to set. * * Command Response - "OK" when the configuration was set properly. Otherwise, the transaction fails with an error. */ configSet(parameters: Record<string, GlideString>): T; /** Retrieve the value associated with `field` in the hash stored at `key`. * @see {@link https://valkey.io/commands/hget/|valkey.io} for details. * * @param key - The key of the hash. * @param field - The field in the hash stored at `key` to retrieve from the database. * * Command Response - the value associated with `field`, or null when `field` is not present in the hash or `key` does not exist. */ hget(key: GlideString, field: GlideString): T; /** Sets the specified fields to their respective values in the hash stored at `key`. * @see {@link https://valkey.io/commands/hset/|valkey.io} for details. * * @param key - The key of the hash. * @param fieldValueList - A list of field names and their values. * to be set in the hash stored at the specified key. * * Command Response - The number of fields that were added. */ hset(key: GlideString, fieldsAndValues: HashDataType | Record<string, GlideString>): T; /** * Returns all field names in the hash stored at `key`. * * @see {@link https://valkey.io/commands/hkeys/|valkey.io} for details. * * @param key - The key of the hash. * * Command Response - A list of field names for the hash, or an empty list when the key does not exist. */ hkeys(key: GlideString): T; /** Sets `field` in the hash stored at `key` to `value`, only if `field` does not yet exist. * If `key` does not exist, a new key holding a hash is created. * If `field` already exists, this operation has no effect. * @see {@link https://valkey.io/commands/hsetnx/|valkey.io} for details. * * @param key - The key of the hash. * @param field - The field to set the value for. * @param value - The value to set. * * Command Response - `true` if the field was set, `false` if the field already existed and was not set. */ hsetnx(key: GlideString, field: GlideString, value: GlideString): T; /** Removes the specified fields from the hash stored at `key`. * Specified fields that do not exist within this hash are ignored. * @see {@link https://valkey.io/commands/hdel/|valkey.io} for details. * * @param key - The key of the hash. * @param fields - The fields to remove from the hash stored at `key`. * * Command Response - the number of fields that were removed from the hash, not including specified but non existing fields. * If `key` does not exist, it is treated as an empty hash and it returns 0. */ hdel(key: GlideString, fields: GlideString[]): T; /** Returns the values associated with the specified fields in the hash stored at `key`. * @see {@link https://valkey.io/commands/hmget/|valkey.io} for details. * * @param key - The key of the hash. * @param fields - The fields in the hash stored at `key` to retrieve from the database. * * Command Response - a list of values associated with the given fields, in the same order as they are requested. * For every field that does not exist in the hash, a null value is returned. * If `key` does not exist, it is treated as an empty hash and it returns a list of null values. */ hmget(key: GlideString, fields: GlideString[]): T; /** Returns if `field` is an existing field in the hash stored at `key`. * @see {@link https://valkey.io/commands/hexists/|valkey.io} for details. * * @param key - The key of the hash. * @param field - The field to check in the hash stored at `key`. * * Command Response - `true` if the hash contains `field`. If the hash does not contain `field`, or if `key` does not exist, * the command response will be `false`. */ hexists(key: GlideString, field: GlideString): T; /** * Returns all fields and values of the hash stored at `key`. * * @see {@link https://valkey.io/commands/hgetall/|valkey.io} for details. * * @param key - The key of the hash. * * Command Response - A list of fields and their values stored in the hash. * If `key` does not exist, it returns an empty list. */ hgetall(key: GlideString): T; /** Increments the number stored at `field` in the hash stored at `key` by `increment`. * By using a negative increment value, the value stored at `field` in the hash stored at `key` is decremented. * If `field` or `key` does not exist, it is set to 0 before performing the operation. * @see {@link https://valkey.io/commands/hincrby/|valkey.io} for details. * * @param key - The key of the hash. * @param amount - The amount to increment. * @param field - The field in the hash stored at `key` to increment its value. * * Command Response - the value of `field` in the hash stored at `key` after the increment. */ hincrBy(key: GlideString, field: GlideString, amount: number): T; /** Increment the string representing a floating point number stored at `field` in the hash stored at `key` by `increment`. * By using a negative increment value, the value stored at `field` in the hash stored at `key` is decremented. * If `field` or `key` does not exist, it is set to 0 before performing the operation. * @see {@link https://valkey.io/commands/hincrbyfloat/|valkey.io} for details. * * @param key - The key of the hash. * @param amount - The amount to increment. * @param field - The field in the hash stored at `key` to increment its value. * * Command Response - the value of `field` in the hash stored at `key` after the increment. */ hincrByFloat(key: GlideString, field: GlideString, amount: number): T; /** Returns the number of fields contained in the hash stored at `key`. * @see {@link https://valkey.io/commands/hlen/|valkey.io} for details. * * @param key - The key of the hash. * * Command Response - The number of fields in the hash, or 0 when the key does not exist. */ hlen(key: GlideString): T; /** Returns all values in the hash stored at key. * @see {@link https://valkey.io/commands/hvals/|valkey.io} for details. * * @param key - The key of the hash. * * Command Response - a list of values in the hash, or an empty list when the key does not exist. */ hvals(key: GlideString): T; /** * Returns the string length of the value associated with `field` in the hash stored at `key`. * * @see {@link https://valkey.io/commands/hstrlen/|valkey.io} for details. * * @param key - The key of the hash. * @param field - The field in the hash. * * Command Response - The string length or `0` if `field` or `key` does not exist. */ hstrlen(key: GlideString, field: GlideString): T; /** * Returns a random field name from the hash value stored at `key`. * * @see {@link https://valkey.io/commands/hrandfield/|valkey.io} for details. * @remarks Since Valkey version 6.2.0. * * @param key - The key of the hash. * * Command Response - A random field name from the hash stored at `key`, or `null` when * the key does not exist. */ hrandfield(key: GlideString): T; /** * Iterates incrementally over a hash. * * @see {@link https://valkey.io/commands/hscan/|valkey.io} for more details. * * @param key - The key of the set. * @param cursor - The cursor that points to the next iteration of results. A value of `"0"` indicates the start of the search. * @param options - (Optional) The {@link HScanOptions}. * * Command Response - An array of the `cursor` and the subset of the hash held by `key`. * The first element is always the `cursor` for the next iteration of results. `"0"` will be the `cursor` * returned on the last iteration of the hash. The second element is always an array of the subset of the * hash held in `key`. The array in the second element is a flattened series of string pairs, * where the value is at even indices and the value is at odd indices. * If `options.noValues` is set to `true`, the second element will only contain the fields without the values. */ hscan(key: GlideString, cursor: string, options?: HScanOptions): T; /** * Retrieves up to `count` random field names from the hash value stored at `key`. * * @see {@link https://valkey.io/commands/hrandfield/|valkey.io} for details. * @remarks Since Valkey version 6.2.0. * * @param key - The key of the hash. * @param count - The number of field names to return. * * If `count` is positive, returns unique elements. If negative, allows for duplicates. * * Command Response - An `array` of random field names from the hash stored at `key`, * or an `empty array` when the key does not exist. */ hrandfieldCount(key: GlideString, count: number): T; /** * Retrieves up to `count` random field names along with their values from the hash * value stored at `key`. * * @see {@link https://valkey.io/commands/hrandfield/|valkey.io} for details. * @remarks Since Valkey version 6.2.0. * * @param key - The key of the hash. * @param count - The number of field names to return. * * If `count` is positive, returns unique elements. If negative, allows for duplicates. * * Command Response - A 2D `array` of `[fieldName, value]` `arrays`, where `fieldName` is a random * field name from the hash and `value` is the associated value of the field name. * If the hash does not exist or is empty, the response will be an empty `array`. */ hrandfieldWithValues(key: GlideString, count: number): T; /** Inserts all the specified values at the head of the list stored at `key`. * `elements` are inserted one after the other to the head of the list, from the leftmost element to the rightmost element. * If `key` does not exist, it is created as empty list before performing the push operations. * @see {@link https://valkey.io/commands/lpush/|valkey.io} for details. * * @param key - The key of the list. * @param elements - The elements to insert at the head of the list stored at `key`. * * Command Response - the length of the list after the push operations. */ lpush(key: GlideString, elements: GlideString[]): T; /** * Inserts specified values at the head of the `list`, only if `key` already * exists and holds a list. * * @see {@link https://valkey.io/commands/lpushx/|valkey.io} for details. * * @param key - The key of the list. * @param elements - The elements to insert at the head of the list stored at `key`. * * Command Response - The length of the list after the push operation. */ lpushx(key: GlideString, elements: GlideString[]): T; /** Removes and returns the first elements of the list stored at `key`. * The command pops a single element from the beginning of the list. * @see {@link https://valkey.io/commands/lpop/|valkey.io} for details. * * @param key - The key of the list. * * Command Response - The value of the first element. * If `key` does not exist null will be returned. */ lpop(key: GlideString): T; /** Removes and returns up to `count` elements of the list stored at `key`, depending on the list's length. * @see {@link https://valkey.io/commands/lpop/|valkey.io} for details. * * @param key - The key of the list. * @param count - The count of the elements to pop from the list. * * Command Response - A list of the popped elements will be returned depending on the list's length. * If `key` does not exist null will be returned. */ lpopCount(key: GlideString, count: number): T; /** Returns the specified elements of the list stored at `key`. * The offsets `start` and `end` are zero-based indexes, with 0 being the first element of the list, 1 being the next element and so on. * These offsets can also be negative numbers indicating offsets starting at the end of the list, * with -1 being the last element of the list, -2 being the penultimate, and so on. * @see {@link https://valkey.io/commands/lrange/|valkey.io} for details. * * @param key - The key of the list. * @param start - The starting point of the range. * @param end - The end of the range. * * Command Response - list of elements in the specified range. * If `start` exceeds the end of the list, or if `start` is greater than `end`, an empty list will be returned. * If `end` exceeds the actual end of the list, the range will stop at the actual end of the list. * If `key` does not exist an empty list will be returned. */ lrange(key: GlideString, start: number, end: number): T; /** Returns the length of the list stored at `key`. * @see {@link https://valkey.io/commands/llen/|valkey.io} for details. * * @param key - The key of the list. * * Command Response - the length of the list at `key`. * If `key` does not exist, it is interpreted as an empty list and 0 is returned. */ llen(key: GlideString): T; /** * Atomically pops and removes the left/right-most element to the list stored at `source` * depending on `whereFrom`, and pushes the element at the first/last element of the list * stored at `destination` depending on `whereTo`, see {@link ListDirection}. * * @see {@link https://valkey.io/commands/lmove/|valkey.io} for details. * @remarks Since Valkey version 6.2.0. * * @param source - The key to the source list. * @param destination - The key to the destination list. * @param whereFrom - The {@link ListDirection} to remove the element from. * @param whereTo - The {@link ListDirection} to add the element to. * * Command Response - The popped element, or `null` if `source` does not exist. */ lmove(source: GlideString, destination: GlideString, whereFrom: ListDirection, whereTo: ListDirection): T; /** * * Blocks the connection until it pops atomically and removes the left/right-most element to the * list stored at `source` depending on `whereFrom`, and pushes the element at the first/last element * of the list stored at `destination` depending on `whereTo`. * `BLMOVE` is the blocking variant of {@link lmove}. * * @see {@link https://valkey.io/commands/blmove/|valkey.io} for details. * @remarks When in cluster mode, both `source` and `destination` must map to the same hash slot. * @remarks `BLMOVE` is a client blocking command, see {@link https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#blocking-commands|Valkey Glide Wiki} for more details and best practices. * @remarks Since Valkey version 6.2.0. * * @param source - The key to the source list. * @param destination - The key to the destination list. * @param whereFrom - The {@link ListDirection} to remove the element from. * @param whereTo - The {@link ListDirection} to add the element to. * @param timeout - The number of seconds to wait for a blocking operation to complete. A value of `0` will block indefinitely. * * Command Response - The popped element, or `null` if `source` does not exist or if the operation timed-out. */ blmove(source: GlideString, destination: GlideString, whereFrom: ListDirection, whereTo: ListDirection, timeout: number): T; /** * Sets the list element at `index` to `element`. * The index is zero-based, so `0` means the first element, `1` the second element and so on. * Negative indices can be used to designate elements starting at the tail of * the list. Here, `-1` means the last element, `-2` means the penultimate and so forth. * * @see {@link https://valkey.io/commands/lset/|valkey.io} for details. * * @param key - The key of the list. * @param index - The index of the element in the list to be set. * @param element - The new element to set at the specified index. * * Command Response - Always "OK". */ lset(key: GlideString, index: number, element: GlideString): T; /** Trim an existing list so that it will contain only the specified range of elements specified. * The offsets `start` and `end` are zero-based indexes, with 0 being the first element of the list, 1 being the next element and so on. * These offsets can also be negative numbers indicating offsets starting at the end of the list, * with -1 being the last element of the list, -2 being the penultimate, and so on. * @see {@link https://valkey.io/commands/ltrim/|valkey.io} for details. * * @param key - The key of the list. * @param start - The starting point of the range. * @param end - The end of the range. * * Command Response - always "OK". * If `start` exceeds the end of the list, or if `start` is greater than `end`, the result will be an empty list (which causes key to be removed). * If `end` exceeds the actual end of the list, it will be treated like the last element of the list. * If `key` does not exist the command will be ignored. */ ltrim(key: GlideString, start: number, end: number): T; /** Removes the first `count` occurrences of elements equal to `element` from the list stored at `key`. * If `count` is positive : Removes elements equal to `element` moving from head to tail. * If `count` is negative : Removes elements equal to `element` moving from tail to head. * If `count` is 0 or `count` is greater than the occurrences of elements equal to `element`: Removes all elements equal to `element`. * * @param key - The key of the list. * @param count - The count of the occurrences of elements equal to `element` to remove. * @param element - The element to remove from the list. * * Command Response - the number of the removed elements. * If `key` does not exist, 0 is returned. */ lrem(key: GlideString, count: number, element: GlideString): T; /** Inserts all the specified values at the tail of the list stored at `key`. * `elements` are inserted one after the other to the tail of the list, from the leftmost element to the rightmost element. * If `key` does not exist, it is created as empty list before performing the push operations. * @see {@link https://valkey.io/commands/rpush/|valkey.io} for details. * * @param key - The key of the list. * @param elements - The elements to insert at the tail of the list stored at `key`. * * Command Response - the length of the list after the push operations. */ rpush(key: GlideString, elements: GlideString[]): T; /** * Inserts specified values at the tail of the `list`, only if `key` already * exists and holds a list. * * @see {@link https://valkey.io/commands/rpushx/|valkey.io} for details. * * @param key - The key of the list. * @param elements - The elements to insert at the tail of the list stored at `key`. * * Command Response - The length of the list after the push operation. */ rpushx(key: GlideString, elements: GlideString[]): T; /** Removes and returns the last elements of the list stored at `key`. * The command pops a single element from the end of the list. * @see {@link https://valkey.io/commands/rpop/|valkey.io} for details. * * @param key - The key of the list. * * Command Response - The value of the last element. * If `key` does not exist null will be returned. */ rpop(key: GlideString): T; /** Removes and returns up to `count` elements from the list stored at `key`, depending on the list's length. * @see {@link https://valkey.io/commands/rpop/|valkey.io} for details. * * @param key - The key of the list. * @param count - The count of the elements to pop from the list. * * Command Response - A list of popped elements will be returned depending on the list's length. * If `key` does not exist null will be returned. */ rpopCount(key: GlideString, count: number): T; /** Adds the specified members to the set stored at `key`. Specified members that are already a member of this set are ignored. * If `key` does not exist, a new set is created before adding `members`. * @see {@link https://valkey.io/commands/sadd/|valkey.io} for details. * * @param key - The key to store the members to its set. * @param members - A list of members to add to the set stored at `key`. * * Command Response - the number of members that were added to the set, not including all the members already present in the set. */ sadd(key: GlideString, members: GlideString[]): T; /** Removes the specified members from the set stored at `key`. Specified members that are not a member of this set are ignored. * @see {@link https://valkey.io/commands/srem/|valkey.io} for details. * * @param key - The key to remove the members from its set. * @param members - A list of members to remove from the set stored at `key`. * * Command Response - the number of members that were removed from the set, not including non existing members. * If `key` does not exist, it is treated as an empty set and this command returns 0. */ srem(key: GlideString, members: GlideString[]): T; /** * Iterates incrementally over a set. * * @see {@link https://valkey.io/commands/sscan} for details. * * @param key - The key of the set. * @param cursor - The cursor that points to the next iteration of results. A value of `"0"` indicates the start of the search. * @param options - The (Optional) {@link BaseScanOptions}. * * Command Response - An array of the cursor and the subset of the set held by `key`. The first element is always the `cursor` and for the next iteration of results. * The `cursor` will be `"0"` on the last iteration of the set. The second element is always an array of the subset of the set held in `key`. */ sscan(key: GlideString, cursor: GlideString, options?: BaseScanOptions): T; /** Returns all the members of the set value stored at `key`. * @see {@link https://valkey.io/commands/smembers/|valkey.io} for details. * * @param key - The key to return its members. * * Command Response - all members of the set. * If `key` does not exist, it is treated as an empty set and this command returns empty list. */ smembers(key: GlideString): T; /** Moves `member` from the set at `source` to the set at `destination`, removing it from the source set. * Creates a new destination set if needed. The operation is atomic. * @see {@link https://valkey.io/commands/smove/|valkey.io} for more details. * * @param source - The key of the set to remove the element from. * @param destination - The key of the set to add the element to. * @param member - The set element to move. * * Command Response - `true` on success, or `false` if the `source` set does not exist or the element is not a member of the source set. */ smove(source: GlideString, destination: GlideString, member: GlideString): T; /** Returns the set cardinality (number of elements) of the set stored at `key`. * @see {@link https://valkey.io/commands/scard/|valkey.io} for details. * * @param key - The key to return the number of its members. * * Command Response - the cardinality (number of elements) of the set, or 0 if key does not exist. */ scard(key: GlideString): T; /** Gets the intersection of all the given sets. * When in cluster mode, all `keys` must map to the same hash slot. * @see {@link https://valkey.io/commands/sinter/|valkey.io} for details. * * @param keys - The `keys` of the sets to get the intersection. * * Command Response - A set of members which are present in all given sets. * If one or more sets do not exist, an empty set will be returned. */ sinter(keys: GlideString[]): T; /** * Gets the cardinality of the intersection of all the given sets. * * @see {@link https://valkey.io/commands/sintercard/|valkey.io} for details. * @remarks Since Valkey version 7.0.0. * * @param keys - The keys of the sets. * @param options - (Optional) Additional parameters: * - (Optional) `limit`: the limit for the intersection cardinality value. If not specified, or set to `0`, no limit is used. * * Command Response - The cardinality of the intersection result. If one or more sets do not exist, `0` is returned. */ sintercard(keys: GlideString[], options?: { limit?: number; }): T; /** * Stores the members of the intersection of all given sets specified by `keys` into a new set at `destination`. * * @see {@link https://valkey.io/commands/sinterstore/|valkey.io} for details. * * @param destination - The key of the destination set. * @param keys - The keys from which to retrieve the set members. * * Command Response - The number of elements in the resulting set. */ sinterstore(destination: GlideString, keys: GlideString[]): T; /** * Computes the difference between the first set and all the successive sets in `keys`. * * @see {@link https://valkey.io/commands/sdiff/|valkey.io} for details. * * @param keys - The keys of the sets to diff. * * Command Response - A `Set` of elements representing the difference between the sets. * If a key in `keys` does not exist, it is treated as an empty set. */ sdiff(keys: GlideString[]): T; /** * Stores the difference between the first set and all the successive sets in `keys` into a new set at `destination`. * * @see {@link https://valkey.io/commands/sdiffstore/|valkey.io} for details. * * @param destination - The key of the destination set. * @param keys - The keys of the sets to diff. * * Command Response - The number of elements in the resulting set. */ sdiffstore(destination: GlideString, keys: GlideString[]): T; /** * Gets the union of all the given sets. * * @see {@link https://valkey.io/commands/sunion/|valkey.io} for details. * * @param keys - The keys of the sets. * * Command Response - A `Set` of members which are present in at least one of the given sets. * If none of the sets exist, an empty `Set` will be returned. */ sunion(keys: GlideString[]): T; /** * Stores the members of the union of all given sets specified by `keys` into a new set * at `destination`. * * @see {@link https://valkey.io/commands/sunionstore/|valkey.io} for details. * * @param destination - The key of the destination set. * @param keys - The keys from which to retrieve the set members. * * Command Response - The number of elements in the resulting set. */ sunionstore(destination: GlideString, keys: GlideString[]): T; /** Returns if `member` is a member of the set stored at `key`. * @see {@link https://valkey.io/commands/sismember/|valkey.io} for details. * * @param key - The key of the set. * @param member - The member to check for existence in the set. * * Command Response - `true` if the member exists in the set, `false` otherwise. * If `key` doesn't exist, it is treated as an empty set and the command returns `false`. */ sismember(key: GlideString, member: GlideString): T; /** * Checks whether each member is contained in the members of the set stored at `key`. * * @see {@link https://valkey.io/commands/smismember/|valkey.io} for details. * @remarks Since Valkey version 6.2.0. * * @param key - The key of the set to check. * @param members - A list of members to check for existence in the set. * * Command Response - An `array` of `boolean` values, each indicating if the respective member exists in the set. */ smismember(key: GlideString, members: GlideString[]): T; /** Removes and returns one random member from the set value store at `key`. * @see {@link https://valkey.io/commands/spop/|valkey.io} for details. * To pop multiple members, see `spopCount`. * * @param key - The key of the set. * * Command Response - the value of the popped member. * If `key` does not exist, null will be returned. */ spop(key: GlideString): T; /** Removes and returns up to `count` random members from the set value store at `key`, depending on the set's length. * @see {@link https://valkey.io/commands/spop/|valkey.io} for details. * * @param key - The key of the set. * @param count - The count of the elements to pop from the set. * * Command Response - A list of popped elements will be returned depending on the set's length. * If `key` does not exist, empty list will be returned. */ spopCount(key: GlideString, count: number): T; /** Returns a random element from the set value stored at `key`. * * @see {@link https://valkey.io/commands/srandmember/|valkey.io} for more details. * * @param key - The key from which to retrieve the set member. * Command Response - A random element from the set, or null if `key` does not exist. */ srandmember(key: GlideString): T; /** Returns one or more random elements from the set value stored at `key`. * * @see {@link https://valkey.io/commands/srandmember/|valkey.io} for more details. * * @param key - The key of the sorted set. * @param count - The number of members to return. * If `count` is positive, returns unique members. * If `count` is negative, allows for duplicates members. * Command Response - A list of members from the set. If the set does not exist or is empty, an empty list will be returned. */ srandmemberCount(key: GlideString, count: number): T; /** * Returns the number of keys in `keys` that