Client
Overview
Module
- package:
@aerokit/sdk/redis - source: redis/client.ts
- last updated:
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:
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.
tsappend(key: string, value: string): number;
Parameter Type Description 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.
tsbitcount(key: string): number;
Parameter Type Description 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.
tsdecr(key: string): number;
Parameter Type Description keystringThe key holding the numeric value. Returns
- Type:
number- Description: The value of key after the decrement.
del()
Deletes the specified key.
tsdel(key: string): number;
Parameter Type Description 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.
tsexists(key: string): boolean;
Parameter Type Description keystringThe key to check. Returns
- Type:
boolean- Description: True if the key exists, false otherwise.
get()
Gets the value of the specified key.
tsget(key: string): string;
Parameter Type Description 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.
tsincr(key: string): number;
Parameter Type Description 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.
tskeys(pattern: string): void;
Parameter Type Description 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.
tsset(key: string, value: string): string;
Parameter Type Description 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.
tslindex(key: string, index: number): string;
Parameter Type Description 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.
tsllen(key: string): number;
Parameter Type Description 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).
tslpop(key: string): string;
Parameter Type Description 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).
tslpush(key: string, value: any): any;
Parameter Type Description 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.
tslrange(key: string, start: number, stop: number): void;
Parameter Type Description 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).
tsrpop(key: string): string;
Parameter Type Description 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).
tsrpush(key: string, value: any): number;
Parameter Type Description keystringThe key of the list. valueanyOne or more values to append to the list. Returns
- Type:
number- Description: The new length of the list.
