Skip to content

Commit 4efa8de

Browse files
committed
fix: update Redis client deletion method to accept an array of keys
1 parent 5cf6c04 commit 4efa8de

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

packages/idempotency/src/persistence/RedisPersistenceLayer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class RedisPersistenceLayer extends BasePersistenceLayer {
8686
* Initializes the Redis connection if it's the default Redis client and not already open.
8787
*
8888
* This method attempts to connect to Redis if necessary. If using a custom Redis client,
89-
* it assumes the client is already initialized.
89+
* it assumes the client is already connected.
9090
*
9191
* @throws {IdempotencyPersistenceConnectionError} When the connection to Redis fails
9292
*/
@@ -123,7 +123,7 @@ class RedisPersistenceLayer extends BasePersistenceLayer {
123123
console.debug(
124124
`Deleting record for idempotency key: ${record.idempotencyKey}`
125125
);
126-
await this.#client.del(record.idempotencyKey);
126+
await this.#client.del([record.idempotencyKey]);
127127
}
128128

129129
protected async _putRecord(record: IdempotencyRecord): Promise<void> {

packages/idempotency/src/types/RedisPersistence.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
import type { JSONValue } from '@aws-lambda-powertools/commons/types';
2+
13
/**
24
* Protocol defining the interface for a Redis client.
3-
* This ensures standardization among different Redis client implementations.
5+
*
6+
* This protocol outlines the expected behavior of a Redis client, allowing for
7+
* standardization among different implementations and allowing customers to extend it
8+
* in their own implementation.
49
*/
510
interface RedisClientProtocol {
611
/**
@@ -17,18 +22,18 @@ interface RedisClientProtocol {
1722
*/
1823
set(
1924
name: string,
20-
value: string,
25+
value: JSONValue,
2126
options?: {
2227
EX?: number; // Expiration time in seconds
2328
NX?: boolean; // Only set the key if it does not already exist
2429
}
2530
): Promise<string | null>;
2631

2732
/**
28-
* Deletes one or more keys.
29-
* @param keys The key(s) to delete
33+
* Deletes the specified keys from Redis.
34+
* @param keys The keys to delete
3035
*/
31-
del(keys: string): Promise<number>;
36+
del(keys: string[]): Promise<number>;
3237
}
3338

3439
/**

packages/idempotency/tests/unit/persistence/RedisPersistenceLayer.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ describe('Class: RedisPersistenceLayerTestClass', () => {
399399
await layer._deleteRecord(record);
400400

401401
// Assess
402-
expect(client.del).toHaveBeenCalledWith(dummyKey);
402+
expect(client.del).toHaveBeenCalledWith([dummyKey]);
403403
expect(consoleDebugSpy).toHaveBeenCalledWith(
404404
`Deleting record for idempotency key: ${record.idempotencyKey}`
405405
);

0 commit comments

Comments
 (0)