redis.connector Documentation
Purpose
The redis.connector logic serves as an adapter that connects to a Redis database for executing commands. By simplifying the integration process with Redis, this component allows users to perform various operations such as data retrieval or modification directly through the Vantage analytics and data platform, making it an essential tool for businesses reliant on real-time data processing.
Settings
The redis.connector accepts the following settings:
1. inputs.command
- Input Type: String
- Description: This setting represents the specific Redis command that the user wishes to execute (e.g.,
SET,GET,DEL). It is a required field, and without it, the connector cannot perform any operations. - Default Value: None (this field must be provided).
2. inputs.args
- Input Type: Array of Strings (optional)
- Description: This setting allows users to specify any arguments that the Redis command may require. It is an optional field; however, the necessity of this parameter is dictated by the command being executed. For example, the
SETcommand would require a key and a value, which should be passed as separate elements of this array. - Default Value: Empty array
[](if no arguments are supplied).
3. session.user.clientId
- Input Type: String
- Description: This field is derived from the user’s session and represents the client's unique identifier within the system. It is crucial as it ensures that the user is authenticated and has access to their specific Redis service and credentials.
- Default Value: None (this value is obtained from the active session).
How It Works
-
Session Validation: The
redis.connectorfirst validates the user's session to ensure the user is logged in. If not, an error message is displayed requesting the user to log in. -
Command Verification: The connector checks whether the required
inputs.commandis provided. If missing, it throws an error. -
Service Lookup: Using the
clientId, the connector retrieves the Redis service details from the database. If no service is found, it returns a message indicating that no Redis service exists for the client. -
Credential Retrieval: The connector fetches the necessary credentials for accessing the Redis service. If no credentials are found, it returns an error message.
-
Command Execution: Upon successfully obtaining the Redis service and credentials, the connector initializes the integration using the required credentials. It then executes the specified Redis command, along with any provided arguments.
-
Error Handling: If any errors occur during the execution (e.g., malformed command, connection issues), an error message is displayed with specific details regarding the failure.
Data Expectations
The redis.connector expects a well-defined set of data in the following format:
-
inputs: An object containing:
command(string): The command to be executed.args(optional array): The list of arguments for the command.
-
Session Data: The logic expects the session to contain a valid
clientIdthat corresponds to the user's account.
Use Cases & Examples
Use Cases
-
Real-time Data Caching: A business using Redis for real-time data caching may need to refresh cache contents frequently based on user interactions. The
redis.connectorcan be employed to issue commands dynamically based on user inputs or application state. -
Data Analytics: Analytics platforms may need to read from or manipulate cached datasets in Redis for reporting or analytical purposes. The
redis.connectorallows configuration of commands that can support such data manipulations efficiently. -
Session Management: An application leveraging Redis for session management can utilize the
redis.connectorto modify session states (like expiration) or retrieve user session data quickly.
Example Configuration
Use Case Example: Real-time Data Caching
Scenario: A web application, OrderTracker, needs to update the order status in Redis whenever an order is placed.
Configuration:
const redisCommandConfig = {
inputs: {
command: 'SET', // Command to execute
args: ['order:12345', 'delivered'], // Setting order ID with its new status as 'delivered'
},
};Implementation:
In the component, you could integrate the redis.connector as follows:
const response = await redisConnector(redisCommandConfig);
console.log(response.output1); // Confirm the command execution or catch potential errorsIn this example, upon execution, the redis.connector would update the order status for order ID 12345 in the Redis database to delivered, enabling real-time updates for users tracking their orders.