From f7322cb42a90c08ea2e9475167fe719ea9e1bdc1 Mon Sep 17 00:00:00 2001 From: Shoham Elias Date: Wed, 3 Apr 2024 13:11:42 +0000 Subject: [PATCH 01/26] Add missing examples for Python and Node --- node/src/BaseClient.ts | 651 +++++++++++++++++- node/src/RedisClient.ts | 69 +- node/src/RedisClusterClient.ts | 84 ++- .../glide/async_commands/cluster_commands.py | 6 +- python/python/glide/async_commands/core.py | 76 +- 5 files changed, 851 insertions(+), 35 deletions(-) diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index c5b0201d9d..58f91c3364 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -417,6 +417,13 @@ export class BaseClient { * * @param key - The key to retrieve from the database. * @returns If `key` exists, returns the value of `key` as a string. Otherwise, return null. + * + * @example + * ```typescript + * // Example usage of get method to retrieve the value of a key + * const result = await client.get("key"); + * console.log(result); // Output: 'value' + * ``` */ public get(key: string): Promise { return this.createWritePromise(createGet(key)); @@ -431,6 +438,13 @@ export class BaseClient { * @returns - 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. + * + * @example + * ```typescript + * // Example usage of set method to set a key-value pair + * const result = await client.set("my_key", "my_value"); + * console.log(result); // Output: 'OK' + * ``` */ public set( key: string, @@ -445,6 +459,21 @@ export class BaseClient { * * @param keys - the keys we wanted to remove. * @returns the number of keys that were removed. + * + * @example + * ```typescript + * // Example usage of del method to delete an existing key + * await client.set("my_key", "my_value"); + * const result = await client.del("my_key"); + * console.log(result); // Output: 1 + * ``` + * + * @example + * ```typescript + * // Example usage of del method for a non-existing key + * const result = await client.del("non_existing_key"); + * console.log(result); // Output: 0 + * ``` */ public del(keys: string[]): Promise { return this.createWritePromise(createDel(keys)); @@ -456,6 +485,15 @@ export class BaseClient { * @param keys - A list of keys to retrieve values for. * @returns A list of values corresponding to the provided keys. If a key is not found, * its corresponding value in the list will be null. + * + * @example + * ```typescript + * // Example usage of mget method to retrieve values of multiple keys + * await client.set("key1", "value1"); + * await client.set("key2", "value2"); + * const result = await client.mget(["key1", "key2"]); + * console.log(result); // Output: ['value1', 'value2'] + * ``` */ public mget(keys: string[]): Promise<(string | null)[]> { return this.createWritePromise(createMGet(keys)); @@ -466,6 +504,13 @@ export class BaseClient { * * @param keyValueMap - A key-value map consisting of keys and their respective values to set. * @returns always "OK". + * + * @example + * ```typescript + * // Example usage of mset method to set values for multiple keys + * const result = await client.mset(\{"key1": "value1", "key2": "value2"\}); + * console.log(result); // Output: 'OK' + * ``` */ public mset(keyValueMap: Record): Promise<"OK"> { return this.createWritePromise(createMSet(keyValueMap)); @@ -476,6 +521,14 @@ export class BaseClient { * * @param key - The key to increment its value. * @returns the value of `key` after the increment. + * + * @example + * ```typescript + * // Example usage of incr method to increment the value of a key + * await client.set("my_counter", "10"); + * const result = await client.incr("my_counter"); + * console.log(result); // Output: 11 + * ``` */ public incr(key: string): Promise { return this.createWritePromise(createIncr(key)); @@ -487,6 +540,14 @@ export class BaseClient { * @param key - The key to increment its value. * @param amount - The amount to increment. * @returns the value of `key` after the increment. + * + * @example + * ```typescript + * // Example usage of incrBy method to increment the value of a key by a specified amount + * await client.set("my_counter", "10"); + * const result = await client.incrBy("my_counter", 5); + * console.log(result); // Output: 15 + * ``` */ public incrBy(key: string, amount: number): Promise { return this.createWritePromise(createIncrBy(key, amount)); @@ -501,6 +562,13 @@ export class BaseClient { * @param amount - The amount to increment. * @returns the value of `key` after the increment. * + * @example + * ```typescript + * // Example usage of incrByFloat method to increment the value of a floating point key by a specified amount + * await client.set("my_float_counter", "10.5"); + * const result = await client.incrByFloat("my_float_counter", 2.5); + * console.log(result); // Output: 13.0 + * ``` */ public incrByFloat(key: string, amount: number): Promise { return this.createWritePromise(createIncrByFloat(key, amount)); @@ -511,6 +579,14 @@ export class BaseClient { * * @param key - The key to decrement its value. * @returns the value of `key` after the decrement. + * + * @example + * ```typescript + * // Example usage of decr method to decrement the value of a key by 1 + * await client.set("my_counter", "10"); + * const result = await client.decr("my_counter"); + * console.log(result); // Output: 9 + * ``` */ public decr(key: string): Promise { return this.createWritePromise(createDecr(key)); @@ -522,6 +598,14 @@ export class BaseClient { * @param key - The key to decrement its value. * @param amount - The amount to decrement. * @returns the value of `key` after the decrement. + * + * @example + * ```typescript + * // Example usage of decrby method to decrement the value of a key by a specified amount + * await client.set("my_counter", "10"); + * const result = await client.decrby("my_counter", 5); + * console.log(result); // Output: 5 + * ``` */ public decrBy(key: string, amount: number): Promise { return this.createWritePromise(createDecrBy(key, amount)); @@ -533,6 +617,20 @@ export class BaseClient { * @param key - The key of the hash. * @param field - The field in the hash stored at `key` to retrieve from the database. * @returns the value associated with `field`, or null when `field` is not present in the hash or `key` does not exist. + * + * @example + * ```typescript + * // Example usage of the hget method + * const result = await client.hget("my_hash", "field"); + * console.log(result); // Output: "value" + * ``` + * + * @example + * ```typescript + * // Example usage of the hget method + * const result = await client.hget("my_hash", "nonexistent_field"); + * console.log(result); // Output: null + * ``` */ public hget(key: string, field: string): Promise { return this.createWritePromise(createHGet(key, field)); @@ -545,6 +643,13 @@ export class BaseClient { * @param fieldValueMap - A field-value map consisting of fields and their corresponding values * to be set in the hash stored at the specified key. * @returns The number of fields that were added. + * + * @example + * ```typescript + * // Example usage of the hset method + * const result = await client.hset("my_hash", \{"field": "value", "field2": "value2"\}); + * console.log(result); // Output: 2 - Indicates that 2 fields were successfully set in the hash "my_hash". + * ``` */ public hset( key: string, @@ -562,6 +667,20 @@ export class BaseClient { * @param field - The field to set the value for. * @param value - The value to set. * @returns `true` if the field was set, `false` if the field already existed and was not set. + * + * @example + * ```typescript + * // Example usage of the hsetnx method + * const result = await client.hsetnx("my_hash", "field", "value"); + * console.log(result); // Output: true - Indicates that the field "field" was set successfully in the hash "my_hash". + * ``` + * + * @example + * ```typescript + * // Example usage of the hsetnx method + * const result = await client.hsetnx("my_hash", "field", "new_value"); + * console.log(result); // Output: false - Indicates that the field "field" already existed in the hash "my_hash" and was not set again. + * ``` */ public hsetnx(key: string, field: string, value: string): Promise { return this.createWritePromise(createHSetNX(key, field, value)); @@ -575,6 +694,13 @@ export class BaseClient { * @param fields - The fields to remove from the hash stored at `key`. * @returns 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. + * + * @example + * ```typescript + * // Example usage of the hdel method + * const result = await client.hdel("my_hash", ["field1", "field2"]); + * console.log(result); // Output: 2 - Indicates that two fields were successfully removed from the hash. + * ``` */ public hdel(key: string, fields: string[]): Promise { return this.createWritePromise(createHDel(key, fields)); @@ -588,6 +714,13 @@ export class BaseClient { * @returns 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. + * + * @example + * ```typescript + * // Example usage of the hmget method + * const result = await client.hmget("my_hash", ["field1", "field2"]); + * console.log(result); // Output: ["value1", "value2"] - A list of values associated with the specified fields. + * ``` */ public hmget(key: string, fields: string[]): Promise<(string | null)[]> { return this.createWritePromise(createHMGet(key, fields)); @@ -599,6 +732,20 @@ export class BaseClient { * @param key - The key of the hash. * @param field - The field to check in the hash stored at `key`. * @returns `true` the hash contains `field`. If the hash does not contain `field`, or if `key` does not exist, it returns `false`. + * + * @example + * ```typescript + * // Example usage of the hexists method with existing field + * const result = await client.hexists("my_hash", "field1"); + * console.log(result); // Output: true + * ``` + * + * @example + * ```typescript + * // Example usage of the hexists method with non existing field + * const result = await client.hexists("my_hash", "nonexistent_field"); + * console.log(result); // Output: false + * ``` */ public hexists(key: string, field: string): Promise { return this.createWritePromise(createHExists(key, field)); @@ -610,6 +757,13 @@ export class BaseClient { * @param key - The key of the hash. * @returns a list of fields and their values stored in the hash. Every field name in the list is followed by its value. * If `key` does not exist, it returns an empty list. + * + * @example + * ```typescript + * // Example usage of the hgetall method + * const result = await client.hgetall("my_hash"); + * console.log(result); // Output: \{"field1": "value1", "field2": "value2"\} + * ``` */ public hgetall(key: string): Promise> { return this.createWritePromise(createHGetAll(key)); @@ -624,6 +778,13 @@ export class BaseClient { * @param amount - The amount to increment. * @param field - The field in the hash stored at `key` to increment its value. * @returns the value of `field` in the hash stored at `key` after the increment. + * + * @example + * ```typescript + * // Example usage of the hincrby method + * const result = await client.hincrby("my_hash", "field1", 5); + * console.log(result); // Output: 5 + * ``` */ public hincrBy( key: string, @@ -642,6 +803,13 @@ export class BaseClient { * @param amount - The amount to increment. * @param field - The field in the hash stored at `key` to increment its value. * @returns the value of `field` in the hash stored at `key` after the increment. + * + * @example + * ```typescript + * // Example usage of the hincrbyfloat method + * const result = await client.hincrbyfloat("my_hash", "field1", 2.5); + * console.log(result); // Output: "2.5" + * ``` */ public hincrByFloat( key: string, @@ -656,6 +824,20 @@ export class BaseClient { * * @param key - The key of the hash. * @returns The number of fields in the hash, or 0 when the key does not exist. + * + * @example + * ```typescript + * // Example usage of the hlen method with an existing key + * const result = await client.hlen("my_hash"); + * console.log(result); // Output: 3 + * ``` + * + * @example + * ```typescript + * // Example usage of the hlen method with a non-existing key + * const result = await client.hlen("non_existing_key"); + * console.log(result); // Output: 0 + * ``` */ public hlen(key: string): Promise { return this.createWritePromise(createHLen(key)); @@ -666,6 +848,13 @@ export class BaseClient { * * @param key - The key of the hash. * @returns a list of values in the hash, or an empty list when the key does not exist. + * + * @example + * ```typescript + * // Example usage of the hvals method + * const result = await client.hvals("my_hash"); + * console.log(result); // Output: ["value1", "value2", "value3"] - Returns all the values stored in the hash "my_hash". + * ``` */ public hvals(key: string): Promise { return this.createWritePromise(createHvals(key)); @@ -679,6 +868,20 @@ export class BaseClient { * @param key - The key of the list. * @param elements - The elements to insert at the head of the list stored at `key`. * @returns the length of the list after the push operations. + * + * @example + * ```typescript + * // Example usage of the lpush method with an existing list + * const result = await client.lpush("my_list", ["value2", "value3"]); + * console.log(result); // Output: 3 - Indicated that the new length of the list is 3 after the push operation. + * ``` + * + * @example + * ```typescript + * // Example usage of the lpush method with a non-existing list + * const result = await client.lpush("nonexistent_list", ["new_value"]); + * console.log(result); // Output: 1 + * ``` */ public lpush(key: string, elements: string[]): Promise { return this.createWritePromise(createLPush(key, elements)); @@ -691,6 +894,20 @@ export class BaseClient { * @param key - The key of the list. * @returns The value of the first element. * If `key` does not exist null will be returned. + * + * @example + * ```typescript + * // Example usage of the lpop method with an existing list + * const result = await client.lpop("my_list"); + * console.log(result); // Output: "value1" + * ``` + * + * @example + * ```typescript + * // Example usage of the lpop method with a non-existing list + * const result = await client.lpop("non_exiting_key"); + * console.log(result); // Output: null + * ``` */ public lpop(key: string): Promise { return this.createWritePromise(createLPop(key)); @@ -703,6 +920,20 @@ export class BaseClient { * @param count - The count of the elements to pop from the list. * @returns A list of the popped elements will be returned depending on the list's length. * If `key` does not exist null will be returned. + * + * @example + * ```typescript + * // Example usage of the lpopCount method with an existing list + * const result = await client.lpopCount("my_list", 2); + * console.log(result); // Output: ["value1", "value2"] + * ``` + * + * @example + * ```typescript + * // Example usage of the lpopCount method with a non-existing list + * const result = await client.lpopCount("non_exiting_key", 3); + * console.log(result); // Output: null + * ``` */ public lpopCount(key: string, count: number): Promise { return this.createWritePromise(createLPop(key, count)); @@ -721,6 +952,27 @@ export class BaseClient { * 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. + * + * @example + * ```typescript + * // Example usage of the lrange method with an existing list and positive indices + * const result = await client.lrange("my_list", 0, 2); + * console.log(result); // Output: ["value1", "value2", "value3"] + * ``` + * + * @example + * ```typescript + * // Example usage of the lrange method with an existing list and negative indices + * const result = await client.lrange("my_list", -2, -1); + * console.log(result); // Output: ["value2", "value3"] + * ``` + * + * @example + * ```typescript + * // Example usage of the lrange method with a non-existing list + * const result = await client.lrange("non_exiting_key", 0, 2); + * console.log(result); // Output: [] + * ``` */ public lrange(key: string, start: number, end: number): Promise { return this.createWritePromise(createLRange(key, start, end)); @@ -732,6 +984,13 @@ export class BaseClient { * @param key - The key of the list. * @returns the length of the list at `key`. * If `key` does not exist, it is interpreted as an empty list and 0 is returned. + * + * @example + * ```typescript + * // Example usage of the llen method + * const result = await client.llen("my_list"); + * console.log(result); // Output: 3 - Indicates that there are 3 elements in the list. + * ``` */ public llen(key: string): Promise { return this.createWritePromise(createLLen(key)); @@ -750,6 +1009,13 @@ export class BaseClient { * 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. + * + * @example + * ```typescript + * // Example usage of the ltrim method + * const result = await client.ltrim("my_list", 0, 1); + * console.log(result); // Output: "OK" - Indicates that the list has been trimmed to contain elements from 0 to 1. + * ``` */ public ltrim(key: string, start: number, end: number): Promise<"OK"> { return this.createWritePromise(createLTrim(key, start, end)); @@ -765,6 +1031,13 @@ export class BaseClient { * @param element - The element to remove from the list. * @returns the number of the removed elements. * If `key` does not exist, 0 is returned. + * + * @example + * ```typescript + * // Example usage of the lrem method + * const result = await client.lrem("my_list", 2, "value"); + * console.log(result); // Output: 2 - Removes the first 2 occurrences of "value" in the list. + * ``` */ public lrem(key: string, count: number, element: string): Promise { return this.createWritePromise(createLRem(key, count, element)); @@ -778,6 +1051,20 @@ export class BaseClient { * @param key - The key of the list. * @param elements - The elements to insert at the tail of the list stored at `key`. * @returns the length of the list after the push operations. + * + * @example + * ```typescript + * // Example usage of the rpush method with an existing list + * const result = await client.rpush("my_list", ["value2", "value3"]); + * console.log(result); // Output: 3 - # Indicated that the new length of the list is 3 after the push operation. + * ``` + * + * @example + * ```typescript + * // Example usage of the rpush method with a non-existing list + * const result = await client.rpush("nonexistent_list", ["new_value"]); + * console.log(result); // Output: 1 + * ``` */ public rpush(key: string, elements: string[]): Promise { return this.createWritePromise(createRPush(key, elements)); @@ -790,6 +1077,20 @@ export class BaseClient { * @param key - The key of the list. * @returns The value of the last element. * If `key` does not exist null will be returned. + * + * @example + * ```typescript + * // Example usage of the rpop method with an existing list + * const result = await client.rpop("my_list"); + * console.log(result); // Output: "value1" + * ``` + * + * @example + * ```typescript + * // Example usage of the rpop method with a non-existing list + * const result = await client.rpop("non_exiting_key"); + * console.log(result); // Output: null + * ``` */ public rpop(key: string): Promise { return this.createWritePromise(createRPop(key)); @@ -802,6 +1103,20 @@ export class BaseClient { * @param count - The count of the elements to pop from the list. * @returns A list of popped elements will be returned depending on the list's length. * If `key` does not exist null will be returned. + * + * @example + * ```typescript + * // Example usage of the rpopCount method with an existing list + * const result = await client.rpopCount("my_list", 2); + * console.log(result); // Output: ["value1", "value2"] + * ``` + * + * @example + * ```typescript + * // Example usage of the rpopCount method with a non-existing list + * const result = await client.rpopCount("non_exiting_key", 7); + * console.log(result); // Output: null + * ``` */ public rpopCount(key: string, count: number): Promise { return this.createWritePromise(createRPop(key, count)); @@ -814,6 +1129,13 @@ export class BaseClient { * @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`. * @returns the number of members that were added to the set, not including all the members already present in the set. + * + * @example + * ```typescript + * // Example usage of the sadd method with an existing set + * const result = await client.sadd("my_set", ["member1", "member2"]); + * console.log(result); // Output: 2 + * ``` */ public sadd(key: string, members: string[]): Promise { return this.createWritePromise(createSAdd(key, members)); @@ -826,6 +1148,13 @@ export class BaseClient { * @param members - A list of members to remove from the set stored at `key`. * @returns 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. + * + * @example + * ```typescript + * // Example usage of the srem method + * const result = await client.srem("my_set", ["member1", "member2"]); + * console.log(result); // Output: 2 + * ``` */ public srem(key: string, members: string[]): Promise { return this.createWritePromise(createSRem(key, members)); @@ -837,6 +1166,13 @@ export class BaseClient { * @param key - The key to return its members. * @returns all members of the set. * If `key` does not exist, it is treated as an empty set and this command returns empty list. + * + * @example + * ```typescript + * // Example usage of the smembers method + * const result = await client.smembers("my_set"); + * console.log(result); // Output: ["member1", "member2", "member3"] + * ``` */ public smembers(key: string): Promise { return this.createWritePromise(createSMembers(key)); @@ -847,6 +1183,13 @@ export class BaseClient { * * @param key - The key to return the number of its members. * @returns the cardinality (number of elements) of the set, or 0 if key does not exist. + * + * @example + * ```typescript + * // Example usage of the scard method + * const result = await client.scard("my_set"); + * console.log(result); // Output: 3 + * ``` */ public scard(key: string): Promise { return this.createWritePromise(createSCard(key)); @@ -859,6 +1202,20 @@ export class BaseClient { * @param member - The member to check for existence in the set. * @returns `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`. + * + * @example + * ```typescript + * // Example usage of the sismember method when member exists + * const result = await client.sismember("my_set", "member1"); + * console.log(result); // Output: true - Indicates that "member1" exists in the set "my_set". + * ``` + * + * @example + * ```typescript + * // Example usage of the sismember method when member does not exist + * const result = await client.sismember("my_set", "non_existing_member"); + * console.log(result); // Output: false - Indicates that "non_existing_member" does not exist in the set "my_set". + * ``` */ public sismember(key: string, member: string): Promise { return this.createWritePromise(createSismember(key, member)); @@ -870,6 +1227,13 @@ export class BaseClient { * @param keys - The keys list to check. * @returns the number of keys that exist. If the same existing key is mentioned in `keys` multiple times, * it will be counted multiple times. + * + * @example + * ```typescript + * // Example usage of the exists method + * const result = await client.exists(["key1", "key2", "key3"]); + * console.log(result); // Output: 3 - Indicates that all three keys exist in the database. + * ``` */ public exists(keys: string[]): Promise { return this.createWritePromise(createExists(keys)); @@ -882,6 +1246,13 @@ export class BaseClient { * * @param keys - The keys we wanted to unlink. * @returns the number of keys that were unlinked. + * + * @example + * ```typescript + * // Example usage of the unlink method + * const result = await client.unlink(["key1", "key2", "key3"]); + * console.log(result); // Output: 3 - Indicates that all three keys were unlinked from the database. + * ``` */ public unlink(keys: string[]): Promise { return this.createWritePromise(createUnlink(keys)); @@ -898,6 +1269,13 @@ export class BaseClient { * @param option - The expire option. * @returns `true` if the timeout was set. `false` if the timeout was not set. e.g. key doesn't exist, * or operation skipped due to the provided arguments. + * + * @example + * ```typescript + * // Example usage of the expire method + * const result = await client.expire("my_key", 60); + * console.log(result); // Output: true - Indicates that a timeout of 60 seconds has been set for "my_key." + * ``` */ public expire( key: string, @@ -918,6 +1296,13 @@ export class BaseClient { * @param option - The expire option. * @returns `true` if the timeout was set. `false` if the timeout was not set. e.g. key doesn't exist, * or operation skipped due to the provided arguments. + * + * @example + * ```typescript + * // Example usage of the expireAt method + * const result = await client.expireAt("my_key", 1672531200, ExpireOptions.HasNoExpiry); + * console.log(result); // Output: true + * ``` */ public expireAt( key: string, @@ -940,6 +1325,13 @@ export class BaseClient { * @param option - The expire option. * @returns `true` if the timeout was set. `false` if the timeout was not set. e.g. key doesn't exist, * or operation skipped due to the provided arguments. + * + * @example + * ```typescript + * // Example usage of the pexpire method + * const result = await client.pexpire("my_key", 60000, ExpireOptions.HasNoExpiry); + * console.log(result); // Output: true - Indicates that a timeout of 60,000 milliseconds has been set for "my_key." + * ``` */ public pexpire( key: string, @@ -962,6 +1354,13 @@ export class BaseClient { * @param option - The expire option. * @returns `true` if the timeout was set. `false` if the timeout was not set. e.g. key doesn't exist, * or operation skipped due to the provided arguments. + * + * @example + * ```typescript + * // Example usage of the pexpireAt method + * const result = await client.pexpireAt("my_key", 1672531200000, ExpireOptions.HasNoExpiry); + * console.log(result); // Output: true + * ``` */ public pexpireAt( key: string, @@ -978,6 +1377,20 @@ export class BaseClient { * * @param key - The key to return its timeout. * @returns TTL in seconds, -2 if `key` does not exist or -1 if `key` exists but has no associated expire. + * + * @example + * ```typescript + * // Example usage of the ttl method with an existing key + * const result = await client.ttl("my_key"); + * console.log(result); // Output: 3600 - Indicates that "my_key" has a remaining time to live of 3600 seconds. + * ``` + * + * @example + * ```typescript + * // Example usage of the ttl method with a non-existing key + * const result = await client.ttl("nonexistent_key"); + * console.log(result); // Output: -2 + * ``` */ public ttl(key: string): Promise { return this.createWritePromise(createTTL(key)); @@ -1026,12 +1439,18 @@ export class BaseClient { * If `changed` is set, returns the number of elements updated in the sorted set. * * @example - * await client.zadd("mySortedSet", \{ "member1": 10.5, "member2": 8.2 \}) - * 2 (Indicates that two elements have been added to the sorted set "mySortedSet".) - * - * await client.zadd("existingSortedSet", \{ member1: 15.0, member2: 5.5 \}, \{ conditionalChange: "onlyIfExists" \} , true); - * 2 (Updates the scores of two existing members in the sorted set "existingSortedSet".) + * ```typescript + * // Example usage of the zadd method to add elements to a sorted set + * const result = await client.zadd("my_sorted_set", \{ "member1": 10.5, "member2": 8.2 \}); + * console.log(result); // Output: 2 - Indicates that two elements have been added to the sorted set "my_sorted_set." + * ``` * + * @example + * ```typescript + * // Example usage of the zadd method to update scores in an existing sorted set + * const result = await client.zadd("existing_sorted_set", \{ member1: 15.0, member2: 5.5 \}, options=\{ conditionalChange: "onlyIfExists" \} , changed=true); + * console.log(result); // Output: 2 - Updates the scores of two existing members in the sorted set "existing_sorted_set." + * ``` */ public zadd( key: string, @@ -1062,11 +1481,18 @@ export class BaseClient { * If there was a conflict with the options, the operation aborts and null is returned. * * @example - * await client.zaddIncr("mySortedSet", member , 5.0) - * 5.0 + * ```typescript + * // Example usage of the zaddIncr method to add a member with a score to a sorted set + * const result = await client.zaddIncr("my_sorted_set", member, 5.0); + * console.log(result); // Output: 5.0 + * ``` * - * await client.zaddIncr("existingSortedSet", member , "3.0" , \{ UpdateOptions: "ScoreLessThanCurrent" \}) - * null + * @example + * ```typescript + * // Example usage of the zaddIncr method to add or update a member with a score in an existing sorted set + * const result = await client.zaddIncr("existing_sorted_set", member, "3.0", \{ UpdateOptions: "ScoreLessThanCurrent" \}); + * console.log(result); // Output: null + * ``` */ public zaddIncr( key: string, @@ -1087,6 +1513,20 @@ export class BaseClient { * @param members - A list of members to remove from the sorted set. * @returns The number of members that were removed from the sorted set, not including non-existing members. * If `key` does not exist, it is treated as an empty sorted set, and this command returns 0. + * + * @example + * ```typescript + * // Example usage of the zrem function to remove members from a sorted set + * const result = await client.zrem("my_sorted_set", ["member1", "member2"]); + * console.log(result); // Output: 2 - Indicates that two members have been removed from the sorted set "my_sorted_set." + * ``` + * + * @example + * ```typescript + * // Example usage of the zrem function when the sorted set does not exist + * const result = await client.zrem("non_existing_sorted_set", ["member1", "member2"]); + * console.log(result); // Output: 0 - Indicates that no members were removed as the sorted set "non_existing_sorted_set" does not exist. + * ``` */ public zrem(key: string, members: string[]): Promise { return this.createWritePromise(createZrem(key, members)); @@ -1098,6 +1538,20 @@ export class BaseClient { * @param key - The key of the sorted set. * @returns The number of elements in the sorted set. * If `key` does not exist, it is treated as an empty sorted set, and this command returns 0. + * + * @example + * ```typescript + * // Example usage of the zcard method to get the cardinality of a sorted set + * const result = await client.zcard("my_sorted_set"); + * console.log(result); // Output: 3 - Indicates that there are 3 elements in the sorted set "my_sorted_set". + * ``` + * + * @example + * ```typescript + * // Example usage of the zcard method with a non-existing key + * const result = await client.zcard("non_existing_key"); + * console.log(result); // Output: 0 + * ``` */ public zcard(key: string): Promise { return this.createWritePromise(createZcard(key)); @@ -1111,6 +1565,20 @@ export class BaseClient { * @returns The score of the member. * If `member` does not exist in the sorted set, null is returned. * If `key` does not exist, null is returned. + * + * @example + * ```typescript + * // Example usage of the zscore function to get the score of a member in a sorted set + * const result = await client.zscore("my_sorted_set", "member"); + * console.log(result); // Output: 10.5 - Indicates that the score of "member" in the sorted set "my_sorted_set" is 10.5. + * ``` + * + * @example + * ```typescript + * // Example usage of the zscore function when the member does not exist in the sorted set + * const result = await client.zscore("my_sorted_set", "non_existing_member"); + * console.log(result); // Output: null + * ``` */ public zscore(key: string, member: string): Promise { return this.createWritePromise(createZscore(key, member)); @@ -1125,6 +1593,20 @@ export class BaseClient { * @returns The number of members in the specified score range. * If `key` does not exist, it is treated as an empty sorted set, and the command returns 0. * If `minScore` is greater than `maxScore`, 0 is returned. + * + * @example + * ```typescript + * // Example usage of the zcount method to count members in a sorted set within a score range + * const result = await client.zcount("my_sorted_set", \{ bound: 5.0, isInclusive: true \}, "positiveInfinity"); + * console.log(result); // Output: 2 - Indicates that there are 2 members with scores between 5.0 (inclusive) and +inf in the sorted set "my_sorted_set". + * ``` + * + * @example + * ```typescript + * // Example usage of the zcount method to count members in a sorted set within a score range + * const result = await client.zcount("my_sorted_set", \{ bound: 5.0, isInclusive: true \}, \{ bound: 10.0, isInclusive: false \}); + * console.log(result); // Output: 1 - Indicates that there is one member with score between 5.0 (inclusive) and 10.0 (exclusive) in the sorted set "my_sorted_set". + * ``` */ public zcount( key: string, @@ -1140,6 +1622,22 @@ export class BaseClient { * @param key - The key to check its length. * @returns - The length of the string value stored at key * If `key` does not exist, it is treated as an empty string, and the command returns 0. + * + * @example + * ```typescript + * // Example usage of set method + * // Example usage of strlen method with an existing key + * await client.set("key", "GLIDE"); + * const len1 = await client.strlen("key"); + * console.log(len1); // Output: 5 + * ``` + * + * @example + * ```typescript + * // Example usage of strlen method with a non-existing key + * const len2 = await client.strlen("non_existing_key"); + * console.log(len2); // Output: 0 + * ``` */ public strlen(key: string): Promise { return this.createWritePromise(createStrlen(key)); @@ -1150,6 +1648,14 @@ export class BaseClient { * * @param key - The `key` to check its data type. * @returns If the `key` exists, the type of the stored value is returned. Otherwise, a "none" string is returned. + * + * @example + * ```typescript + * // Example usage of type method + * await client.set("key", "value"); + * const type = await client.type("key"); + * console.log(type); // Output: 'string' + * ``` */ public type(key: string): Promise { return this.createWritePromise(createType(key)); @@ -1165,6 +1671,20 @@ export class BaseClient { * @returns A map of the removed members and their scores, ordered from the one with the lowest score to the one with the highest. * If `key` doesn't exist, it will be treated as an empty sorted set and the command returns an empty map. * If `count` is higher than the sorted set's cardinality, returns all members and their scores. + * + * @example + * ```typescript + * // Example usage of zpopmin method to remove and return the member with the lowest score from a sorted set + * const result = await client.zpopmin("my_sorted_set"); + * console.log(result); // Output: \{'member1': 5.0\} - Indicates that 'member1' with a score of 5.0 has been removed from the sorted set. + * ``` + * + * @example + * ```typescript + * // Example usage of zpopmin method to remove and return multiple members with the lowest scores from a sorted set + * const result = await client.zpopmin("my_sorted_set", 2); + * console.log(result); // Output: \{'member3': 7.5 , 'member2': 8.0\} - Indicates that 'member3' with a score of 7.5 and 'member2' with a score of 8.0 have been removed from the sorted set. + * ``` */ public zpopmin( key: string, @@ -1183,6 +1703,20 @@ export class BaseClient { * @returns A map of the removed members and their scores, ordered from the one with the highest score to the one with the lowest. * If `key` doesn't exist, it will be treated as an empty sorted set and the command returns an empty map. * If `count` is higher than the sorted set's cardinality, returns all members and their scores, ordered from highest to lowest. + * + * @example + * ```typescript + * // Example usage of zpopmax method to remove and return the member with the highest score from a sorted set + * const result = await client.zpopmax("my_sorted_set"); + * console.log(result); // Output: \{'member1': 10.0\} - Indicates that 'member1' with a score of 10.0 has been removed from the sorted set. + * ``` + * + * @example + * ```typescript + * // Example usage of zpopmax method to remove and return multiple members with the highest scores from a sorted set + * const result = await client.zpopmax("my_sorted_set", 2); + * console.log(result); // Output: \{'member2': 8.0, 'member3': 7.5\} - Indicates that 'member2' with a score of 8.0 and 'member3' with a score of 7.5 have been removed from the sorted set. + * ``` */ public zpopmax( key: string, @@ -1196,6 +1730,20 @@ export class BaseClient { * * @param key - The key to return its timeout. * @returns TTL in milliseconds. -2 if `key` does not exist, -1 if `key` exists but has no associated expire. + * + * @example + * ```typescript + * // Example usage of pttl method with an existing key + * const result = await client.pttl("my_key"); + * console.log(result); // Output: 5000 - Indicates that the key "my_key" has a remaining time to live of 5000 milliseconds. + * ``` + * + * @example + * ```typescript + * // Example usage of pttl method with a non-existing key + * const result = await client.pttl("non_existing_key"); + * console.log(result); // Output: -2 - Indicates that the key "non_existing_key" does not exist. + * ``` */ public pttl(key: string): Promise { return this.createWritePromise(createPttl(key)); @@ -1213,6 +1761,13 @@ export class BaseClient { * If `start` exceeds the end of the sorted set, or if `start` is greater than `end`, 0 returned. * If `end` exceeds the actual end of the sorted set, the range will stop at the actual end of the sorted set. * If `key` does not exist 0 will be returned. + * + * @example + * ```typescript + * // Example usage of zremRangeByRank method + * const result = await client.zremRangeByRank("my_sorted_set", 0, 2); + * console.log(result); // Output: 3 - Indicates that three elements have been removed from the sorted set "my_sorted_set" between ranks 0 and 2. + * ``` */ public zremRangeByRank( key: string, @@ -1231,6 +1786,20 @@ export class BaseClient { * @returns the number of members removed. * If `key` does not exist, it is treated as an empty sorted set, and the command returns 0. * If `minScore` is greater than `maxScore`, 0 is returned. + * + * @example + * ```typescript + * // Example usage of zremRangeByScore method to remove members from a sorted set based on score range + * const result = await client.zremRangeByScore("my_sorted_set", \{ bound: 5.0, isInclusive: true \}, "positiveInfinity"); + * console.log(result); // Output: 2 - Indicates that 2 members with scores between 5.0 (inclusive) and +inf have been removed from the sorted set "my_sorted_set". + * ``` + * + * @example + * ```typescript + * // Example usage of zremRangeByScore method when the sorted set does not exist + * const result = await client.zremRangeByScore("non_existing_sorted_set", \{ bound: 5.0, isInclusive: true \}, \{ bound: 10.0, isInclusive: false \}); + * console.log(result); // Output: 0 - Indicates that no members were removed as the sorted set "non_existing_sorted_set" does not exist. + * ``` */ public zremRangeByScore( key: string, @@ -1250,6 +1819,20 @@ export class BaseClient { * @param member - The member whose rank is to be retrieved. * @returns The rank of `member` in the sorted set. * If `key` doesn't exist, or if `member` is not present in the set, null will be returned. + * + * @example + * ```typescript + * // Example usage of zrank method to retrieve the rank of a member in a sorted set + * const result = await client.zrank("my_sorted_set", "member2"); + * console.log(result); // Output: 1 - Indicates that "member2" has the second-lowest score in the sorted set "my_sorted_set". + * ``` + * + * @example + * ```typescript + * // Example usage of zrank method with a non-existing member + * const result = await client.zrank("my_sorted_set", "non_existing_member"); + * console.log(result); // Output: null - Indicates that "non_existing_member" is not present in the sorted set "my_sorted_set". + * ``` */ public zrank(key: string, member: string): Promise { return this.createWritePromise(createZrank(key, member)); @@ -1264,6 +1847,20 @@ export class BaseClient { * If `key` doesn't exist, or if `member` is not present in the set, null will be returned. * * since - Redis version 7.2.0. + * + * @example + * ```typescript + * // Example usage of zrank_withscore method to retrieve the rank and score of a member in a sorted set + * const result = await client.zrank_withscore("my_sorted_set", "member2"); + * console.log(result); // Output: [1, 6.0] - Indicates that "member2" with score 6.0 has the second-lowest score in the sorted set "my_sorted_set". + * ``` + * + * @example + * ```typescript + * // Example usage of zrank_withscore method with a non-existing member + * const result = await client.zrank_withscore("my_sorted_set", "non_existing_member"); + * console.log(result); // Output: null - Indicates that "non_existing_member" is not present in the sorted set "my_sorted_set". + * ``` */ public zrankWithScore( key: string, @@ -1333,6 +1930,20 @@ export class BaseClient { * @param index - The `index` of the element in the list to retrieve. * @returns - The element at `index` in the list stored at `key`. * If `index` is out of range or if `key` does not exist, null is returned. + * + * @example + * ```typescript + * // Example usage of lindex method to retrieve elements from a list by index + * const result = await client.lindex("my_list", 0); + * console.log(result); // Output: 'value1' - Returns the first element in the list stored at 'my_list'. + * ``` + * + * @example + * ```typescript + * // Example usage of lindex method to retrieve elements from a list by negative index + * const result = await client.lindex("my_list", -1); + * console.log(result); // Output: 'value3' - Returns the last element in the list stored at 'my_list'. + * ``` */ public lindex(key: string, index: number): Promise { return this.createWritePromise(createLindex(key, index)); @@ -1344,6 +1955,13 @@ export class BaseClient { * * @param key - The key to remove the existing timeout on. * @returns `false` if `key` does not exist or does not have an associated timeout, `true` if the timeout has been removed. + * + * @example + * ```typescript + * // Example usage of persist method to remove the timeout associated with a key + * const result = await client.persist("my_key"); + * console.log(result); // Output: true - Indicates that the timeout associated with the key "my_key" was successfully removed. + * ``` */ public persist(key: string): Promise { return this.createWritePromise(createPersist(key)); @@ -1359,6 +1977,14 @@ export class BaseClient { * @param key - The key to rename. * @param newKey - The new name of the key. * @returns - If the `key` was successfully renamed, return "OK". If `key` does not exist, an error is thrown. + * + * @example + * ```typescript + * // Example usage of rename method to rename a key + * await client.set("old_key", "value"); + * const result = await client.rename("old_key", "new_key"); + * console.log(result); // Output: OK - Indicates successful renaming of the key "old_key" to "new_key". + * ``` */ public rename(key: string, newKey: string): Promise<"OK"> { return this.createWritePromise(createRename(key, newKey)); @@ -1378,8 +2004,11 @@ export class BaseClient { * formatted as [key, value]. If no element could be popped and the timeout expired, returns Null. * * @example - * await client.brpop(["list1", "list2"], 5); - * ["list1", "element"] + * ```typescript + * // Example usage of brpop method to block and wait for elements from multiple lists + * const result = await client.brpop(["list1", "list2"], 5); + * console.log(result); // Output: ["list1", "element"] - Indicates an element "element" was popped from "list1". + * ``` */ public brpop( keys: string[], diff --git a/node/src/RedisClient.ts b/node/src/RedisClient.ts index 0d55793a94..f5a5ab6edf 100644 --- a/node/src/RedisClient.ts +++ b/node/src/RedisClient.ts @@ -111,9 +111,10 @@ export class RedisClient extends BaseClient { * @remarks - This function should only be used for single-response commands. Commands that don't return response (such as SUBSCRIBE), or that return potentially more than a single response (such as XREAD), or that change the client's behavior (such as entering pub/sub mode on RESP2 connections) shouldn't be called using this function. * * @example - * Returns a list of all pub/sub clients: - * ```ts - * connection.customCommand(["CLIENT","LIST","TYPE", "PUBSUB"]) + * ```typescript + * // Example usage of customCommand method to retrieve pub/sub clients + * const result = await client.customCommand(["CLIENT", "LIST", "TYPE", "PUBSUB"],); + * console.log(result); // Output: Returns a list of all pub/sub clients * ``` */ public customCommand(args: string[]): Promise { @@ -127,6 +128,20 @@ export class RedisClient extends BaseClient { * If not provided, the server will respond with "PONG". * If provided, the server will respond with a copy of the message. * @returns - "PONG" if `message` is not provided, otherwise return a copy of `message`. + * + * @example + * ```typescript + * // Example usage of ping method without any message + * const result = await client.ping(); + * console.log(result); // Output: "PONG" + * ``` + * + * @example + * ```typescript + * // Example usage of ping method with a message + * const result = await client.ping("Hello"); + * console.log(result); // Output: "Hello" + * ``` */ public ping(message?: string): Promise { return this.createWritePromise(createPing(message)); @@ -148,6 +163,13 @@ export class RedisClient extends BaseClient { * * @param index - The index of the database to select. * @returns A simple OK response. + * + * @example + * ```typescript + * // Example usage of select method + * const result = await client.select(2); + * console.log(result); // Output: 'OK' + * ``` */ public select(index: number): Promise<"OK"> { return this.createWritePromise(createSelect(index)); @@ -157,6 +179,13 @@ export class RedisClient extends BaseClient { * See https://redis.io/commands/client-getname/ for more details. * * @returns the name of the client connection as a string if a name is set, or null if no name is assigned. + * + * @example + * ```typescript + * // Example usage of client_getname method + * const result = await client.client_getname(); + * console.log(result); // Output: 'Connection Name' + * ``` */ public clientGetName(): Promise { return this.createWritePromise(createClientGetName()); @@ -166,6 +195,13 @@ export class RedisClient extends BaseClient { * See https://redis.io/commands/config-rewrite/ for details. * * @returns "OK" when the configuration was rewritten properly. Otherwise, an error is thrown. + * + * @example + * ```typescript + * // Example usage of configRewrite command + * const result = await client.configRewrite(); + * console.log(result); // Output: 'OK' + * ``` */ public configRewrite(): Promise<"OK"> { return this.createWritePromise(createConfigRewrite()); @@ -175,6 +211,13 @@ export class RedisClient extends BaseClient { * See https://redis.io/commands/config-resetstat/ for details. * * @returns always "OK". + * + * @example + * ```typescript + * // Example usage of configResetStat command + * const result = await client.configResetStat(); + * console.log(result); // Output: 'OK' + * ``` */ public configResetStat(): Promise<"OK"> { return this.createWritePromise(createConfigResetStat()); @@ -196,6 +239,12 @@ export class RedisClient extends BaseClient { * * @returns A map of values corresponding to the configuration parameters. * + * @example + * ```typescript + * // Example usage of configGet method with multiple configuration parameters + * const result = await client.configGet(["timeout", "maxmemory"]); + * console.log(result); // Output: \{'timeout': '1000', 'maxmemory': '1GB'\} + * ``` */ public configGet(parameters: string[]): Promise> { return this.createWritePromise(createConfigGet(parameters)); @@ -209,8 +258,11 @@ export class RedisClient extends BaseClient { * @returns "OK" when the configuration was set properly. Otherwise an error is thrown. * * @example - * config_set([("timeout", "1000")], [("maxmemory", "1GB")]) - Returns OK - * + * ```typescript + * // Example usage of configSet method to set multiple configuration parameters + * const result = await client.configSet(\{ timeout: "1000", maxmemory, "1GB" \}); + * console.log(result); // Output: 'OK' + * ``` */ public configSet(parameters: Record): Promise<"OK"> { return this.createWritePromise(createConfigSet(parameters)); @@ -239,6 +291,13 @@ export class RedisClient extends BaseClient { * @returns - The current server time as a two items `array`: * A Unix timestamp and the amount of microseconds already elapsed in the current second. * The returned `array` is in a [Unix timestamp, Microseconds already elapsed] format. + * + * @example + * ```typescript + * // Example usage of time method without any argument + * const result = await client.time(); + * console.log(result); // Output: ['1710925775', '913580'] + * ``` */ public time(): Promise<[string, string]> { return this.createWritePromise(createTime()); diff --git a/node/src/RedisClusterClient.ts b/node/src/RedisClusterClient.ts index e19d00075f..4386f745ec 100644 --- a/node/src/RedisClusterClient.ts +++ b/node/src/RedisClusterClient.ts @@ -262,9 +262,10 @@ export class RedisClusterClient extends BaseClient { * @remarks - This function should only be used for single-response commands. Commands that don't return response (such as SUBSCRIBE), or that return potentially more than a single response (such as XREAD), or that change the client's behavior (such as entering pub/sub mode on RESP2 connections) shouldn't be called using this function. * * @example - * Returns a list of all pub/sub clients on all primary nodes - * ```ts - * connection.customCommand(["CLIENT", "LIST","TYPE", "PUBSUB"], "allPrimaries") + * ```typescript + * // Example usage of customCommand method to retrieve pub/sub clients with routing to all primary nodes + * const result = await client.customCommand(["CLIENT", "LIST", "TYPE", "PUBSUB"], "allPrimaries"); + * console.log(result); // Output: Returns a list of all pub/sub clients * ``` */ public customCommand(args: string[], route?: Routes): Promise { @@ -303,6 +304,20 @@ export class RedisClusterClient extends BaseClient { * @param route - The command will be routed to all primaries, unless `route` is provided, in which * case the client will route the command to the nodes defined by `route`. * @returns - "PONG" if `message` is not provided, otherwise return a copy of `message`. + * + * @example + * ```typescript + * // Example usage of ping method without any message + * const result = await client.ping(); + * console.log(result); // Output: "PONG" + * ``` + * + * @example + * ```typescript + * // Example usage of ping method with a message + * const result = await client.ping("Hello"); + * console.log(result); // Output: "Hello" + * ``` */ public ping(message?: string, route?: Routes): Promise { return this.createWritePromise( @@ -340,6 +355,20 @@ export class RedisClusterClient extends BaseClient { * @returns - the name of the client connection as a string if a name is set, or null if no name is assigned. * When specifying a route other than a single node, it returns a dictionary where each address is the key and * its corresponding node response is the value. + * + * @example + * ```typescript + * // Example usage of client_getname method + * const result = await client.client_getname(); + * console.log(result); // Output: 'Connection Name' + * ``` + * + * @example + * ```typescript + * // Example usage of clientGetName method with routing to all nodes + * const result = await client.clientGetName('allNodes'); + * console.log(result); // Output: \{'addr': 'Connection Name', 'addr2': 'Connection Name', 'addr3': 'Connection Name'\} + * ``` */ public clientGetName( route?: Routes, @@ -357,6 +386,13 @@ export class RedisClusterClient extends BaseClient { * case the client will route the command to the nodes defined by `route`. * * @returns "OK" when the configuration was rewritten properly. Otherwise, an error is thrown. + * + * @example + * ```typescript + * // Example usage of configRewrite command + * const result = await client.configRewrite(); + * console.log(result); // Output: 'OK' + * ``` */ public configRewrite(route?: Routes): Promise<"OK"> { return this.createWritePromise( @@ -372,6 +408,13 @@ export class RedisClusterClient extends BaseClient { * case the client will route the command to the nodes defined by `route`. * * @returns always "OK". + * + * @example + * ```typescript + * // Example usage of configResetStat command + * const result = await client.configResetStat(); + * console.log(result); // Output: 'OK' + * ``` */ public configResetStat(route?: Routes): Promise<"OK"> { return this.createWritePromise( @@ -405,6 +448,20 @@ export class RedisClusterClient extends BaseClient { * * @returns A map of values corresponding to the configuration parameters. When specifying a route other than a single node, * it returns a dictionary where each address is the key and its corresponding node response is the value. + * + * @example + * ```typescript + * // Example usage of config_get method with a single configuration parameter with routing to a random node + * const result = await client.config_get(["timeout"], "randomNode"); + * console.log(result); // Output: \{'timeout': '1000'\} + * ``` + * + * @example + * ```typescript + * // Example usage of configGet method with multiple configuration parameters + * const result = await client.configGet(["timeout", "maxmemory"]); + * console.log(result); // Output: \{'timeout': '1000', 'maxmemory': '1GB'\} + * ``` */ public configGet( parameters: string[], @@ -427,8 +484,11 @@ export class RedisClusterClient extends BaseClient { * @returns "OK" when the configuration was set properly. Otherwise an error is thrown. * * @example - * config_set([("timeout", "1000")], [("maxmemory", "1GB")]) - Returns OK - * + * ```typescript + * // Example usage of configSet method to set multiple configuration parameters + * const result = await client.configSet(\{ timeout: "1000", maxmemory, "1GB" \}); + * console.log(result); // Output: 'OK' + * ``` */ public configSet( parameters: Record, @@ -483,6 +543,20 @@ export class RedisClusterClient extends BaseClient { * The returned `array` is in a [Unix timestamp, Microseconds already elapsed] format. * When specifying a route other than a single node, it returns a dictionary where each address is the key and * its corresponding node response is the value. + * + * @example + * ```typescript + * // Example usage of time method without any argument + * const result = await client.time(); + * console.log(result); // Output: ['1710925775', '913580'] + * ``` + * + * @example + * ```typescript + * // Example usage of time method with routing to all nodes + * const result = await client.time('allNodes'); + * console.log(result); // Output: \{'addr': ['1710925775', '913580'], 'addr2': ['1710925775', '913580'], 'addr3': ['1710925775', '913580']\} + * ``` */ public time(route?: Routes): Promise> { return this.createWritePromise(createTime(), toProtobufRoute(route)); diff --git a/python/python/glide/async_commands/cluster_commands.py b/python/python/glide/async_commands/cluster_commands.py index 1576a91466..e3727adadb 100644 --- a/python/python/glide/async_commands/cluster_commands.py +++ b/python/python/glide/async_commands/cluster_commands.py @@ -118,6 +118,10 @@ async def config_rewrite( Returns: OK: OK is returned when the configuration was rewritten properly. Otherwise an error is raised. + + Example: + >>> await client.config_rewrite() + 'OK' """ return cast( TOK, await self._execute_command(RequestType.ConfigRewrite, [], route) @@ -327,7 +331,7 @@ async def time(self, route: Optional[Route] = None) -> TClusterResponse[List[str Examples: >>> await client.time() ['1710925775', '913580'] - >>> await client.client_getname(AllNodes()) + >>> await client.time(AllNodes()) {'addr': ['1710925775', '913580'], 'addr2': ['1710925775', '913580'], 'addr3': ['1710925775', '913580']} """ return cast( diff --git a/python/python/glide/async_commands/core.py b/python/python/glide/async_commands/core.py index 0d9ada155d..6e958b47e6 100644 --- a/python/python/glide/async_commands/core.py +++ b/python/python/glide/async_commands/core.py @@ -238,6 +238,10 @@ async def set( If the value is successfully set, return OK. If value isn't set because of only_if_exists or only_if_does_not_exist conditions, return None. If return_old_value is set, return the old value as a string. + + Example: + >>> await client.set("key", "value") + 'OK' """ args = [key, value] if conditional_set: @@ -260,6 +264,10 @@ async def get(self, key: str) -> Optional[str]: Returns: Optional[str]: If the key exists, returns the value of the key as a string. Otherwise, return None. + + Example: + >>> await client.get("key") + 'value' """ return cast( Optional[str], await self._execute_command(RequestType.GetString, [key]) @@ -275,6 +283,13 @@ async def delete(self, keys: List[str]) -> int: Returns: int: The number of keys that were deleted. + + Examples: + >>> await client.set("key", "value") + >>> await client.delete("key") + 1 + >>> await client.delete("key") + 0 """ return cast(int, await self._execute_command(RequestType.Del, keys)) @@ -289,6 +304,11 @@ async def incr(self, key: str) -> int: Returns: int: The value of `key` after the increment. + + Examples: + >>> await client.set("key", "10") + >>> await client.incr("key") + 11 """ return cast(int, await self._execute_command(RequestType.Incr, [key])) @@ -303,6 +323,11 @@ async def incrby(self, key: str, amount: int) -> int: Returns: int: The value of key after the increment. + + Example: + >>> await client.set("key", "10") + >>> await client.incrby("key" , 5) + 15 """ return cast( int, await self._execute_command(RequestType.IncrBy, [key, str(amount)]) @@ -321,6 +346,11 @@ async def incrbyfloat(self, key: str, amount: float) -> float: Returns: float: The value of key after the increment. + + Examples: + >>> await client.set("key", "10") + >>> await client.incrbyfloat("key" , 5.5) + 15.55 """ return cast( float, @@ -337,6 +367,10 @@ async def mset(self, key_value_map: Mapping[str, str]) -> TOK: Returns: OK: a simple OK response. + + Example: + >>> await client.mset({"key" : "value", "key2": "value2"}) + 'OK' """ parameters: List[str] = [] for pair in key_value_map.items(): @@ -354,6 +388,12 @@ async def mget(self, keys: List[str]) -> List[Optional[str]]: Returns: List[Optional[str]]: A list of values corresponding to the provided keys. If a key is not found, its corresponding value in the list will be None. + + Examples: + >>> await client.set("key1", "value1") + >>> await client.set("key1", "value1") + >>> await client.mget(["key1", "key2"]) + ['value1' , 'value2'] """ return cast( List[Optional[str]], await self._execute_command(RequestType.MGet, keys) @@ -370,6 +410,11 @@ async def decr(self, key: str) -> int: Returns: int: The value of key after the decrement. + + Examples: + >>> await client.set("key", "10") + >>> await client.decr("key") + 9 """ return cast(int, await self._execute_command(RequestType.Decr, [key])) @@ -385,6 +430,11 @@ async def decrby(self, key: str, amount: int) -> int: Returns: int: The value of key after the decrement. + + Example: + >>> await client.set("key", "10") + >>> await client.decrby("key" , 5) + 5 """ return cast( int, await self._execute_command(RequestType.DecrBy, [key, str(amount)]) @@ -405,7 +455,7 @@ async def hset(self, key: str, field_value_map: Mapping[str, str]) -> int: Example: >>> await client.hset("my_hash", {"field": "value", "field2": "value2"}) - 2 + 2 # Indicates that 2 fields were successfully set in the hash "my_hash". """ field_value_list: List[str] = [key] for pair in field_value_map.items(): @@ -667,8 +717,8 @@ async def lpush(self, key: str, elements: List[str]) -> int: int: The length of the list after the push operations. Examples: - >>> await client.lpush("my_list", ["value1", "value2"]) - 2 + >>> await client.lpush("my_list", ["value2", "value3"]) + 3 # Indicated that the new length of the list is 3 after the push operation. >>> await client.lpush("nonexistent_list", ["new_value"]) 1 """ @@ -714,9 +764,9 @@ async def lpop_count(self, key: str, count: int) -> Optional[List[str]]: If `key` does not exist, None will be returned. Examples: - >>> await client.lpop("my_list", 2) + >>> await client.lpop_count("my_list", 2) ["value1", "value2"] - >>> await client.lpop("non_exiting_key" , 3) + >>> await client.lpop_count("non_exiting_key" , 3) None """ return cast( @@ -806,8 +856,8 @@ async def rpush(self, key: str, elements: List[str]) -> int: int: The length of the list after the push operations. Examples: - >>> await client.rpush("my_list", ["value1", "value2"]) - 2 + >>> await client.rpush("my_list", ["value2", "value3"]) + 3 # Indicated that the new length of the list is 3 after the push operation. >>> await client.rpush("nonexistent_list", ["new_value"]) 1 """ @@ -853,9 +903,9 @@ async def rpop_count(self, key: str, count: int) -> Optional[List[str]]: If `key` does not exist, None will be returned. Examples: - >>> await client.rpop("my_list", 2) + >>> await client.rpop_count("my_list", 2) ["value1", "value2"] - >>> await client.rpop("non_exiting_key" , 7) + >>> await client.rpop_count("non_exiting_key" , 7) None """ return cast( @@ -1697,9 +1747,9 @@ async def zrem( If `key` does not exist, it is treated as an empty sorted set, and the command returns 0. Examples: - >>> await zrem("my_sorted_set", ["member1", "member2"]) + >>> await client.zrem("my_sorted_set", ["member1", "member2"]) 2 # Indicates that two members have been removed from the sorted set "my_sorted_set." - >>> await zrem("non_existing_sorted_set", ["member1", "member2"]) + >>> await client.zrem("non_existing_sorted_set", ["member1", "member2"]) 0 # Indicates that no members were removed as the sorted set "non_existing_sorted_set" does not exist. """ return cast( @@ -1723,9 +1773,9 @@ async def zscore(self, key: str, member: str) -> Optional[float]: If `key` does not exist, None is returned. Examples: - >>> await zscore("my_sorted_set", "member") + >>> await client.zscore("my_sorted_set", "member") 10.5 # Indicates that the score of "member" in the sorted set "my_sorted_set" is 10.5. - >>> await zscore("my_sorted_set", "non_existing_member") + >>> await client.zscore("my_sorted_set", "non_existing_member") None """ return cast( From decf7a1e3f37b4f8ef17471d07a88628a83683bf Mon Sep 17 00:00:00 2001 From: Shoham Elias <116083498+shohamazon@users.noreply.github.com> Date: Sun, 7 Apr 2024 11:51:31 +0300 Subject: [PATCH 02/26] Update node/src/BaseClient.ts Co-authored-by: Andrew Carbonetto --- node/src/BaseClient.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index 58f91c3364..58d32d23f8 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -508,7 +508,7 @@ export class BaseClient { * @example * ```typescript * // Example usage of mset method to set values for multiple keys - * const result = await client.mset(\{"key1": "value1", "key2": "value2"\}); + * const result = await client.mset({"key1": "value1", "key2": "value2"}); * console.log(result); // Output: 'OK' * ``` */ From 9a38647e109c71ff1446f86875530060de884ae6 Mon Sep 17 00:00:00 2001 From: Shoham Elias <116083498+shohamazon@users.noreply.github.com> Date: Sun, 7 Apr 2024 11:58:03 +0300 Subject: [PATCH 03/26] Update node/src/BaseClient.ts Co-authored-by: Andrew Carbonetto --- node/src/BaseClient.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index 58d32d23f8..5281c85140 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -762,7 +762,7 @@ export class BaseClient { * ```typescript * // Example usage of the hgetall method * const result = await client.hgetall("my_hash"); - * console.log(result); // Output: \{"field1": "value1", "field2": "value2"\} + * console.log(result); // Output: {"field1": "value1", "field2": "value2"} * ``` */ public hgetall(key: string): Promise> { From 89337e52f37b81e81d5f032e87b02a1c5a9123c5 Mon Sep 17 00:00:00 2001 From: Shoham Elias <116083498+shohamazon@users.noreply.github.com> Date: Sun, 7 Apr 2024 12:11:55 +0300 Subject: [PATCH 04/26] Update node/src/BaseClient.ts --- node/src/BaseClient.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index 5281c85140..880ab0ad04 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -621,6 +621,7 @@ export class BaseClient { * @example * ```typescript * // Example usage of the hget method + * await client.hset("my_hash", "field"); * const result = await client.hget("my_hash", "field"); * console.log(result); // Output: "value" * ``` From 10f9e0c19effae4661e692b0dd7814577063ee0d Mon Sep 17 00:00:00 2001 From: Shoham Elias Date: Sun, 7 Apr 2024 09:14:58 +0000 Subject: [PATCH 05/26] add hset example --- python/python/glide/async_commands/core.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python/python/glide/async_commands/core.py b/python/python/glide/async_commands/core.py index 6e958b47e6..78a8dd46a0 100644 --- a/python/python/glide/async_commands/core.py +++ b/python/python/glide/async_commands/core.py @@ -479,6 +479,7 @@ async def hget(self, key: str, field: str) -> Optional[str]: Returns None if `field` is not presented in the hash or `key` does not exist. Examples: + >>> await client.hset("my_hash", "field") >>> await client.hget("my_hash", "field") "value" >>> await client.hget("my_hash", "nonexistent_field") From 72551e967fa8d74d44491b54b33aeca31ae2071b Mon Sep 17 00:00:00 2001 From: Shoham Elias Date: Sun, 7 Apr 2024 10:35:28 +0000 Subject: [PATCH 06/26] add examples fo base client --- node/src/BaseClient.ts | 89 +++++++++++++++------- python/python/glide/async_commands/core.py | 5 ++ 2 files changed, 67 insertions(+), 27 deletions(-) diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index 880ab0ad04..272c1b312c 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -620,7 +620,7 @@ export class BaseClient { * * @example * ```typescript - * // Example usage of the hget method + * // Example usage of the hget method on an-existing field * await client.hset("my_hash", "field"); * const result = await client.hget("my_hash", "field"); * console.log(result); // Output: "value" @@ -628,7 +628,7 @@ export class BaseClient { * * @example * ```typescript - * // Example usage of the hget method + * // Example usage of the hget method on a non-existing field * const result = await client.hget("my_hash", "nonexistent_field"); * console.log(result); // Output: null * ``` @@ -671,7 +671,7 @@ export class BaseClient { * * @example * ```typescript - * // Example usage of the hsetnx method + * // Example usage of the hsetnx method on a field that already exists 132 * const result = await client.hsetnx("my_hash", "field", "value"); * console.log(result); // Output: true - Indicates that the field "field" was set successfully in the hash "my_hash". * ``` @@ -782,7 +782,7 @@ export class BaseClient { * * @example * ```typescript - * // Example usage of the hincrby method + * // Example usage of the hincrby method to increment the value in a hash by a specified amount * const result = await client.hincrby("my_hash", "field1", 5); * console.log(result); // Output: 5 * ``` @@ -807,7 +807,7 @@ export class BaseClient { * * @example * ```typescript - * // Example usage of the hincrbyfloat method + * // Example usage of the hincrbyfloat method to increment the value of a floating point in a hash by a specified amount * const result = await client.hincrbyfloat("my_hash", "field1", 2.5); * console.log(result); // Output: "2.5" * ``` @@ -1129,7 +1129,7 @@ export class BaseClient { * * @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`. - * @returns the number of members that were added to the set, not including all the members already present in the set. + * @returns The number of members that were added to the set, not including all the members already present in the set. * * @example * ```typescript @@ -1147,7 +1147,7 @@ export class BaseClient { * * @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`. - * @returns the number of members that were removed from the set, not including non existing members. + * @returns 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. * * @example @@ -1165,7 +1165,7 @@ export class BaseClient { * See https://redis.io/commands/smembers/ for details. * * @param key - The key to return its members. - * @returns all members of the set. + * @returns All members of the set. * If `key` does not exist, it is treated as an empty set and this command returns empty list. * * @example @@ -1183,7 +1183,7 @@ export class BaseClient { * See https://redis.io/commands/scard/ for details. * * @param key - The key to return the number of its members. - * @returns the cardinality (number of elements) of the set, or 0 if key does not exist. + * @returns The cardinality (number of elements) of the set, or 0 if key does not exist. * * @example * ```typescript @@ -1226,7 +1226,7 @@ export class BaseClient { * See https://redis.io/commands/exists/ for details. * * @param keys - The keys list to check. - * @returns the number of keys that exist. If the same existing key is mentioned in `keys` multiple times, + * @returns The number of keys that exist. If the same existing key is mentioned in `keys` multiple times, * it will be counted multiple times. * * @example @@ -1246,7 +1246,7 @@ export class BaseClient { * See https://redis.io/commands/unlink/ for details. * * @param keys - The keys we wanted to unlink. - * @returns the number of keys that were unlinked. + * @returns The number of keys that were unlinked. * * @example * ```typescript @@ -1275,8 +1275,15 @@ export class BaseClient { * ```typescript * // Example usage of the expire method * const result = await client.expire("my_key", 60); - * console.log(result); // Output: true - Indicates that a timeout of 60 seconds has been set for "my_key." + * console.log(result); // Output: true - Indicates that a timeout of 60 seconds has been set for "my_key". * ``` + * + * @example + * ```typescript + * // Example usage of the expire method with exisiting expiry + * const result = await client.expire("my_key", 60, ExpireOptions.HasNoExpiry); + * console.log(result); // Output: false - Indicates that "my_key" has an existing expiry. + * ``` */ public expire( key: string, @@ -1300,9 +1307,9 @@ export class BaseClient { * * @example * ```typescript - * // Example usage of the expireAt method + * // Example usage of the expireAt method on a key with no previus expiry * const result = await client.expireAt("my_key", 1672531200, ExpireOptions.HasNoExpiry); - * console.log(result); // Output: true + * console.log(result); // Output: true - Indicates that the expiration time for "my_key" was successfully set. * ``` */ public expireAt( @@ -1329,9 +1336,9 @@ export class BaseClient { * * @example * ```typescript - * // Example usage of the pexpire method + * // Example usage of the pexpire method on a key with no previus expiry * const result = await client.pexpire("my_key", 60000, ExpireOptions.HasNoExpiry); - * console.log(result); // Output: true - Indicates that a timeout of 60,000 milliseconds has been set for "my_key." + * console.log(result); // Output: true - Indicates that a timeout of 60,000 milliseconds has been set for "my_key". * ``` */ public pexpire( @@ -1358,9 +1365,9 @@ export class BaseClient { * * @example * ```typescript - * // Example usage of the pexpireAt method + * // Example usage of the pexpireAt method on a key with no previus expiry * const result = await client.pexpireAt("my_key", 1672531200000, ExpireOptions.HasNoExpiry); - * console.log(result); // Output: true + * console.log(result); // Output: true - Indicates that the expiration time for "my_key" was successfully set. * ``` */ public pexpireAt( @@ -1381,16 +1388,23 @@ export class BaseClient { * * @example * ```typescript - * // Example usage of the ttl method with an existing key + * // Example usage of the ttl method with existing key * const result = await client.ttl("my_key"); * console.log(result); // Output: 3600 - Indicates that "my_key" has a remaining time to live of 3600 seconds. * ``` * * @example * ```typescript + * // Example usage of the ttl method with existing key that has no associated expire. + * const result = await client.ttl("key"); + * console.log(result); // Output: -1 - Indicates that the key has no associated expire. + * ``` + * + * @example + * ```typescript * // Example usage of the ttl method with a non-existing key * const result = await client.ttl("nonexistent_key"); - * console.log(result); // Output: -2 + * console.log(result); // Output: -2 - Indicates that the key doesn't exist. * ``` */ public ttl(key: string): Promise { @@ -1492,7 +1506,7 @@ export class BaseClient { * ```typescript * // Example usage of the zaddIncr method to add or update a member with a score in an existing sorted set * const result = await client.zaddIncr("existing_sorted_set", member, "3.0", \{ UpdateOptions: "ScoreLessThanCurrent" \}); - * console.log(result); // Output: null + * console.log(result); // Output: null - Indicates that the member in the sorted set haven't been updated. * ``` */ public zaddIncr( @@ -1569,17 +1583,24 @@ export class BaseClient { * * @example * ```typescript - * // Example usage of the zscore function to get the score of a member in a sorted set + * // Example usage of the zscore method∂∂ to get the score of a member in a sorted set * const result = await client.zscore("my_sorted_set", "member"); * console.log(result); // Output: 10.5 - Indicates that the score of "member" in the sorted set "my_sorted_set" is 10.5. * ``` * * @example * ```typescript - * // Example usage of the zscore function when the member does not exist in the sorted set + * // Example usage of the zscore method when the member does not exist in the sorted set * const result = await client.zscore("my_sorted_set", "non_existing_member"); * console.log(result); // Output: null * ``` + * + * @example + * ```typescript + * // Example usage of the zscore method with non existimng key + * const result = await client.zscore("non_existing_set", "member"); + * console.log(result); // Output: null + * ``` */ public zscore(key: string, member: string): Promise { return this.createWritePromise(createZscore(key, member)); @@ -1626,7 +1647,6 @@ export class BaseClient { * * @example * ```typescript - * // Example usage of set method * // Example usage of strlen method with an existing key * await client.set("key", "GLIDE"); * const len1 = await client.strlen("key"); @@ -1652,11 +1672,19 @@ export class BaseClient { * * @example * ```typescript - * // Example usage of type method + * // Example usage of type method with a string value * await client.set("key", "value"); * const type = await client.type("key"); * console.log(type); // Output: 'string' * ``` + * + * @example + * ```typescript + * // Example usage of type method with a list + * await client.lpush("key", ["value"]); + * const type = await client.type("key"); + * console.log(type); // Output: 'list' + * ``` */ public type(key: string): Promise { return this.createWritePromise(createType(key)); @@ -1745,6 +1773,13 @@ export class BaseClient { * const result = await client.pttl("non_existing_key"); * console.log(result); // Output: -2 - Indicates that the key "non_existing_key" does not exist. * ``` + * + * @example + * ```typescript + * // Example usage of pttl method with an exisiting key that has no associated expire. + * const result = await client.pttl("key"); + * console.log(result); // Output: -1 - Indicates that the key "key" has no associated expire. + * ``` */ public pttl(key: string): Promise { return this.createWritePromise(createPttl(key)); @@ -1791,14 +1826,14 @@ export class BaseClient { * @example * ```typescript * // Example usage of zremRangeByScore method to remove members from a sorted set based on score range - * const result = await client.zremRangeByScore("my_sorted_set", \{ bound: 5.0, isInclusive: true \}, "positiveInfinity"); + * const result = await client.zremRangeByScore("my_sorted_set", { bound: 5.0, isInclusive: true }, "positiveInfinity"); * console.log(result); // Output: 2 - Indicates that 2 members with scores between 5.0 (inclusive) and +inf have been removed from the sorted set "my_sorted_set". * ``` * * @example * ```typescript * // Example usage of zremRangeByScore method when the sorted set does not exist - * const result = await client.zremRangeByScore("non_existing_sorted_set", \{ bound: 5.0, isInclusive: true \}, \{ bound: 10.0, isInclusive: false \}); + * const result = await client.zremRangeByScore("non_existing_sorted_set", { bound: 5.0, isInclusive: true }, { bound: 10.0, isInclusive: false }); * console.log(result); // Output: 0 - Indicates that no members were removed as the sorted set "non_existing_sorted_set" does not exist. * ``` */ diff --git a/python/python/glide/async_commands/core.py b/python/python/glide/async_commands/core.py index 78a8dd46a0..fd1597303b 100644 --- a/python/python/glide/async_commands/core.py +++ b/python/python/glide/async_commands/core.py @@ -1269,6 +1269,8 @@ async def ttl(self, key: str) -> int: 3600 # Indicates that "my_key" has a remaining time to live of 3600 seconds. >>> await client.ttl("nonexistent_key") -2 # Returns -2 for a non-existing key. + >>> await client.ttl("key") + -1 # Indicates that "key: has no has no associated expire. """ return cast(int, await self._execute_command(RequestType.TTL, [key])) @@ -1339,6 +1341,9 @@ async def type(self, key: str) -> str: >>> await client.set("key", "value") >>> await client.type("key") 'string' + >>> await client.lpush("key", ["value"]) + >>> await client.type("key") + 'list' """ return cast(str, await self._execute_command(RequestType.Type, [key])) From c0122a40d87210dc148f0524830848bc8c111d00 Mon Sep 17 00:00:00 2001 From: Shoham Elias Date: Sun, 7 Apr 2024 10:39:32 +0000 Subject: [PATCH 07/26] un prettier --- node/src/BaseClient.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index 272c1b312c..db5e441813 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -1277,13 +1277,13 @@ export class BaseClient { * const result = await client.expire("my_key", 60); * console.log(result); // Output: true - Indicates that a timeout of 60 seconds has been set for "my_key". * ``` - * + * * @example * ```typescript * // Example usage of the expire method with exisiting expiry * const result = await client.expire("my_key", 60, ExpireOptions.HasNoExpiry); * console.log(result); // Output: false - Indicates that "my_key" has an existing expiry. - * ``` + * ``` */ public expire( key: string, From e55da68cc59bc576aea27f7581ed1bc4aab6ebea Mon Sep 17 00:00:00 2001 From: Shoham Elias <116083498+shohamazon@users.noreply.github.com> Date: Sun, 7 Apr 2024 13:48:06 +0300 Subject: [PATCH 08/26] Update python/python/glide/async_commands/core.py Co-authored-by: Andrew Carbonetto --- python/python/glide/async_commands/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/python/glide/async_commands/core.py b/python/python/glide/async_commands/core.py index fd1597303b..3637fdda3b 100644 --- a/python/python/glide/async_commands/core.py +++ b/python/python/glide/async_commands/core.py @@ -391,7 +391,7 @@ async def mget(self, keys: List[str]) -> List[Optional[str]]: Examples: >>> await client.set("key1", "value1") - >>> await client.set("key1", "value1") + >>> await client.set("key2", "value2") >>> await client.mget(["key1", "key2"]) ['value1' , 'value2'] """ From bb5f19e04729d6f4df6cd9071054170a34f05f7a Mon Sep 17 00:00:00 2001 From: Shoham Elias <116083498+shohamazon@users.noreply.github.com> Date: Sun, 7 Apr 2024 13:48:18 +0300 Subject: [PATCH 09/26] Update node/src/RedisClient.ts Co-authored-by: Yury-Fridlyand --- node/src/RedisClient.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/src/RedisClient.ts b/node/src/RedisClient.ts index f5a5ab6edf..a01bbacff4 100644 --- a/node/src/RedisClient.ts +++ b/node/src/RedisClient.ts @@ -113,7 +113,7 @@ export class RedisClient extends BaseClient { * @example * ```typescript * // Example usage of customCommand method to retrieve pub/sub clients - * const result = await client.customCommand(["CLIENT", "LIST", "TYPE", "PUBSUB"],); + * const result = await client.customCommand(["CLIENT", "LIST", "TYPE", "PUBSUB"]); * console.log(result); // Output: Returns a list of all pub/sub clients * ``` */ From a1c1500055e02e9a0b45576258dced7817b46b54 Mon Sep 17 00:00:00 2001 From: Shoham Elias <116083498+shohamazon@users.noreply.github.com> Date: Sun, 7 Apr 2024 13:48:39 +0300 Subject: [PATCH 10/26] Update node/src/RedisClient.ts Co-authored-by: Yury-Fridlyand --- node/src/RedisClient.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/src/RedisClient.ts b/node/src/RedisClient.ts index a01bbacff4..3e80d18866 100644 --- a/node/src/RedisClient.ts +++ b/node/src/RedisClient.ts @@ -184,7 +184,7 @@ export class RedisClient extends BaseClient { * ```typescript * // Example usage of client_getname method * const result = await client.client_getname(); - * console.log(result); // Output: 'Connection Name' + * console.log(result); // Output: 'Client Name' * ``` */ public clientGetName(): Promise { From b25d166d23b6e54e86dcc84a9d29b958de0a3556 Mon Sep 17 00:00:00 2001 From: Shoham Elias <116083498+shohamazon@users.noreply.github.com> Date: Sun, 7 Apr 2024 13:49:06 +0300 Subject: [PATCH 11/26] Update python/python/glide/async_commands/core.py Co-authored-by: Andrew Carbonetto --- python/python/glide/async_commands/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/python/glide/async_commands/core.py b/python/python/glide/async_commands/core.py index 3637fdda3b..d7cfe7e3e3 100644 --- a/python/python/glide/async_commands/core.py +++ b/python/python/glide/async_commands/core.py @@ -719,7 +719,7 @@ async def lpush(self, key: str, elements: List[str]) -> int: Examples: >>> await client.lpush("my_list", ["value2", "value3"]) - 3 # Indicated that the new length of the list is 3 after the push operation. + 3 # Indicates that the new length of the list is 3 after the push operation. >>> await client.lpush("nonexistent_list", ["new_value"]) 1 """ From a08b7b7325f2db847ac194c1914f316eac9c534d Mon Sep 17 00:00:00 2001 From: Shoham Elias <116083498+shohamazon@users.noreply.github.com> Date: Sun, 7 Apr 2024 13:49:26 +0300 Subject: [PATCH 12/26] Update python/python/glide/async_commands/core.py Co-authored-by: Andrew Carbonetto --- python/python/glide/async_commands/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/python/glide/async_commands/core.py b/python/python/glide/async_commands/core.py index d7cfe7e3e3..258dac0382 100644 --- a/python/python/glide/async_commands/core.py +++ b/python/python/glide/async_commands/core.py @@ -858,7 +858,7 @@ async def rpush(self, key: str, elements: List[str]) -> int: Examples: >>> await client.rpush("my_list", ["value2", "value3"]) - 3 # Indicated that the new length of the list is 3 after the push operation. + 3 # Indicates that the new length of the list is 3 after the push operation. >>> await client.rpush("nonexistent_list", ["new_value"]) 1 """ From 0f163351d02f1c581a2d0fa0084fa94f695b2a6e Mon Sep 17 00:00:00 2001 From: Shoham Elias <116083498+shohamazon@users.noreply.github.com> Date: Sun, 7 Apr 2024 14:59:44 +0300 Subject: [PATCH 13/26] Update node/src/BaseClient.ts Co-authored-by: Andrew Carbonetto --- node/src/BaseClient.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index db5e441813..06d5462499 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -743,7 +743,7 @@ export class BaseClient { * * @example * ```typescript - * // Example usage of the hexists method with non existing field + * // Example usage of the hexists method with non-existing field * const result = await client.hexists("my_hash", "nonexistent_field"); * console.log(result); // Output: false * ``` From fb199ae4632fb399122ab207e197d650c28b3a86 Mon Sep 17 00:00:00 2001 From: Shoham Elias <116083498+shohamazon@users.noreply.github.com> Date: Sun, 7 Apr 2024 15:00:25 +0300 Subject: [PATCH 14/26] Update node/src/BaseClient.ts Co-authored-by: Yury-Fridlyand --- node/src/BaseClient.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index 06d5462499..511754deb8 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -881,7 +881,7 @@ export class BaseClient { * ```typescript * // Example usage of the lpush method with a non-existing list * const result = await client.lpush("nonexistent_list", ["new_value"]); - * console.log(result); // Output: 1 + * console.log(result); // Output: 1 - Indicates that a new list was created with one element * ``` */ public lpush(key: string, elements: string[]): Promise { From 31fb48a3c21bf5c54e35978cde5dece6c25162b5 Mon Sep 17 00:00:00 2001 From: Shoham Elias <116083498+shohamazon@users.noreply.github.com> Date: Sun, 7 Apr 2024 15:04:32 +0300 Subject: [PATCH 15/26] Update node/src/BaseClient.ts Co-authored-by: Andrew Carbonetto --- node/src/BaseClient.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index 511754deb8..56083563ce 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -1057,7 +1057,7 @@ export class BaseClient { * ```typescript * // Example usage of the rpush method with an existing list * const result = await client.rpush("my_list", ["value2", "value3"]); - * console.log(result); // Output: 3 - # Indicated that the new length of the list is 3 after the push operation. + * console.log(result); // Output: 3 - Indicates that the new length of the list is 3 after the push operation. * ``` * * @example From 62158a9eaaf56ff4c8430cda2e572bd27107d18e Mon Sep 17 00:00:00 2001 From: Shoham Elias <116083498+shohamazon@users.noreply.github.com> Date: Sun, 7 Apr 2024 15:11:56 +0300 Subject: [PATCH 16/26] Update node/src/BaseClient.ts Co-authored-by: Andrew Carbonetto --- node/src/BaseClient.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index 56083563ce..a7ba0399f8 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -1463,7 +1463,7 @@ export class BaseClient { * @example * ```typescript * // Example usage of the zadd method to update scores in an existing sorted set - * const result = await client.zadd("existing_sorted_set", \{ member1: 15.0, member2: 5.5 \}, options=\{ conditionalChange: "onlyIfExists" \} , changed=true); + * const result = await client.zadd("existing_sorted_set", { member1: 15.0, member2: 5.5 }, options={ conditionalChange: "onlyIfExists" } , changed=true); * console.log(result); // Output: 2 - Updates the scores of two existing members in the sorted set "existing_sorted_set." * ``` */ From 2716bd8a2e7bc606cff92c71d627dfb9834a3e6f Mon Sep 17 00:00:00 2001 From: Shoham Elias <116083498+shohamazon@users.noreply.github.com> Date: Sun, 7 Apr 2024 15:13:16 +0300 Subject: [PATCH 17/26] Update node/src/BaseClient.ts Co-authored-by: Andrew Carbonetto --- node/src/BaseClient.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index a7ba0399f8..f91a073e33 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -1505,7 +1505,7 @@ export class BaseClient { * @example * ```typescript * // Example usage of the zaddIncr method to add or update a member with a score in an existing sorted set - * const result = await client.zaddIncr("existing_sorted_set", member, "3.0", \{ UpdateOptions: "ScoreLessThanCurrent" \}); + * const result = await client.zaddIncr("existing_sorted_set", member, "3.0", { UpdateOptions: "ScoreLessThanCurrent" }); * console.log(result); // Output: null - Indicates that the member in the sorted set haven't been updated. * ``` */ From 4341eb2388e72c32a87af00ca0a183a596356279 Mon Sep 17 00:00:00 2001 From: Shoham Elias <116083498+shohamazon@users.noreply.github.com> Date: Sun, 7 Apr 2024 15:39:45 +0300 Subject: [PATCH 18/26] Update node/src/BaseClient.ts Co-authored-by: Andrew Carbonetto --- node/src/BaseClient.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index f91a073e33..eb85bf7d82 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -1626,7 +1626,7 @@ export class BaseClient { * @example * ```typescript * // Example usage of the zcount method to count members in a sorted set within a score range - * const result = await client.zcount("my_sorted_set", \{ bound: 5.0, isInclusive: true \}, \{ bound: 10.0, isInclusive: false \}); + * const result = await client.zcount("my_sorted_set", { bound: 5.0, isInclusive: true }, { bound: 10.0, isInclusive: false }); * console.log(result); // Output: 1 - Indicates that there is one member with score between 5.0 (inclusive) and 10.0 (exclusive) in the sorted set "my_sorted_set". * ``` */ From 926ba791f5d055b21b9ac616309c9fb034b40f80 Mon Sep 17 00:00:00 2001 From: Shoham Elias <116083498+shohamazon@users.noreply.github.com> Date: Sun, 7 Apr 2024 15:40:40 +0300 Subject: [PATCH 19/26] Update node/src/BaseClient.ts Co-authored-by: Andrew Carbonetto --- node/src/BaseClient.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index eb85bf7d82..f39efdc645 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -1744,7 +1744,7 @@ export class BaseClient { * ```typescript * // Example usage of zpopmax method to remove and return multiple members with the highest scores from a sorted set * const result = await client.zpopmax("my_sorted_set", 2); - * console.log(result); // Output: \{'member2': 8.0, 'member3': 7.5\} - Indicates that 'member2' with a score of 8.0 and 'member3' with a score of 7.5 have been removed from the sorted set. + * console.log(result); // Output: {'member2': 8.0, 'member3': 7.5} - Indicates that 'member2' with a score of 8.0 and 'member3' with a score of 7.5 have been removed from the sorted set. * ``` */ public zpopmax( From f7ec8a9d5011f6d63c69cc5fd305c27dbfbcf54f Mon Sep 17 00:00:00 2001 From: Shoham Elias <116083498+shohamazon@users.noreply.github.com> Date: Sun, 7 Apr 2024 15:41:14 +0300 Subject: [PATCH 20/26] Update node/src/BaseClient.ts Co-authored-by: Andrew Carbonetto --- node/src/BaseClient.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index f39efdc645..bebf7ddf30 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -1619,7 +1619,7 @@ export class BaseClient { * @example * ```typescript * // Example usage of the zcount method to count members in a sorted set within a score range - * const result = await client.zcount("my_sorted_set", \{ bound: 5.0, isInclusive: true \}, "positiveInfinity"); + * const result = await client.zcount("my_sorted_set", { bound: 5.0, isInclusive: true }, "positiveInfinity"); * console.log(result); // Output: 2 - Indicates that there are 2 members with scores between 5.0 (inclusive) and +inf in the sorted set "my_sorted_set". * ``` * From 2c4163b0cd2017f1d3c14598a8848b32803f839e Mon Sep 17 00:00:00 2001 From: Shoham Elias Date: Sun, 7 Apr 2024 12:54:05 +0000 Subject: [PATCH 21/26] have ' constistancy --- node/src/BaseClient.ts | 8 ++++---- node/src/RedisClient.ts | 10 +++++----- node/src/RedisClusterClient.ts | 16 ++++++++-------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index bebf7ddf30..ecdbe5f2aa 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -809,7 +809,7 @@ export class BaseClient { * ```typescript * // Example usage of the hincrbyfloat method to increment the value of a floating point in a hash by a specified amount * const result = await client.hincrbyfloat("my_hash", "field1", 2.5); - * console.log(result); // Output: "2.5" + * console.log(result); // Output: '2.5' * ``` */ public hincrByFloat( @@ -900,7 +900,7 @@ export class BaseClient { * ```typescript * // Example usage of the lpop method with an existing list * const result = await client.lpop("my_list"); - * console.log(result); // Output: "value1" + * console.log(result); // Output: 'value1' * ``` * * @example @@ -1015,7 +1015,7 @@ export class BaseClient { * ```typescript * // Example usage of the ltrim method * const result = await client.ltrim("my_list", 0, 1); - * console.log(result); // Output: "OK" - Indicates that the list has been trimmed to contain elements from 0 to 1. + * console.log(result); // Output: 'OK' - Indicates that the list has been trimmed to contain elements from 0 to 1. * ``` */ public ltrim(key: string, start: number, end: number): Promise<"OK"> { @@ -1083,7 +1083,7 @@ export class BaseClient { * ```typescript * // Example usage of the rpop method with an existing list * const result = await client.rpop("my_list"); - * console.log(result); // Output: "value1" + * console.log(result); // Output: 'value1' * ``` * * @example diff --git a/node/src/RedisClient.ts b/node/src/RedisClient.ts index 3e80d18866..cfa6db50b5 100644 --- a/node/src/RedisClient.ts +++ b/node/src/RedisClient.ts @@ -133,14 +133,14 @@ export class RedisClient extends BaseClient { * ```typescript * // Example usage of ping method without any message * const result = await client.ping(); - * console.log(result); // Output: "PONG" + * console.log(result); // Output: 'PONG' * ``` * * @example * ```typescript * // Example usage of ping method with a message * const result = await client.ping("Hello"); - * console.log(result); // Output: "Hello" + * console.log(result); // Output: 'Hello' * ``` */ public ping(message?: string): Promise { @@ -243,7 +243,7 @@ export class RedisClient extends BaseClient { * ```typescript * // Example usage of configGet method with multiple configuration parameters * const result = await client.configGet(["timeout", "maxmemory"]); - * console.log(result); // Output: \{'timeout': '1000', 'maxmemory': '1GB'\} + * console.log(result); // Output: {'timeout': '1000', 'maxmemory': '1GB'} * ``` */ public configGet(parameters: string[]): Promise> { @@ -260,7 +260,7 @@ export class RedisClient extends BaseClient { * @example * ```typescript * // Example usage of configSet method to set multiple configuration parameters - * const result = await client.configSet(\{ timeout: "1000", maxmemory, "1GB" \}); + * const result = await client.configSet({ timeout: "1000", maxmemory, "1GB" }); * console.log(result); // Output: 'OK' * ``` */ @@ -278,7 +278,7 @@ export class RedisClient extends BaseClient { * ```typescript * // Example usage of the echo command * const echoedMessage = await client.echo("Glide-for-Redis"); - * console.log(echoedMessage); // Output: "Glide-for-Redis" + * console.log(echoedMessage); // Output: 'Glide-for-Redis' * ``` */ public echo(message: string): Promise { diff --git a/node/src/RedisClusterClient.ts b/node/src/RedisClusterClient.ts index 4386f745ec..517e3f4d74 100644 --- a/node/src/RedisClusterClient.ts +++ b/node/src/RedisClusterClient.ts @@ -309,14 +309,14 @@ export class RedisClusterClient extends BaseClient { * ```typescript * // Example usage of ping method without any message * const result = await client.ping(); - * console.log(result); // Output: "PONG" + * console.log(result); // Output: 'PONG' * ``` * * @example * ```typescript * // Example usage of ping method with a message * const result = await client.ping("Hello"); - * console.log(result); // Output: "Hello" + * console.log(result); // Output: 'Hello' * ``` */ public ping(message?: string, route?: Routes): Promise { @@ -367,7 +367,7 @@ export class RedisClusterClient extends BaseClient { * ```typescript * // Example usage of clientGetName method with routing to all nodes * const result = await client.clientGetName('allNodes'); - * console.log(result); // Output: \{'addr': 'Connection Name', 'addr2': 'Connection Name', 'addr3': 'Connection Name'\} + * console.log(result); // Output: {'addr': 'Connection Name', 'addr2': 'Connection Name', 'addr3': 'Connection Name'} * ``` */ public clientGetName( @@ -453,14 +453,14 @@ export class RedisClusterClient extends BaseClient { * ```typescript * // Example usage of config_get method with a single configuration parameter with routing to a random node * const result = await client.config_get(["timeout"], "randomNode"); - * console.log(result); // Output: \{'timeout': '1000'\} + * console.log(result); // Output: {'timeout': '1000'} * ``` * * @example * ```typescript * // Example usage of configGet method with multiple configuration parameters * const result = await client.configGet(["timeout", "maxmemory"]); - * console.log(result); // Output: \{'timeout': '1000', 'maxmemory': '1GB'\} + * console.log(result); // Output: {'timeout': '1000', 'maxmemory': '1GB'} * ``` */ public configGet( @@ -486,7 +486,7 @@ export class RedisClusterClient extends BaseClient { * @example * ```typescript * // Example usage of configSet method to set multiple configuration parameters - * const result = await client.configSet(\{ timeout: "1000", maxmemory, "1GB" \}); + * const result = await client.configSet({ timeout: "1000", maxmemory, "1GB" }); * console.log(result); // Output: 'OK' * ``` */ @@ -519,7 +519,7 @@ export class RedisClusterClient extends BaseClient { * ```typescript * // Example usage of the echo command with routing to all nodes * const echoedMessage = await client.echo("Glide-for-Redis", "allNodes"); - * console.log(echoedMessage); // Output: \{'addr': 'Glide-for-Redis', 'addr2': 'Glide-for-Redis', 'addr3': 'Glide-for-Redis'\} + * console.log(echoedMessage); // Output: {'addr': 'Glide-for-Redis', 'addr2': 'Glide-for-Redis', 'addr3': 'Glide-for-Redis'} * ``` */ public echo( @@ -555,7 +555,7 @@ export class RedisClusterClient extends BaseClient { * ```typescript * // Example usage of time method with routing to all nodes * const result = await client.time('allNodes'); - * console.log(result); // Output: \{'addr': ['1710925775', '913580'], 'addr2': ['1710925775', '913580'], 'addr3': ['1710925775', '913580']\} + * console.log(result); // Output: {'addr': ['1710925775', '913580'], 'addr2': ['1710925775', '913580'], 'addr3': ['1710925775', '913580']} * ``` */ public time(route?: Routes): Promise> { From a3d3e2e15cd3e8310cc6100fba50f34c57487ada Mon Sep 17 00:00:00 2001 From: Shoham Elias Date: Sun, 7 Apr 2024 13:33:37 +0000 Subject: [PATCH 22/26] add set examples --- node/src/BaseClient.ts | 20 ++++++++++++++++---- python/python/glide/async_commands/core.py | 20 +++++++++++--------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index ecdbe5f2aa..25faccd417 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -444,6 +444,18 @@ export class BaseClient { * // Example usage of set method to set a key-value pair * const result = await client.set("my_key", "my_value"); * console.log(result); // Output: 'OK' + * + * // Example usage of set method with conditional options and expiration + * const result2 = await client.set("key", "new_value", {conditionalSet: "onlyIfExists", expiry: { type: "seconds", count: 5 }}); + * console.log(result2); // Output: 'OK' - Set "new_value" to "key" only if "key" already exists, and set the key expiration to 5 seconds. + * + * // Example usage of set method with conditional options and returning old value + * const result3 = await client.set("key", "value", {conditionalSet: "onlyIfDoesNotExist", returnOldValue: true}); + * console.log(result3); // Output: 'new_value' - Returns the old value of "key". + * + * // Example usage of get method to retrieve the value of a key + * const result4 = await client.get("key"); + * console.log(result4); // Output: 'new_value' - Value wasn't modified back to being "value" because of "NX" flag. * ``` */ public set( @@ -464,14 +476,14 @@ export class BaseClient { * ```typescript * // Example usage of del method to delete an existing key * await client.set("my_key", "my_value"); - * const result = await client.del("my_key"); + * const result = await client.del(["my_key"]); * console.log(result); // Output: 1 * ``` * * @example * ```typescript * // Example usage of del method for a non-existing key - * const result = await client.del("non_existing_key"); + * const result = await client.del(["non_existing_key"]); * console.log(result); // Output: 0 * ``` */ @@ -671,14 +683,14 @@ export class BaseClient { * * @example * ```typescript - * // Example usage of the hsetnx method on a field that already exists 132 + * // Example usage of the hsetnx method * const result = await client.hsetnx("my_hash", "field", "value"); * console.log(result); // Output: true - Indicates that the field "field" was set successfully in the hash "my_hash". * ``` * * @example * ```typescript - * // Example usage of the hsetnx method + * // Example usage of the hsetnx method on a field that already exists * const result = await client.hsetnx("my_hash", "field", "new_value"); * console.log(result); // Output: false - Indicates that the field "field" already existed in the hash "my_hash" and was not set again. * ``` diff --git a/python/python/glide/async_commands/core.py b/python/python/glide/async_commands/core.py index 258dac0382..2d6a1b4639 100644 --- a/python/python/glide/async_commands/core.py +++ b/python/python/glide/async_commands/core.py @@ -216,11 +216,7 @@ async def set( ) -> Optional[str]: """ Set the given key with the given value. Return value is dependent on the passed options. - See https://redis.io/commands/set/ for details. - - @example - Set "foo" to "bar" only if "foo" already exists, and set the key expiration to 5 seconds: - - connection.set("foo", "bar", conditional_set=ConditionalChange.ONLY_IF_EXISTS, expiry=Expiry(ExpiryType.SEC, 5)) + See https://redis.io/commands/set/ for more details. Args: key (str): the key to store. @@ -242,6 +238,12 @@ async def set( Example: >>> await client.set("key", "value") 'OK' + >>> await client.set("key", "new_value",conditional_set=ConditionalChange.ONLY_IF_EXISTS, expiry=Expiry(ExpiryType.SEC, 5)) + 'OK' # Set "new_value" to "key" only if "key" already exists, and set the key expiration to 5 seconds. + >>> await client.set("key", "value", conditional_set=ConditionalChange.ONLY_IF_DOES_NOT_EXIST,return_old_value=True) + 'new_value' # Returns the old value of "key". + >>> await client.get("key") + 'new_value' # Value wasn't modified back to being "value" because of "NX" flag. """ args = [key, value] if conditional_set: @@ -286,10 +288,10 @@ async def delete(self, keys: List[str]) -> int: Examples: >>> await client.set("key", "value") - >>> await client.delete("key") - 1 - >>> await client.delete("key") - 0 + >>> await client.delete(["key"]) + 1 # Indicates that the key was successfully deleted. + >>> await client.delete(["key"]) + 0 # No keys we're deleted since "key" doesn't exist. """ return cast(int, await self._execute_command(RequestType.Del, keys)) From fe9f9b6735231d182a04ff18c64d82c6accd1d8f Mon Sep 17 00:00:00 2001 From: Shoham Elias Date: Sun, 7 Apr 2024 13:37:36 +0000 Subject: [PATCH 23/26] fix typo --- node/src/BaseClient.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index 25faccd417..aba85df674 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -1319,7 +1319,7 @@ export class BaseClient { * * @example * ```typescript - * // Example usage of the expireAt method on a key with no previus expiry + * // Example usage of the expireAt method on a key with no previous expiry * const result = await client.expireAt("my_key", 1672531200, ExpireOptions.HasNoExpiry); * console.log(result); // Output: true - Indicates that the expiration time for "my_key" was successfully set. * ``` @@ -1348,7 +1348,7 @@ export class BaseClient { * * @example * ```typescript - * // Example usage of the pexpire method on a key with no previus expiry + * // Example usage of the pexpire method on a key with no previous expiry * const result = await client.pexpire("my_key", 60000, ExpireOptions.HasNoExpiry); * console.log(result); // Output: true - Indicates that a timeout of 60,000 milliseconds has been set for "my_key". * ``` @@ -1377,7 +1377,7 @@ export class BaseClient { * * @example * ```typescript - * // Example usage of the pexpireAt method on a key with no previus expiry + * // Example usage of the pexpireAt method on a key with no previous expiry * const result = await client.pexpireAt("my_key", 1672531200000, ExpireOptions.HasNoExpiry); * console.log(result); // Output: true - Indicates that the expiration time for "my_key" was successfully set. * ``` From fe17d154b2d8c341a27e6524d32ce77255296ab4 Mon Sep 17 00:00:00 2001 From: Shoham Elias <116083498+shohamazon@users.noreply.github.com> Date: Sun, 7 Apr 2024 16:39:05 +0300 Subject: [PATCH 24/26] Update node/src/BaseClient.ts Co-authored-by: Andrew Carbonetto --- node/src/BaseClient.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index aba85df674..fa78dd695a 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -1717,7 +1717,7 @@ export class BaseClient { * ```typescript * // Example usage of zpopmin method to remove and return the member with the lowest score from a sorted set * const result = await client.zpopmin("my_sorted_set"); - * console.log(result); // Output: \{'member1': 5.0\} - Indicates that 'member1' with a score of 5.0 has been removed from the sorted set. + * console.log(result); // Output: {'member1': 5.0} - Indicates that 'member1' with a score of 5.0 has been removed from the sorted set. * ``` * * @example From b16b348ee9ac157ae66b319c0b9a318c21189970 Mon Sep 17 00:00:00 2001 From: Shoham Elias <116083498+shohamazon@users.noreply.github.com> Date: Sun, 7 Apr 2024 16:39:32 +0300 Subject: [PATCH 25/26] Update node/src/BaseClient.ts Co-authored-by: Andrew Carbonetto --- node/src/BaseClient.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index fa78dd695a..2a4c0d458f 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -1749,7 +1749,7 @@ export class BaseClient { * ```typescript * // Example usage of zpopmax method to remove and return the member with the highest score from a sorted set * const result = await client.zpopmax("my_sorted_set"); - * console.log(result); // Output: \{'member1': 10.0\} - Indicates that 'member1' with a score of 10.0 has been removed from the sorted set. + * console.log(result); // Output: {'member1': 10.0} - Indicates that 'member1' with a score of 10.0 has been removed from the sorted set. * ``` * * @example From dced55166487bfe0d41d1972a2e5680d914eede0 Mon Sep 17 00:00:00 2001 From: Shoham Elias <116083498+shohamazon@users.noreply.github.com> Date: Sun, 7 Apr 2024 16:39:57 +0300 Subject: [PATCH 26/26] Update node/src/BaseClient.ts Co-authored-by: Andrew Carbonetto --- node/src/BaseClient.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index 2a4c0d458f..12ef4ae424 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -1724,7 +1724,7 @@ export class BaseClient { * ```typescript * // Example usage of zpopmin method to remove and return multiple members with the lowest scores from a sorted set * const result = await client.zpopmin("my_sorted_set", 2); - * console.log(result); // Output: \{'member3': 7.5 , 'member2': 8.0\} - Indicates that 'member3' with a score of 7.5 and 'member2' with a score of 8.0 have been removed from the sorted set. + * console.log(result); // Output: {'member3': 7.5 , 'member2': 8.0} - Indicates that 'member3' with a score of 7.5 and 'member2' with a score of 8.0 have been removed from the sorted set. * ``` */ public zpopmin(