Skip to content

Commit

Permalink
Add support for async serializer for use with worker threads (#390)
Browse files Browse the repository at this point in the history
  • Loading branch information
ozcanovunc authored May 11, 2023
1 parent f390403 commit 54d17d3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface NormalizedRedisClient {
}

interface Serializer {
parse(s: string): SessionData
parse(s: string): SessionData | Promise<SessionData>
stringify(s: SessionData): string
}

Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<object>
stringify(object): string
}
```
Expand Down

0 comments on commit 54d17d3

Please sign in to comment.