spring-data-redis的问题


spring的xml配置


 <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
        <property name="maxIdle" value="${redis.maxIdle}" />
        <property name="maxTotal" value="${redis.maxTotal}" />
        <property name="maxWaitMillis" value="${redis.maxWaitMillis}" />
        <property name="testOnBorrow" value="${redis.testOnBorrow}" />
    </bean>
<bean id="connectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
        p:host-name="127.0.0.1" p:port="6379" p:use-pool="true" p:pool-config-ref="poolConfig"/>

junit代码


 @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Resource(name="redisTemplate")
    private ValueOperations<String, String> ops;

    @Test
    public void testStringRedisTemple() {
        System.out.println(redisTemplate);
        System.out.println(ops);
        //这里报错
        ops.set("room", "622");
    }

图片描述

spring Redis java spring-data-redis

野生mio酱 9 years, 5 months ago

问了大神才知道是jedis版本太高了,spring-data-redis是1.5的版本,jedis是2.7.2的版本,jedis版本太高
错误在这:


 SEND_COMMAND = ReflectionUtils.findMethod(Connection.class, "sendCommand", new Class[] { Command.class,
                byte[][].class });
        ReflectionUtils.makeAccessible(SEND_COMMAND);

jedis 2.7.0 的connection类 :


 protected Connection sendCommand(final Command cmd, final byte[]... args)

而2.7.2版本以变:


 protected Connection sendCommand(final ProtocolCommand cmd, final byte[]... args)

所以SEND_COMMAND得到为null

love漫 answered 9 years, 5 months ago

Your Answer