第二个错误相对容易理解。 第一个更具挑战性。
我尝试了不同的组合来克服这个错误,但没有任何改善。 我的控制台返回给我:
// 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/