Skip to content

Commit

Permalink
fix: 🐛 correct redis stringify
Browse files Browse the repository at this point in the history
  • Loading branch information
djdembeck committed Sep 25, 2021
1 parent c17d76c commit b21bdeb
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
2 changes: 0 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"dependencies": {
"cheerio": "^1.0.0-rc.10",
"concurrently": "^6.2.1",
"fast-json-stringify": "^2.7.10",
"fastify": "^3.21.6",
"fastify-plugin": "^3.0.0",
"fastify-redis": "^4.3.1",
Expand Down
9 changes: 4 additions & 5 deletions src/config/routes/books/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import ChapterHelper from '../../../helpers/audibleChapter'
import ScrapeHelper from '../../../helpers/audibleScrape'
import SharedHelper from '../../../helpers/shared'
import StitchHelper from '../../../helpers/audibleStitch'
import fastJson from 'fast-json-stringify'

async function routes (fastify, options) {
fastify.get('/books/:asin', async (request, reply) => {
Expand All @@ -16,17 +15,17 @@ async function routes (fastify, options) {

const { redis } = fastify
const findInRedis = await redis.get(request.params.asin, (val: string) => {
return JSON.parse(val)
return val
})

const findInDb = await Promise.resolve(Book.findOne({
asin: request.params.asin
}))

if (findInRedis) {
return findInRedis
return JSON.parse(findInRedis)
} else if (findInDb) {
redis.set(request.params.asin, fastJson(findInDb))
redis.set(request.params.asin, JSON.stringify(findInDb, null, 2))
return findInDb
} else {
// Set up helpers
Expand All @@ -49,7 +48,7 @@ async function routes (fastify, options) {
}
const stichedData = await Promise.resolve(stitch.process())
const newDbItem = await Promise.resolve(Book.insertOne(stichedData))
redis.set(request.params.asin, fastJson(newDbItem))
redis.set(request.params.asin, JSON.stringify(newDbItem, null, 2))
return newDbItem
}
})
Expand Down

0 comments on commit b21bdeb

Please sign in to comment.