一、该问题的重现步骤是什么?
1.
.getRedisTemplate().execute(SessionCallback() { Object execute(RedisOperations redisOperations) DataAccessException { String likeKey = RedisKeyKit.(, ); String userLikeKey = RedisKeyKit.(); isMember = redisOperations.opsForSet().isMember(likeKey, ); redisOperations.multi(); (!isMember) { redisOperations.opsForSet().add(likeKey, ); redisOperations.opsForValue().increment(userLikeKey); } { redisOperations.opsForSet().remove(likeKey, ); redisOperations.opsForValue().decrement(userLikeKey); } redisOperations.exec(); } });
2.
String userLikeKey = RedisKeyKit.(userId); .getCounter(userLikeKey);
3.
二、你期待的结果是什么?实际看到的又是什么?
bladeRedis.getCounter(userLikeKey); 获取到正确得计数值
三、你正在使用的是什么产品,什么版本?在什么操作系统上?
2.8
四、请提供详细的错误堆栈信息,这很重要。
java.lang.RuntimeException: Truncated.
at io.protostuff.IOUtil.mergeFrom(IOUtil.java:50)
at io.protostuff.ProtostuffIOUtil.mergeFrom(ProtostuffIOUtil.java:104)
at org.springblade.core.redis.serializer.ProtoStuffSerializer.deserialize(ProtoStuffSerializer.java:59)
at org.springframework.data.redis.core.AbstractOperations.deserializeValue(AbstractOperations.java:335)
at org.springframework.data.redis.core.AbstractOperations$ValueDeserializingRedisCallback.doInRedis(AbstractOperations.java:61)
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:228)
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:188)
at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:96)
at org.springframework.data.redis.core.DefaultValueOperations.get(DefaultValueOperations.java:53)
at org.springblade.core.redis.cache.BladeRedis.getCounter(BladeRedis.java:280)
at vip.qichong.community.behavior.service.impl.LikesServiceImpl.userLikedCount(LikesServiceImpl.java:109)
at vip.qichong.community.behavior.service.impl.LikesServiceImpl$$FastClassBySpringCGLIB$$3ad7bb4b.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:687)
五、若有更多详细信息,请在下面提供。
获取设置缓存都用用同一个类要么你都用BladeRedis,要么你都用RedisTemplate,不然序列化方式不一致的。
我这样获取 bladeRedis.getRedisTemplate().opsForValue().increment(userLikeKey);设置值进去。 然后在Object obj = bladeRedis.getRedisTemplate().opsForValue().get(userLikeKey); 这样获取后还是报上面得错误
.execute(SessionCallback() { Object execute(RedisOperations redisOperations) DataAccessException { String likeKey = RedisKeyKit.(, ); String userLikeKey = RedisKeyKit.(); isMember = redisOperations.opsForSet().isMember(likeKey, ); redisOperations.multi(); (!isMember) { redisOperations.opsForSet().add(likeKey, ); redisOperations.opsForValue().increment(userLikeKey); } { redisOperations.opsForSet().remove(likeKey, ); redisOperations.opsForValue().decrement(userLikeKey); } redisOperations.exec(); } });
String userLikeKey = RedisKeyKit.(userId); Object obj = .opsForValue().get(userLikeKey); (Func.(obj)) { ; } { Long.(String.(obj)); }
increment 需要自己实例化 RedisTemplate<String, String> 来操作
bridataRedis.hIncrBy("test_key", "num", 0);
bridataRedis.hGetAll("test_key");
确实不行,会异常
扫一扫访问 Blade技术社区 移动端