社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Redis

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

anveshtummala • 5 年前 • 886 次点击  

我正在将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
 
886 次点击  
文章 [ 1 ]  |  最新文章 5 年前
TheDude
Reply   •   1 楼
TheDude    6 年前

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