Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting the "ReplyError: ERR unknown command JSON.SET" with Redis?

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?

like image 951
vuld0 Avatar asked Jan 24 '26 19:01

vuld0


2 Answers

There few potential causes:

#1 RedisJSON module is not installed. Try:

redis-cli info modules

Output should contain module:name=ReJSON,ver=... and you should be able to do the following in the redis-cli:

127.0.0.1:6379> json.set test_node $ '{ "node": "blah" }'
OK
127.0.0.1:6379> json.get test_node
"{\"node\":\"blah\"}"

#2 redis npm module is of an older version.

npm -v redis
8.1.4

try npm upgrade redis if yours is older.

The error looks like one, coming from the Redis server, so problem #1 is the most likely cause.

like image 151
Anton Avatar answered Jan 26 '26 13:01

Anton


You could also try with the redis-stack docker container

# Create a docker-compose.yaml placed in root dir with following description
# Then just run >> docker compose up

version: "3.9"
services:
  redis:
    image: "redis/redis-stack:edge"
    ports:
      - "6379:6379"
    environment:
      - "REDIS_ARGS=--appendonly yes"
    volumes:
      - ./data:/data
    deploy:
      replicas: 1
      restart_policy:
        condition: on-failure
like image 35
Helmer Barcos Avatar answered Jan 26 '26 14:01

Helmer Barcos