Search code examples
redisredisjson

Redis rejson or string


I am going to use Redis to store json documents that will have nested structure. My requirement is just to set and get the documents. I have no need to perform any json specific commands on the documents. Do I get any advantage by using rejson module. GET and SET commands will perform better than JSON.GET and JSON.SET commands. Following is from the redis documentation

JSON.SET Available since 1.0.0. Time complexity: O(M+N), where M is the size of the original value (if it exists) and N is the size of the new value.

JSON.GET Available since 1.0.0. Time complexity: O(N), where N is the size of the value.

GET key Available since 1.0.0. Time complexity: O(1)

SET key value [expiration EX seconds|PX milliseconds] [NX|XX] Available since 1.0.0. Time complexity: O(1)

Just want to confirm that storing the documents as string values is the right thing to do.


Solution

  • If you really don't need to query on your JSON values directly than storing JSON as raw strings will be cheaper to access as there will be no JSON parsing on read/write.