【redisTemplate为空 】 | IT修真院·坑乎
redisTemplate为空
我也踩过这个坑( 1 )
已统计您的踩坑,无需重复点击
回答(1)
详细描述
错误截图
编辑于2024-05-18
  • [上海|结业弟子]JAVA-吴振羽
    0

    这个肯定报错,你可以看一下opsForValue()这个方法返回的是一个接口

    public ValueOperations<K, V> opsForValue() {
    if (this.valueOps == null) {
    this.valueOps = new DefaultValueOperations(this);
       }

    return this.valueOps;
    }

    而在这个接口的实现类里的get()方法才用key从redis中获取value

    public V get(Object key) {
    return this.execute(new AbstractOperations<K, V>.ValueDeserializingRedisCallback(key) {
    protected byte[] inRedis(byte[] rawKey, RedisConnection connection) {
    return connection.get(rawKey);
           }
    }, true);
    }
    编辑于2019-08-27