From 6a1da30eba7e00459400533ab72cad43ee56b933 Mon Sep 17 00:00:00 2001 From: Ozcan Ovunc Date: Tue, 9 May 2023 21:24:09 +0300 Subject: [PATCH] Add support for async serializer so it can be used with worker threads --- index.ts | 4 ++-- readme.md | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/index.ts b/index.ts index 51de30f..88af6a0 100644 --- a/index.ts +++ b/index.ts @@ -12,7 +12,7 @@ interface NormalizedRedisClient { } interface Serializer { - parse(s: string): SessionData + parse(s: string): SessionData | Promise stringify(s: SessionData): string } @@ -83,7 +83,7 @@ class RedisStore extends Store { try { let data = await this.client.get(key) if (!data) return cb() - return cb(null, this.serializer.parse(data)) + return cb(null, await this.serializer.parse(data)) } catch (err) { return cb(err) } diff --git a/readme.md b/readme.md index 416de32..7c26f1b 100644 --- a/readme.md +++ b/readme.md @@ -113,9 +113,11 @@ This option disables key expiration requiring the user to manually manage key cl Provide a custom encoder/decoder to use when storing and retrieving session data from Redis (default: `JSON.parse` and `JSON.stringify`). +Optionally `parse` method can be async if need be. + ```ts interface Serializer { - parse(string): object + parse(string): object | Promise stringify(object): string } ```