Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for async serializer so it can be used with worker threads #390

Merged
merged 1 commit into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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