javascript - Redis ReJSON 系统地返回两个错误 : missing key at non-terminal path and new object must be created at root

标签 javascript node.js redis redisjson

第二个错误相对容易理解。 第一个更具挑战性。

我尝试了不同的组合来克服这个错误,但没有任何改善。 我的控制台返回给我:

// console log > first promise { ReplyError: ERR new objects must be created at the root at parseError (node_modules/redis-parser/lib/parser.js:193:12) at parseType (node_modules/redis-parser/lib/parser.js:303:14) command: 'JSON.SET', args: [ 'jsonTest7', '.user.here.now', '{".nestedValue": "I am a nested value"}' ], code: 'ERR' } // console log > second promise // console log > jsonTest7 response: null

这是我的 snippet.js:

const redis=require("redis"); 
rejson = require('redis-rejson');
const {promisify} = require('util'); 

rejson(redis); /* important - this must come BEFORE creating the client */
let client= redis.createClient({
    port:6380,
    host:'localhost', 
});  

const setAsync = promisify(client.json_set).bind(client);
const getAsync = promisify(client.json_get).bind(client);
const existsAsync= promisify(client.exists).bind(client);
client.exists('jsonTest2', function(err, reply) {
    if (reply === 1) {
        return true
    } else {
        return false
    }
});

async function isExist(object){ 
    var isExist= await existsAsync(object).then(data=> data)
        .catch((err) => console.error(err)); 
    console.log("isExist: ", typeof isExist)
    if(isExist !== 1) { 
        console.log("creating object...")
        await setAsync(object, '.', '{"here":"something"}');
        console.log("object created: " + object)
    } 
}
async function myFunc(object, rootKey) { 
    console.log("then 1")
    await isExist(object)
    await setAsync(object,  ".user.here.now", '{".nestedValue": "I am a nested value"}')
                .catch((err) => console.error(err));
    console.log("then 2")
    const res = await getAsync(object,  '.user.here.now')
                .catch((err) => console.error(err)); 
    console.log(object + " response: ", res) 

}
myFunc("jsonTest7")

任何提示都会很棒, 谢谢

最佳答案

第一个错误意味着您正在尝试创建一个新文档 - 即 RedisJSON 键不存在 - 但仅提供一个子文档(即“.​​user.here.now”)。新键必须设置为根(“.”)级别,如当前代码示例所示。

关于javascript - Redis ReJSON 系统地返回两个错误 : missing key at non-terminal path and new object must be created at root,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54972540/

相关文章:

javascript - Javascript 中的表单填写不起作用?

javascript - MVC : Javascript confirm for delete action not working

redis - 查找存在于两个 Redis 排序集中的最大(或最小)值

json - 关于在 Redis 中使用的最佳数据结构的建议?

c - 结构的前向声明而不使用它

javascript - 通过 Widget 将 ISO-Date 替换为 HTML 文档中的正常日期

javascript - 单击表格行以触发 javascript 和 .net 服务器端代码

node.js - 水线orientdb数据库连接超时

node.js - 使用 Node.js 导入/导出 MongoDB

javascript - 为什么 Chrome 会将引用类型为 Date 的对象的原型(prototype)视为 "Object {}",而不是 "Date {}"?