Redis rejson or string
Asked Answered
X

1

7

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.

Xantho answered 5/12, 2018 at 1:57 Comment(0)
I
5

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.

Izolaiztaccihuatl answered 5/12, 2018 at 1:59 Comment(3)
Thanks Cody. Makes sense to me.Xantho
How large are your JSON documents? You may find that if they are very large that compressing them and storing as byte[] may help your performance. Depends on your load obviously and the mix of writes vs.reads and how fast your gzip routine performs under your load. This is how our cache wrapper works.Zygotene
ReJSON author here - agreeing with Cody (at least with the current v1 ;)).Sartre

© 2022 - 2024 — McMap. All rights reserved.