Skip to content

Commit 54d17d3

Browse files
authored
Add support for async serializer for use with worker threads (#390)
1 parent f390403 commit 54d17d3

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ interface NormalizedRedisClient {
1212
}
1313

1414
interface Serializer {
15-
parse(s: string): SessionData
15+
parse(s: string): SessionData | Promise<SessionData>
1616
stringify(s: SessionData): string
1717
}
1818

@@ -83,7 +83,7 @@ class RedisStore extends Store {
8383
try {
8484
let data = await this.client.get(key)
8585
if (!data) return cb()
86-
return cb(null, this.serializer.parse(data))
86+
return cb(null, await this.serializer.parse(data))
8787
} catch (err) {
8888
return cb(err)
8989
}

readme.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,11 @@ This option disables key expiration requiring the user to manually manage key cl
113113

114114
Provide a custom encoder/decoder to use when storing and retrieving session data from Redis (default: `JSON.parse` and `JSON.stringify`).
115115

116+
Optionally `parse` method can be async if need be.
117+
116118
```ts
117119
interface Serializer {
118-
parse(string): object
120+
parse(string): object | Promise<object>
119121
stringify(object): string
120122
}
121123
```

0 commit comments

Comments
 (0)