【问题标题】:How to avoid multiple redis calls while reading a hashkey读取hashkey时如何避免多次redis调用
【发布时间】:2019-07-05 03:53:02
【问题描述】:

我将 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 进行 2 次调用。请就如何解决这个问题提出建议,并在一个 redis 调用中做到这一点。

【问题讨论】:

    标签: performance caching optimization redis stackexchange.redis


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2021-10-16
      • 2014-08-22
      • 1970-01-01
      • 2020-01-09
      • 2018-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多