Skip to content

Commit 93706e5

Browse files
committed
docs: update class documentation for RedisPersistenceLayer with usage examples
1 parent dda4cf1 commit 93706e5

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

packages/idempotency/src/persistence/RedisPersistenceLayer.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,46 @@ import { BasePersistenceLayer } from './BasePersistenceLayer.js';
1616
import { IdempotencyRecord } from './IdempotencyRecord.js';
1717
import RedisConnection from './RedisConnection.js';
1818

19+
/**
20+
* Redis persistence layer for idempotency records.
21+
*
22+
* This class uses Redis to write and read idempotency records. It supports both the default Redis client
23+
* from @redis/client package as well as custom Redis clients.
24+
*
25+
* There are various options to configure the persistence layer, such as attribute names for storing
26+
* status, expiry, data, and validation keys in Redis.
27+
*
28+
* With default configuration, you don't need to create the Redis client beforehand, the persistence layer
29+
* will create it for you using the provided options. You can also bring your own Redis client by passing
30+
* it through the `client` option.
31+
*
32+
* See the {@link https://docs.powertools.aws.dev/lambda/typescript/latest/utilities/idempotency/ Idempotency documentation}
33+
* for more details on the Redis configuration and usage patterns.
34+
*
35+
* @example
36+
* ```ts
37+
* import { RedisPersistenceLayer } from '@aws-lambda-powertools/idempotency/redis';
38+
*
39+
* const persistence = await new RedisPersistenceLayer({ url: 'redis://localhost:6379' }).init();
40+
* ```
41+
*
42+
* @example
43+
* ```ts
44+
* // Using your own Redis client
45+
* import { createClient } from '@redis/client';
46+
* import { RedisPersistenceLayer } from '@aws-lambda-powertools/idempotency/redis';
47+
*
48+
* const redisClient = createClient({ url: 'redis://localhost:6379' });
49+
* await redisClient.connect();
50+
*
51+
* const persistence = new RedisPersistenceLayer({
52+
* client: redisClient,
53+
* });
54+
* ```
55+
*
56+
* @see https://github.com/redis/node-redis/tree/master/packages/client
57+
* @category Persistence Layer
58+
*/
1959
class RedisPersistenceLayer extends BasePersistenceLayer {
2060
readonly #client: RedisClientProtocol | RedisClientType | RedisClusterType;
2161
readonly #dataAttr: string;

0 commit comments

Comments
 (0)