I was trying to set JSON as value in Redis, and I am getting an error for the following code:
const createClient = require('redis');
async function redisJSONDemo () {
try {
const TEST_KEY = 'test_node';
const client = createClient.createClient();
await client.connect();
// RedisJSON uses JSON Path syntax. '.' is the root.
await client.json.set(TEST_KEY, '.', { node: 'blah' });
const value = await client.json.get(TEST_KEY, {
// JSON Path: .node = the element called 'node' at root level.
path: '.node'
});
console.log(`value of node: ${value}`);
await client.quit();
} catch (e) {
console.error(e);
}
}
redisJSONDemo();
Error:
ReplyError: ERR unknown command JSON.SET, with args beginning with: test_node, ., {"node":"blah"},
How can it be fixed?