skip to Main Content

No matter what I try, I keep getting this error message.

import redis

r = redis.Redis(host='127.0.0.1', port=6379)
r.ping() # -> True


r.json().set('test', '.', '{"foo": "bar"}')
# -> redis.exceptions.ResponseError: unknown command 'JSON.SET', with args beginning with: 'test' '.' '{"foo":"bar"}'

Code based on redis-py example

redis-py version: 5.0.7 (latest)

Docker image:

docker run -d --name redis-stack -p 6379:6379 redis/redis-stack:latest

Redis JSON module is enabled (redis-stack container)
docker-cli info modules:

module:name=RedisCompat,ver=1,api=1,filters=0,usedby=[],using=[],options=[]
module:name=search,ver=20814,api=1,filters=0,usedby=[],using=[ReJSON],options=[handle-io-errors]
module:name=timeseries,ver=11012,api=1,filters=0,usedby=[],using=[],options=[]
module:name=redisgears_2,ver=20023,api=1,filters=0,usedby=[],using=[],options=[]
module:name=ReJSON,ver=20610,api=1,filters=0,usedby=[search],using=[],options=[handle-io-errors]
module:name=bf,ver=20612,api=1,filters=0,usedby=[],using=[],options=[]

Setting via CLI is working:

127.0.0.1:6379> JSON.SET 'test' . '{"hello":"world"}'

Actually none of the commands work: JSON.SET, JSON.GET, FT.CREATE ….

Very strange…
Does anyone have any idea why this is not working?

2

Answers


  1. Chosen as BEST ANSWER

    After several attempts, I got it to work. Won't call it a solution, but a workaround. In fact, the previous instance was a simple Redis without any additional module. Simply deleting an image and starting a new image on the same port doesn't really seem to work. After new port mapping, everything works as expected.

    Running the container on new port solves the problem.

    docker run -d --name redis-stack -p 6389:6379 redis/redis-stack:latest
    

    ^ Changed local port to 6389

    However, I have no idea why everything worked as expected with redis-cli, but not with redis-py. Deleting of __pycache__ doesn't help.

    I hope this will help someone.


  2. I can reproduce the error on a Redis server (without modules). On a Redis Stack Server everything works fine. Review the instance running on the port used by the script.

    I get this on the simple Redis Server.

      File "/Users/mortensi/venvs/ps/lib/python3.9/site-packages/redis/connection.py", line 536, in read_response
        raise response
    redis.exceptions.ResponseError: unknown command 'JSON.SET', with args beginning with: 'test' '.' '"{"foo": "bar"}"'
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search