Skip to content

Redis

Workload for Redis API compatible key-value stores.

Description

With this workload you define Redis key-value stores.

A Redis workload is initialized with a stable ID.

See examples.

Each workload has an environment variable name associated with it to hold the connection string for the database named after the workloads' id. For example:

  • id documents: ML_REDIS_DOCUMENTS_URL.

Client

You can use any Redis client with the workload.

The client is defined by passing a constructor function when initializing the workload.

You access the client with the client accessor. This accessor will call this client constructor function with the workload's environment variable name and memoize its result.

See examples.

Development environment

A docker container for the dev environment is launched with npx monolayer start dev

You can stop it with npx monolayer stop dev.

After the container is started:

  • The environment variable with the connection string for the workload's Docker container will be written to .env.

INFO

Check your framework documentation to see it the .env file is loaded automatically.

Test environment

A docker container for the test environment is launched with npx monolayer start test

You can stop it with npx monolayer stop test.

  • The environment variable with the connection string for the workload's Docker container will be written to .env.test.

INFO

Check your framework documentation to see it the .env.test file is loaded automatically.

Example

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

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