1

I need to read and write csv, rdb and json into redis using python. I'm considering using rejson for json support. The commands for rejson seem to be different when using rejson on json versus redis hashes for csv and rdb data.

Can I have only one set of code or do i need to condition it given the redis commands are different for json and rejson vs. hashes?

This code snippet shows how to use RedisJSON with raw Redis commands from Python with redis-py:

import redis
import json

data = {
    'foo': 'bar'
}

r = redis.StrictRedis()
r.execute_command('JSON.SET', 'doc', '.', json.dumps(data))
reply = json.loads(r.execute_command('JSON.GET', 'doc'))
Guy Korland
  • 9,139
  • 14
  • 59
  • 106
Reid K
  • 49
  • 6

1 Answers1

1

You'll need dedicated code paths for each data structure. Hashes and JSON use a different API (as do the rest of the data structures)

Itamar Haber
  • 47,336
  • 7
  • 91
  • 117