redis使用increment保存后,使用valueOps.get(key)获取报错

Blade 未结 4 1906
914254365
914254365 2021-05-27 11:02

一、该问题的重现步骤是什么?

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()

at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)

at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:687)

五、若有更多详细信息,请在下面提供。

4条回答
  •  914254365
    914254365 (楼主)
    2021-05-27 11:30

    我这样获取 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));
    }


提交回复