Py学习  »  Redis

如何在读取hashkey时避免多次redis调用

anveshtummala • 4 年前 • 682 次点击  

我正在将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调用。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/44293
 
682 次点击  
文章 [ 1 ]  |  最新文章 4 年前
TheDude
Reply   •   1 楼
TheDude    5 年前

你可以用 pipeline 而是在一个请求中执行这两个命令。