performance - 读取hashkey时如何避免多次redis调用
问题描述
我将 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 调用中做到这一点。
解决方案
您可以改用管道在一个请求中执行两个命令。
推荐阅读
- android - 如何修复“无法加载 AppCompat ActionBar 并出现未知错误”。对于 api 28?
- facebook - 如何在 Spring Boot 中获取 facebook oauth 访问代码?
- javascript - 如何对混淆为十六进制表示的 javascript 变量进行反混淆?
- cs-cart - cs购物车全局选项批量添加到类别中的产品
- ibm-midrange - IBM i - DDS 用于显示文件和物理文件
- oracle - 我可以在程序中一次创建具有不同名称的表吗
- r - R中的group_by错误“赋值目标扩展为非语言对象”
- c# - RestSharp 匹配 Curl 语法
- c# - 其他属性依赖于它的值的惰性 getter 属性的最佳方法
- javascript - 滚动时的粘性标题并在我向上滚动时显示