StringRedisTemplate支持交并补源码分析

在Redis集群环境下,某些命令如mset和集合的交并补运算不被支持。然而,使用SpringBoot整合Redis的集群模式,执行集合交并补操作时并未报错,返回结果正确。通过分析stringRedisTemplate的源码,特别是LettuceClusterSetCommands.java中的sInter方法,发现SpringBoot在客户端实现了集合运算,可能导致大量数据传输,增加客户端和服务器的压力。
摘要由CSDN通过智能技术生成

集群状态下,redis并不支持某些命令,如mset,集合的交并补运算等操作,但是springboot整合redis后并使用集群模式,发现在使用集合的交并补操作时并不会报错,且返回的结果符合预期:

@RunWith(SpringRunner.class)
@SpringBootTest
public class RedisClusterApplicationTests {
	
	@Autowired
	private StringRedisTemplate stringRedisTemplate;
	
	@Test
	public void mset() {
		Map<String,String> map = new HashMap<>();
		map.put("a", "a");
		map.put("b", "b");
		map.put("c", "c");
		map.put("d", "d");
		stringRedisTemplate.opsForValue().multiSet(map);
	} 
	@Test
	public void sinterTest() {
		stringRedisTemplate.opsForSet().add("set1", "a","b","c");
		stringRedisTemplate.opsForSet().add("set2", "a","b");
		Set<String> intersect = stringRedisTemplate.opsForSet().intersect("set1", "set2");
		System.out.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值