搜索
java - spring-data-redis的问题
PHPz
PHPz 2017-04-17 14:21:20
[Java讨论组]

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");
    }

PHPz
PHPz

学习是最好的投资!

全部回复(1)
伊谢尔伦

问了大神才知道是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

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号