Skip to content

Commit

Permalink
fix: deserialize dates
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-pr-p committed Jan 20, 2020
1 parent 62aabcf commit 5ef962a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "memoredis",
"version": "1.0.3",
"version": "1.0.4",
"description": "Redis memoization library with good Typescript generics, locking, and argument-wide bulk invalidation",
"main": "build/main/index.js",
"typings": "build/main/index.d.ts",
Expand Down Expand Up @@ -51,6 +51,7 @@
"node": ">=8.9"
},
"dependencies": {
"json-date-parser": "^1.0.1",
"json-stable-stringify": "^1.0.1",
"redis": "^2.8.0",
"redis-lock": "^0.1.4",
Expand Down
7 changes: 6 additions & 1 deletion src/lib/memoizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import jsonStableStringify from 'json-stable-stringify';
import redis, { ClientOpts, RedisClient } from 'redis';
import redisLock from 'redis-lock';
import { String } from 'runtypes';
import { jsonDateParser } from 'json-date-parser';

const SafeString = String.withConstraint(
s => !s.includes(':') && !s.includes('|')
Expand Down Expand Up @@ -72,7 +73,11 @@ export const createMemoizer = (instanceOpts: MemoizerOpts) => {
client.get(key, (err, reply) =>
err
? reject(err)
: resolve(reply !== null ? (JSON.parse(reply) as T) : (reply as null))
: resolve(
reply !== null
? (JSON.parse(reply, jsonDateParser) as T)
: (reply as null)
)
)
);

Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2995,6 +2995,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/json-buffer/-/json-buffer-3.0.0.tgz#5b1f397afc75d677bde8bcfc0e47e1f9a3d9a898"
integrity sha1-Wx85evx11ne96Lz8Dkfh+aPZqJg=

json-date-parser@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/json-date-parser/-/json-date-parser-1.0.1.tgz#b70eb47c898f3b16643ad63ffb8d9620fd784f85"
integrity sha1-tw60fImPOxZkOtY/+42WIP14T4U=

json-parse-better-errors@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz#bb867cfb3450e69107c131d1c514bab3dc8bcaa9"
Expand Down

0 comments on commit 5ef962a

Please sign in to comment.