I have a map data to cache in redis cluster, such as:
{
"demoKey:{1}":{"key1":"value1"},
"demoKey:{2}":{"key2":"value2"},
"demoKey:{3}":{"key3":"value3"}
}
If using lua script
, I get RedisCommandExecutionException with accessing a non local key in a cluster node.
I know there is a way to tag {demokey}
to avoid the RedisCommandExecutionException with accessing a non local key, but it leads to all data cache in the same slot, is it a good way?
I can also use RedisTemplate
instance to cache data iteratively, but is it with high efficiency?
Appreciating for any help.
Both the answer of your questions depend on the application and use-cases.
... it leads to all data cache in the same slot, is it a good way?
If the number of data with same hashtag is small, say not more than a hundred, it should be fine.
But if the number is large, say hundreds of thousands or even more, it is unlikely to be a good idea. In that case,
... to cache data iteratively
is the option you may have to go for.