Когда я пытаюсь сохранить следующие данные в Redis:
{ _id: 5c9535a742e1ce2b2ce90be5,
email: 'admin@admin.com',
items:
[ { _id: 5c9535c042e1ce2b2ce90be6, product: [Object], quantity: 1 },
{ _id: 5c9535c642e1ce2b2ce90beb, product: [Object], quantity: 1 } ],
createdOn: 2019-03-22T19:21:11.349Z,
__v: 0 }
Я получаю следующее предупреждение:
node_redis: Deprecated: The SETEX command contains a argument of type model.
This is converted to "{ _id: 5c9535a742e1ce2b2ce90be5,
email: 'admin@admin.com',
items:
[ { _id: 5c9535c042e1ce2b2ce90be6, product: [Object], quantity: 1 },
{ _id: 5c9535c642e1ce2b2ce90beb, product: [Object], quantity: 1 } ],
createdOn: 2019-03-22T19:21:11.349Z,
__v: 0 }" by using .toString() now and will return an error from v.3.0 on.
Please handle this in your code to make sure everything works as you
intended it to.
Когда я пытаюсь получить данные из Redis, я получаю следующую ошибку:
undefined:1
{ _id: 5c9535a742e1ce2b2ce90be5,
^
SyntaxError: Unexpected token _ in JSON at position 2
at JSON.parse (<anonymous>)
Функция, используемая для сохранения в Redis:
exports.setCart = (email, cart) => {
cart - JSON.stringify(cart);
redisClient.setex(email, CACHE_TTL, cart);
}
Функция, используемая для извлечения данных из Redis:
exports.getCart = (email, callback) => {
redisClient.get(email, (err, cart) => {
if(err) {return callback(err, null)}
console.log('CART FROM CACHE ', cart)
return callback(err, JSON.parse(cart));
})
}
Вызов функции для сохранения данных в redis:
redisClient.setCart(email, cart);