1

I'm evaluating redis to understand between json vs string what provides better retrieval performance. As POC I set below json in redis as both json and string values and noticed that the size of JSON value is more than String - please see attached screen shots.

json value size = 239B string value size = 136B For this POC I used redis-stack-server on my mac.

Based on what I noticed, I have three questions.

  • Why size of JSON value is more than String
  • Why retrieval of JSON values is slower than String
  • What is the best alternate to Redis that could provide me better performance as caching layer for APIs
{key:"HbaJsv"location:339secret:"nD9pVeqZIxAIPsY"delta:6}

String values screenshot
Json values screenshot

This is a sample of the code I used.

import redis

client = redis.Redis(host='localhost', port=6677)
doc = {key:"HbaJsv"location:339secret:"nD9pVeqZIxAIPsY"delta:6}
client.json().set("some_hash1", '$', doc)
client.set("some_hash2", json.dumps(doc))

1 Answer 1

4

If you'd only like to retrieve JSONs by their key - you can use Strings.

But on Redis Stack you can also execute JSONpath queries over JSON documents, as well as index and query JSON documents.

Of course, to support such operations, Redis stores JSON documents differently than simple strings.

Sign up to request clarification or add additional context in comments.

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.