0

我将 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 调用中做到这一点。

4

1 回答 1

0

您可以改用管道在一个请求中执行两个命令。

于 2019-02-11T17:05:40.533 回答