- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
当我尝试将以下数据保存到 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);
最佳答案
我不认为 redis 能够直接处理 JSON 对象——尤其是嵌套的 JSON。您可以将一个简单的 JSON 对象存储为散列(我所说的简单是指它是一个平面 JSON,没有包含其他嵌套 JSON 对象的属性)。
最简单的解决方案是在存储之前对所有内容进行 JSON.stringify()
,然后在检索它们时对它们进行 JSON.parse()
。
如果您的对象不是太大,这很好,但它仍然不理想。另一种选择是使用 flat
npm 包,它基本上可以将嵌套的 JSON 扁平化,以便将它们存储为哈希。您可以在 this 上查看有关它的更多信息中等文章。
关于node.js - 为什么我会收到以下 Redis 警告和错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55622890/
这个问题在这里已经有了答案: standalone parentheses in javascript [duplicate] (5 个答案) 关闭 8 年前。 我在学习JavaScript,有时会
我是mysql新手,我必须减少以下更新查询的执行时间 UPDATE temp_countcalculations, ( SELECT count(*) as insuffcounts,CRP_
def escape_html(s): for (i, o) in (("&","&"),(">", ">"),(" "变成 ">"等。 关于python - 以下 for 循环
if (read(read(cin, data1), data2)) 问题是C++ Primer 5th Edition 的练习。 read 函数定义如下: std::istream &read(st
我想创建两个宏。其中一个将扩展到函数原型(prototype)和函数内容,另一个将扩展到仅函数原型(prototype)。我正在考虑创建以下内容: #ifdef SOME_CONDITION #def
我正在使用 jongo API - org.jongo.MongoCollection 是类。 我有对象 ID 列表并转换为与 ObjectId[] 相同并尝试按如下方式查询 collection.f
有人可以解释以下正则表达式匹配什么吗? ^.*$ 谢谢! 最佳答案 或者整个字符串或者整行,取决于是否multiline mode被使用。 关于java - 以下 ^.*$ 正则表达式匹配什么?,我们
#include void main() { int a,b,c; for(b = c = 10; a = "- FIGURE?, UMKC,XYZHello Folks,TFy!QJ
我的代码段中的以下代码行被 Sonar 检测为问题。 代码段: final int Pending=1; Sonar 问题: Name 'Pending' must matc
Print name of all activities with neither maximum nor minimum number of participants 我尝试了以下查询,但出现错误:
这个问题在这里已经有了答案: What is this practice called in JavaScript? (7 个回答) 关闭8年前。 (function() { //do stuff
根据任务,我们必须通过 foldr 实现 foldl。通过比较函数签名和 foldl 实现,我得到了以下解决方案: myFoldl :: (a -> b -> a) -> a -> [b] -> a
这个问题在这里已经有了答案: Export an es6 default class inline with definition or at end of file? (1 个回答) 关闭 2 年
据我了解,以下是相同的: Person p{}; // Case 1 Person p = {}; // Case 1.5 我注意到 Person p = Person{}; // Case 2 产生
below i have given a javascript code picture `` can any one help me in this code. what do this code.
我想在标题和正文上搜索全文,并在答案计数上进行过滤。 我阅读了elasticsearch documentation for combining filters并构建了此查询。 "query": {
它是流动的 C 代码中的内存泄漏吗? #include int *a; int main() { a = malloc(sizeof(int)*10); return
这两个声明有什么区别: char (*ptr)[N]; 对比 char ptr[][N]; 谢谢。 最佳答案 (1)声明 char (*ptr)[N]; ptr 是指向大小为 N 的字符数组的指针 下
data II = I Int Int deriving (Show) instance II Show where show I a b = show (a+b) showt.hs:3:2: s
我从 clojuredoc 中阅读了关于 condp 的文档。在文档中我找到了以下代码: (condp 一些 [1 2 3 4] #{0 6 7} :>> 公司 #{4 5 9} :>> 十二月 #{
我是一名优秀的程序员,十分优秀!