1

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

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

// 控制台日志 > first promise { ReplyError: ERR 新对象必须在根处创建 parseError (node_modules/redis-parser/lib/parser.js:193:12) at parseType (node_modules/redis-parser/lib/parser .js:303:14) 命令:'JSON.SET', args: ['jsonTest7', '.user.here.now', '{".nestedValue": "我是一个嵌套值"}'], 代码: 'ERR' } // 控制台日志 > 第二个承诺 // 控制台日志 > jsonTest7 响应:null

这是我的片段.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")

任何提示都会很棒,谢谢

4

1 回答 1

2

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

于 2019-03-03T20:31:06.613 回答