This document provides a reference for the Redis Shell API.
The ConnectionManager class manages Redis connections.
Initialize the connection manager.
Add a connection.
connection_id- Connection IDconnection_info- Connection informationhost- Redis hostport- Redis portdb- Redis database numberpassword- Redis password
Get a connection by ID.
connection_id- Connection ID
Returns the connection information or None if not found.
Get all connections.
Returns a dictionary of connection IDs to connection information.
Remove a connection.
connection_id- Connection ID
Set the current connection ID.
connection_id- Connection ID
Raises ValueError if the connection ID does not exist.
Get the current connection ID.
Returns the current connection ID or None if not set.
Get the current connection parameters.
Returns a tuple of (host, port, db, password).
Raises ValueError if no current connection is set.
Get a Redis client for the current connection.
Returns a Redis client or None if no current connection is set.
Check if the current connection is a cluster connection.
Returns True if the current connection is a cluster connection, False otherwise.
The StateManager class manages application state.
Initialize the state manager.
Get a state value.
key- State keydefault- Default value if the key does not exist
Returns the state value or the default value if the key does not exist.
Set a state value.
key- State keyvalue- State value
Get the command history.
Returns a list of command strings.
Add a command to the history.
command- Command string
Clear the command history.
The ExtensionManager class manages extensions.
Initialize the extension manager.
cli- CLI instance
Load all extensions.
Load an extension from the given path.
extension_path- Path to the extension directory
Returns the extension information.
Get an extension by namespace.
namespace- Extension namespace
Returns the extension information or None if not found.
Handle a command.
namespace- Extension namespaceargs- Command arguments
Returns the command result or None if the command is not handled.
Get completions for the given text.
text- Text to complete
Returns a list of (completion, description) tuples.
The Config class manages application configuration.
Initialize the configuration manager.
Get a configuration value.
section- Configuration sectionkey- Configuration keydefault- Default value if not found
Returns the configuration value or the default value if not found.
Set a configuration value.
section- Configuration sectionkey- Configuration keyvalue- Configuration value
Get a configuration section.
section- Configuration section
Returns the configuration section as a dictionary.
Get the entire configuration.
Returns the entire configuration as a dictionary.
Save the configuration to file.
The PathHandler class provides utilities for file path operations.
Parse an incomplete path into components.
incomplete- The incomplete path string
Returns a tuple of (base_dir, prefix, is_absolute, path_prefix).
Get directory completions for an incomplete path.
incomplete- The incomplete path string
Returns a list of directory completions.
Get file completions for an incomplete path matching a pattern.
incomplete- The incomplete path stringpattern- The glob pattern to match files against
Returns a list of file completions.
Get completions for an incomplete path, including both directories and files.
incomplete- The incomplete path stringfile_pattern- Optional glob pattern to match files against
Returns a list of path completions.
The CommandParser class provides utilities for command parsing.
Parse a command line into command and arguments.
command_line- The command line to parse
Returns a tuple of (command, args).
Create an argument parser for a command.
description- Command descriptionoptions- List of option definitions
Returns an argument parser.
The CommandFormatter class provides utilities for formatting command output.
Format a table for display.
headers- List of column headersrows- List of rows (each row is a list of column values)padding- Padding between columns
Returns a formatted table string.
Format a dictionary as key-value pairs.
data- Dictionary to formatindent- Indentation level
Returns a formatted string.
The CompletionRegistry class manages completion providers.
Register a completion provider.
name- The name of the providerprovider- The completion provider
Get a completion provider by name.
name- The name of the provider
Returns the completion provider, or None if not found.
Get completions from a provider.
name- The name of the providertext- The text to complete
Returns a list of completions.
The setup_logging function sets up logging for redis-shell.
Set up logging for redis-shell.
level- Log level (debug, info, warning, error, critical)log_file- Optional log file pathlog_format- Optional log format string
Returns a logger instance.
The RedisConnectionHelper class provides utilities for Redis connection operations.
create_redis_client(host='localhost', port=6379, db=0, password=None, decode_responses=False, ssl=False, ssl_ca_certs=None)
Create a standard Redis client.
host- Redis hostport- Redis portdb- Redis database numberpassword- Redis passworddecode_responses- Whether to decode responsesssl- Whether to use SSLssl_ca_certs- Path to CA certificates file
Returns a Redis client.
Check if a Redis client is connected to a cluster.
client- Redis client
Returns a tuple of (is_cluster, nodes).
Create a Redis cluster client.
nodes- List of cluster nodespassword- Redis passworddecode_responses- Whether to decode responsesssl- Whether to use SSLssl_ca_certs- Path to CA certificates file
Returns a Redis cluster client.
Get Redis server information.
client- Redis client
Returns a dictionary of Redis server information.
Format a Redis value for display.
value- Redis value
Returns a formatted value string.