Whenever we think of Cache, we think of Redis Cache unless you are exclusively working with an In-Memory cache. However, many a times, we continue to look at Redis as a store of Key-Value pair. That is a mistake!!
Imagine you have a situation where you have to keep information about members of a group and your app can support dynamic generation of group - how would you store it?
Option 1:
Keep it like a Key-Value pair. E.g.
Key: {GroupName}
Value: {MemberName1}{Delimiter}{MemberName2}{Delimiter}{MemberName3}....
Here delimiter can be of your choice like ",".
It will work fine for you. Redis documentation says that maximum size of a value can be 512MB.
However, now imagine you need to add and remove members from this value. You would end up writing code that will fetch the value, manipulate it and save it again. 2 trips to Redis and some CPU cycles.
Option 2:
Keep it in Set.
SetName: {GroupName}
You can simply add and remove items from it. There is even a single command to list all members of a set.
Now this is handy and faster than Option 1.
Similarly there are multiple advanced data structures built into Redis which can be leveraged in specific situations. Better to use it :).
Imagine you have a situation where you have to keep information about members of a group and your app can support dynamic generation of group - how would you store it?
Option 1:
Keep it like a Key-Value pair. E.g.
Key: {GroupName}
Value: {MemberName1}{Delimiter}{MemberName2}{Delimiter}{MemberName3}....
Here delimiter can be of your choice like ",".
It will work fine for you. Redis documentation says that maximum size of a value can be 512MB.
However, now imagine you need to add and remove members from this value. You would end up writing code that will fetch the value, manipulate it and save it again. 2 trips to Redis and some CPU cycles.
Option 2:
Keep it in Set.
SetName: {GroupName}
You can simply add and remove items from it. There is even a single command to list all members of a set.
Now this is handy and faster than Option 1.
Similarly there are multiple advanced data structures built into Redis which can be leveraged in specific situations. Better to use it :).