redis

What is better in Redis, redundant data or read a bigger data object?


For some flows, I need to store an object like that in Redis:

ObjectA: {id: X, name: 'a', age: 'b', surname: 'c', city: 'abc', state: 'cdb'}

And in a specific flow that has a huge throughput (80 req/s and the system if critical, with a high impact in the critical flow), I just need to check if the ObjectA with the given id already exists in cache. So, I just need the id.

Considering the overhead to read and write more data, what is better?


Solution

  • I assume you store this value as a Redis string? You can use a JSON key instead and query just for the value of the id field.

    redis> JSON.SET ObjectA $ '{"id": "X", "name": "a", "age": "b", "surname": "c", "city": "abc", "state": "cdb"}'
    OK
    redis> JSON.GET ObjectA $.id
    "[\"X\"]"
    

    If your data is flat you can use a Hash as well.