Solidis LogoSolidis

API Reference

Complete reference documentation for all Solidis classes, methods, and interfaces.

SolidisClient
The main client class for interacting with Redis servers

Constructor

1new SolidisClient(options?: SolidisOptions)

Parameters

options
SolidisOptions
Optional configuration object
Connection Methods
async
connect(): Promise<void>

Establishes a connection to the Redis server. Must be called before performing any operations.

Example:
1const client = new SolidisClient();
2await client.connect();
Basic Operations

String Operations

async
set(key: string, value: string, options?: SetOptions): Promise<string>

Sets a key to hold the string value.

async
get(key: string): Promise<string | null>

Gets the value of a key.

async
del(key: string): Promise<number>

Deletes a key.

Example Usage

1// Set a value
2await client.set('user:123', 'John Doe');
3
4// Get a value
5const user = await client.get('user:123');
6console.log(user); // 'John Doe'
7
8// Delete a key
9await client.del('user:123');
Advanced Operations
1// Start a transaction
2const transaction = client.multi();
3
4// Queue commands (no await needed)
5transaction.set('key', 'value');
6transaction.incr('counter');
7transaction.get('key');
8
9// Execute transaction
10const results = await transaction.exec();
11
12console.log(results); // [[ 'OK' ], [ 1 ], [ &lt;Buffer 76 61 6c 75 65&gt; ]]</div>
13                      

Redis transactions allow the execution of a group of commands in a single step, with two important guarantees: all the commands in a transaction are serialized and executed sequentially, and either all or none of the commands are processed.

Configuration Options
1const client = new SolidisClient({
2  uri: 'redis://localhost:6379',
3  host: '127.0.0.1',
4  port: 6379,
5  useTLS: false,
6  lazyConnect: false,
7  authentication: {"{"}
8  username: 'user',
9  password: 'password'
10  {"}"},
11  database: 0,
12  clientName: 'solidis',
13  protocol: 'RESP2', // 'RESP2' or 'RESP3'
14  autoReconnect: true,
15  enableReadyCheck: true,
16  maxConnectionRetries: 20,
17  connectionRetryDelay: 100,
18  commandTimeout: 5000,
19  connectionTimeout: 2000,
20  socketWriteTimeout: 1000,
21  readyCheckInterval: 100,
22  maxCommandsPerPipeline: 300,
23  maxProcessRepliesPerChunk: 4 * 1024, // 4KB
24  maxSocketWriteSizePerOnce: 64 * 1024, // 64KB
25  rejectOnPartialPipelineError: false,
26  debug: false,
27  debugMaxEntries: 10 * 1024,
28});
Advanced Features
1// Import the client and commands
2import { SolidisClient } from '@vcms-io/solidis';
3import { get, set } from '@vcms-io/solidis/command';
4import type { SolidisClientExtensions } from '@vcms-io/solidis';
5
6// Define extensions with custom commands
7const extensions = {
8  get,
9  set,
10  // Custom command implementation
11  fill: async function(this: typeof client, keys: string[], value: string) {
12    return await Promise.all(keys.map((key) => this.set(key, value)));
13  },
14} satisfies SolidisClientExtensions;
15
16// Initialize client with extensions
17const client = new SolidisClient({
18  host: '127.0.0.1',
19  port: 6379
20}).extend(extensions);
21
22// Use custom command
23await client.fill(['key1', 'key2', 'key3'], 'value');

You can extend Solidis with custom commands to create higher-level abstractions or implement specialized functionality for your application.

Error Handling
1// Import error classes
2import {
3  SolidisClientError,
4  SolidisConnectionError,
5  SolidisParserError,
6  SolidisPubSubError,
7  SolidisRequesterError,
8  unwrapSolidisError,
9} from '@vcms-io/solidis';
10
11// Error handling example
12try {
13  await client.set('key', 'value');
14} catch (error) {
15  // Get the root cause with stack trace
16  console.error(unwrapSolidisError(error));
17
18  // Handle specific error types
19  if (error instanceof SolidisConnectionError) {
20    console.error('Connection error:', error.message);
21  } else if (error instanceof SolidisParserError) {
22    console.error('Parser error:', error.message);
23  } else if (error instanceof SolidisClientError) {
24    console.error('Client error:', error.message);
25  }
26}

Error Types

  • SolidisClientErrorBase error class for all Solidis errors
  • SolidisConnectionErrorErrors related to connection issues
  • SolidisParserErrorErrors during RESP protocol parsing
  • SolidisPubSubErrorErrors related to Pub/Sub operations
  • SolidisRequesterErrorErrors during command execution
Events
1// Connection events
2client.on('connect', () => console.log('Connected to server'));
3client.on('ready', () => console.log('Client is ready'));
4client.on('end', () => console.log('Connection closed'));
5client.on('error', (err) => console.error('Error:', err));
6
7// Pub/Sub events
8client.on('message', (channel, message) => console.log(`${channel}: ${message}`));
9client.on('pmessage', (pattern, channel, message) => console.log(`${pattern} ${channel}: ${message}`));
10client.on('subscribe', (channel, count) => console.log(`Subscribed to ${channel}`));
11client.on('unsubscribe', (channel, count) => console.log(`Unsubscribed from ${channel}`));
12
13// Debug events
14client.on('debug', (entry) => console.log(`[${entry.type}] ${entry.message}`));

Event Types

  • connectEmitted when the client connects to the server
  • readyEmitted when the client is ready to send commands
  • endEmitted when the connection is closed
  • errorEmitted when an error occurs
  • messageEmitted when a message is received on a subscribed channel