2

I'm trying to run the sample program from this RedisLabs page. I chose Option A - which was to set up the free Redis cloud server. (Seems like if you install manually, then you have to add the JSON as a plugin.) I'm able to connect and use other "set" commands, but getting error on JSON:

  File "C:\Users\nwalt\.virtualenvs\TDAmeritradeGetQuotes\lib\site-packages\redis\client.py", line 901, in execute_command
    return self.parse_response(conn, command_name, **options)
  File "C:\Users\nwalt\.virtualenvs\TDAmeritradeGetQuotes\lib\site-packages\redis\client.py", line 915, in parse_response
    response = connection.read_response()
  File "C:\Users\nwalt\.virtualenvs\TDAmeritradeGetQuotes\lib\site-packages\redis\connection.py", line 756, in read_response
    raise response
redis.exceptions.ResponseError: unknown command 'JSON.SET'

My Python test program (except put in the sample endpoint before posting):

    import redis
    import json
    import pprint
    
    host_info = "redis.us-east-1-1.ec2.cloud.redislabs.com"
    redisObj = redis.Redis(host=host_info, port=18274, password='xxx')
    
print ("Normal call to Redis")
redisObj.set('foo', 'bar')
value = redisObj.get('foo')
print(value)


capitals = {
     "Lebanon": "Beirut",
     "Norway": "Oslo",
     "France": "Paris"
 }
print ("capitals - before call to Redis")
pprint.pprint(capitals)


print("JSON call to Redis")
redisObj.execute_command('JSON.SET', 'doc', '.', json.dumps(capitals))
print("Data Saved, now fetch data back from redis")
reply = json.loads(redisObj.execute_command('JSON.GET', 'doc'))
print("reply from Redis get")
pprint.pprint(reply)

This is the screen shot from their website where I created the database. I didn't see any option to enable JSON or add any modules.

enter image description here

5
  • It seems like the RedisJSON module is not loaded in your DB. Commented Sep 27, 2020 at 8:55
  • But it's RedisLabs clouds, and they said that was one of the choices to use in the link provided in my question. Commented Sep 27, 2020 at 17:42
  • Correct, but you have to pick the RedisJSON module from the modules list when you create the DB Commented Sep 27, 2020 at 19:06
  • Option A here - redislabs.com/get-started-with-redis doesn't list any steps about adding the module. I put the screen shot into my question of how I created the DB. My impression is that the cloud hosted version came with that module. Commented Sep 27, 2020 at 21:27
  • Please check this page docs.redislabs.com/latest/modules/modules-quickstart Commented Sep 29, 2020 at 5:53

2 Answers 2

3

Not sure this was available when I created the REDIS database, but it is now. When you create it on redislabs.com, you can turn on the modules, and pick one from the list.

enter image description here

Then use this library: "rejson" from https://pypi.org/project/rejson/ to get the method "jsonset" method, using such code such as this:

rj = Client(host=config_dict['REDIS_CONFIG_HOST'], port=config_dict['REDIS_CONFIG_PORT'],                      password=config_dict['REDIS_CONFIG_PASSWORD'], decode_responses=True)

out_doc = {} 
out_doc['firstname'] = "John"
out_doc['lastname'] = "Doe"
rj.jsonset('config', Path.rootPath(), out_doc)
get_doc = rj.jsonget('config', Path.rootPath())
pprint.pprint(get_doc)
Sign up to request clarification or add additional context in comments.

1 Comment

Note that as of redis-py 4.0.0 the rejson library is deprecated...
3

I'm not used the cloud redis, in my local the Python don't load the JSON.SET I just so make done, in this sample https://onelinerhub.com/python-redis/save-json-to-redis

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.