Skip to content

Client ​

Overview ​

Module

The Redis Client module provides a JavaScript interface for interacting with Redis, a popular in-memory data structure store. This module serves as a facade for the underlying Java Redis client implementation, allowing developers to perform common Redis operations such as key-value manipulation and list management using a simple and intuitive API. The Client class abstracts the complexities of the Java implementation, providing a seamless experience for developers working with Redis in their applications built on the platform.

Key Features: ​

  • Key-Value Operations: Methods for setting, getting, deleting, and checking the existence of keys, as well as incrementing and decrementing numeric values.
  • List Operations: Methods for managing lists, including pushing and popping elements from both ends of the list and retrieving list elements by index or range.

Use Cases: ​

  • Caching: The Redis Client can be used to implement caching mechanisms in applications, improving performance by storing frequently accessed data in memory.
  • Session Management: Developers can use this module to manage user sessions in web applications by storing session data in Redis.
  • Real-Time Data Processing: The Redis Client is ideal for applications that require real-time data processing and quick access to data structures like lists and sets.

Example Usage: ​

ts
import { Client } from "@aerokit/sdk/redis";

const redisClient = new Client();

// Set a key-value pair
redisClient.set("myKey", "Hello, Redis!");

// Get the value of a key
const value = redisClient.get("myKey");
console.log(value); // Output: Hello, Redis!

// Push values to a list
redisClient.rpush("myList", "item1", "item2", "item3");

Classes ​

Client ​

append() ​

Appends a value to the value of a key. If the key does not exist, it is created and set to the initial value.

ts
append(key: string, value: string): number;
ParameterTypeDescription
keystringThe key to append to.
valuestringThe value string to append.

Returns

  • Type: number
  • Description: The length of the string after the append operation.

bitcount() ​

Counts the number of set bits (1s) in the string value of a key.

ts
bitcount(key: string): number;
ParameterTypeDescription
keystringThe key to perform the bitcount on.

Returns

  • Type: number
  • Description: The number of set bits.

decr() ​

Decrements the number stored at key by one.

ts
decr(key: string): number;
ParameterTypeDescription
keystringThe key holding the numeric value.

Returns

  • Type: number
  • Description: The value of key after the decrement.

del() ​

Deletes the specified key.

ts
del(key: string): number;
ParameterTypeDescription
keystringThe key to delete.

Returns

  • Type: number
  • Description: The number of keys that were removed (1 if successful, 0 otherwise).

exists() ​

Checks if the specified key exists.

ts
exists(key: string): boolean;
ParameterTypeDescription
keystringThe key to check.

Returns

  • Type: boolean
  • Description: True if the key exists, false otherwise.

get() ​

Gets the value of the specified key.

ts
get(key: string): string;
ParameterTypeDescription
keystringThe key to retrieve the value for.

Returns

  • Type: string
  • Description: The value of the key, or null if the key does not exist.

incr() ​

Increments the number stored at key by one.

ts
incr(key: string): number;
ParameterTypeDescription
keystringThe key holding the numeric value.

Returns

  • Type: number
  • Description: The value of key after the increment.

keys() ​

Finds all keys matching the given pattern.

ts
keys(pattern: string): void;
ParameterTypeDescription
patternstringThe pattern to match keys against (e.g., "user:*").

Returns

  • Type: void
  • Description: An array of matching keys.

set() ​

Sets the string value of a key.

ts
set(key: string, value: string): string;
ParameterTypeDescription
keystringThe key to set.
valuestringThe string value to assign to the key.

Returns

  • Type: string
  • Description: 'OK' on success.

lindex() ​

Gets an element from a list by its zero-based index.

ts
lindex(key: string, index: number): string;
ParameterTypeDescription
keystringThe key of the list.
indexnumberThe zero-based index (0 is the first element, -1 is the last).

Returns

  • Type: string
  • Description: The element at the specified index, or null if the index is out of range.

llen() ​

Gets the length of the list stored at the key.

ts
llen(key: string): number;
ParameterTypeDescription
keystringThe key of the list.

Returns

  • Type: number
  • Description: The length of the list.

lpop() ​

Removes and returns the first element of the list stored at the key (Left POP).

ts
lpop(key: string): string;
ParameterTypeDescription
keystringThe key of the list.

Returns

  • Type: string
  • Description: The first element of the list, or null when the list is empty.

lpush() ​

Inserts all specified values at the head of the list stored at the key (Left PUSH).

ts
lpush(key: string, value: any): any;
ParameterTypeDescription
keystringThe key of the list.
valueanyOne or more values to prepend to the list.

Returns

  • Type: any
  • Description: The new length of the list.

lrange() ​

Returns the specified elements of the list stored at the key.

ts
lrange(key: string, start: number, stop: number): void;
ParameterTypeDescription
keystringThe key of the list.
startnumberThe starting zero-based offset.
stopnumberThe stopping zero-based offset.

Returns

  • Type: void
  • Description: An array of elements in the specified range.

rpop() ​

Removes and returns the last element of the list stored at the key (Right POP).

ts
rpop(key: string): string;
ParameterTypeDescription
keystringThe key of the list.

Returns

  • Type: string
  • Description: The last element of the list, or null when the list is empty.

rpush() ​

Inserts all specified values at the tail of the list stored at the key (Right PUSH).

ts
rpush(key: string, value: any): number;
ParameterTypeDescription
keystringThe key of the list.
valueanyOne or more values to append to the list.

Returns

  • Type: number
  • Description: The new length of the list.

Released under the EPL-2.0 License.