Setup for Alokai Storefront
This documentation explains how to get started with Redis caching in the Alokai Storefront application.
Requirements
- @vsf-enterprise NPM registry access,
- Redis server up and running on your local machine.
Redis in Alokai Cloud
Alokai Storefront applications deployed to our Alokai Cloud can use a built-in Redis service offered as part of our enterprise offering. To enable it, contact your Customer Success manager or use our Support channel.
Installation
Alokai integration with Redis is encapsulated within a single SDK module. To install it in your project, navigate to the frontend directory:
cd apps/storefront-unified-nextjs
and use the following command:
yarn add @vsf-enterprise/redis-sdk
Configuration
The next step is registering the Redis module in the Alokai SDK. It ships with methods responsible for communicating with a Redis server to add or get records from it.
In the /apps/storefront-unified-nextjs/sdk
directory, find the sdk.config.ts
file and initialize the Redis module with the following lines:
import { redisModule } from '@vsf-enterprise/redis-sdk';
export const { getSdk } = createSdk(options, ({ buildModule }) => ({
// ...
redis: buildModule(redisModule, {
ioredis: {
host: process.env.NODE_ENV === "development" ? "localhost" : "redis",
port: 6379,
},
defaultTimeToLive: 10000,
dataPrefix: "mydataprefix:",
tagPrefix: "mytagprefix:",
enabled: true,
}),
}));
A complete list describing available configuration options can be found below.
Property | Required? | Description |
---|---|---|
ioredis | ❌ | Object used to initialize the ioredis client |
defaultTimeToLive | ❌ | Global time (in seconds) after which data records saved in redis using the setCache and getOrSetCache methods will be deleted. |
dataPrefix | ❌ | Prefix for all data keys stored in Redis. Defaults to data:. |
tagPrefix | ❌ | Prefix for all tag keys stored in Redis. Defaults to tag:. |
enabled | ❌ | Disables caching globally by inactivating certain SDK methods when set to false. The inactivated methods stop communicating with the Redis server. Instead, they become no-ops returning no data (e.g. getCache) or returning the data. Defaults to true. |
id | ❌ | Unique identifier of a module instance. Recommended while using multiple instances of the Redis module so that each instance is assigned its own ioredis client instead of sharing one. |
What next?
With the SDK module for Redis configured, proceed to the Guides section to learn about using its methods to improve your Storefront performance.