Return rejected promise and don't set cache if key or value is null.
This commit is contained in:
5
seasoned_api/src/cache/redis.js
vendored
5
seasoned_api/src/cache/redis.js
vendored
@@ -11,7 +11,7 @@ class Cache {
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
client.get(key, (error, reply) => {
|
client.get(key, (error, reply) => {
|
||||||
if (reply == null) {
|
if (reply == null) {
|
||||||
reject()
|
return reject()
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve(JSON.parse(reply))
|
resolve(JSON.parse(reply))
|
||||||
@@ -27,6 +27,9 @@ class Cache {
|
|||||||
* @returns {Object}
|
* @returns {Object}
|
||||||
*/
|
*/
|
||||||
set(key, value, timeToLive = 10800) {
|
set(key, value, timeToLive = 10800) {
|
||||||
|
if (value == null || key == null)
|
||||||
|
return null
|
||||||
|
|
||||||
const json = JSON.stringify(value);
|
const json = JSON.stringify(value);
|
||||||
client.set(key, json, (error, reply) => {
|
client.set(key, json, (error, reply) => {
|
||||||
if (reply == 'OK') {
|
if (reply == 'OK') {
|
||||||
|
|||||||
Reference in New Issue
Block a user