REDIS REJSON系统地返回了两个错误:在非末端路径上缺少键,并且必须在root处创建新对象



第二个错误相对直视要理解。第一个更具挑战性。

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

//控制台日志>第一个Promise {ReplyError:Err New对象必须为 在根部创建 在Parseerror(node_modules/redis-parser/lib/parser.js:193:12) 在Parsetype(node_modules/redis-parser/lib/parser.js:303:14)命令:'json.set',args:['jsontest7', '.user.here.now', '{" .nestedValue":"我是一个嵌套值"}'],代码:'err'}//console log> second Promise//console log> jsontest7响应: null

在这里我的smippet.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.HORE.NOW')。必须像当前的代码示例一样将新密钥设置为root('。')级别。

最新更新