Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: correct node cache example #5084

Merged
merged 3 commits into from
Feb 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions docs/docs/clients/server-side.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1892,8 +1892,8 @@ interface.
For example, this cache implementation uses Redis as a backing store:

```typescript
import { Flagsmith } from 'flagsmith-nodejs';
import type { BaseOfflineHandler, EnvironmentModel, Flags, FlagsmithCache } from 'flagsmith-nodejs';
import { Flagsmith, Flags } from 'flagsmith-nodejs';
import type { BaseOfflineHandler, EnvironmentModel, FlagsmithCache } from 'flagsmith-nodejs';
import * as redis from 'redis';

const redisClient = redis.createClient({
Expand All @@ -1903,11 +1903,12 @@ const redisClient = redis.createClient({
const redisFlagsmithCache = {
async get(key: string): Promise<Flags | undefined> {
const cachedValue = await redisClient.get(key);
return Promise.resolve(cachedValue && JSON.parse(cachedValue));
if (cachedValue) {
return new Flags(JSON.parse(cachedValue));
}
},
async set(key: string, value: Flags): Promise<void> {
await redisClient.set(key, JSON.stringify(value), { EX: 60 });
return Promise.resolve();
},
} satisfies FlagsmithCache;

Expand Down
Loading