我将 hashmap 缓存到 redis 并以下列方式读取特定的 hashkey:
var hashValue = redis.HashGet(rediskey, hashkey) // RedisCall#1
if (hashValue == null && !redis.KeyExist(rediskey)) // RedisCall#2
{
// load from sql and cache it to redis
}
else
{
return hashValue;
}
我试图避免我必须对 redis 进行两次调用。请就如何解决这个问题提出建议,并在一个 redis 调用中做到这一点。