1、概述
遍历key来一个一个发送命令更新,会发送多次网络请求,对性能有一定的影响。
2、方案
使用pipeline或者脚本。此文主要讲述使用lua脚本
redisTemplate.execute(RedisScript.of("local len = #KEYS; for i = 2, len do redis.call('hincrby', KEYS[1], KEYS[i], ARGV[i - 1]) end"),
Arrays.asList("hashKey", "k1", "k2"), 1, 2);