Kumar Thoma
Kumar Thoma

Reputation: 11

Using json vs string values in Redis

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.

{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))

Upvotes: 1

Views: 1184

Answers (1)

Lior Kogan
Lior Kogan

Reputation: 20658

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.

Upvotes: 4

Related Questions