Skip to content

workloads / main / Redis

Class: Redis

Workload for Redis API compatible servers.

The Redis workload is initialized with:

  • A stable ID.
  • A client constructor function providing the client of your choice. The Redis.client | client accessor will call this function and memoize its result. The expected envirnoment variable name with the connection string is passed as an argument.

NOTES

When launching the development or test containers with npx monolayer start dev, the environment variable with the connection string for the workload's Docker container will be written to the corresponding dotenv file (.env or .env.test)

Example

ts
import { Redis } from "@monolayer/sdk";
import { Redis as IORedis } from "ioredis";

const cache = new Redis("cache", (envVarName) =>
  new IORedis(process.env[envVarName]!)
);

Type Param

Client type

Extends

Accessors

connectionString

Get Signature

ts
get connectionString(): string

Reads the value fron environment variable name that should hold the connection string.

Returns

string

Inherited from

StatefulWorkloadWithClient.connectionString


connectionStringEnvVar

Get Signature

ts
get connectionStringEnvVar(): string

Returns the unique environment variable name that should hold the connection string.

Returns

string

Inherited from

StatefulWorkloadWithClient.connectionStringEnvVar

Constructors

new Redis()

ts
new Redis(id): Redis

Parameters

ParameterTypeDescription

id

string

Unique ID.

Returns

Redis

Inherited from

StatefulWorkloadWithClient.constructor

Properties

PropertyModifierTypeDescription
idreadonlystringUnique ID