Redisson整合Spring

这里只做一个简单的入门教程,不对之处还望指正。

对于Spring相关的概念这里不做赘述。

参照官方文档:

https://github.com/redisson/redisson/wiki/%E7%9B%AE%E5%BD%95

需要配置redisson:client,注意我这里存放在service层的springxml中

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:redisson="http://redisson.org/schema/redisson"
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-4.0.xsd
        http://www.springframework.org/schema/util
       http://www.springframework.org/schema/util/spring-util.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
         http://redisson.org/schema/redisson
       http://redisson.org/schema/redisson/redisson.xsd
        ">
    <context:component-scan base-package="com.rqb.*.service" />
    <!--redisson的实例 -->
    <redisson:client id="redissonClient2">
        <redisson:single-server address="127.0.0.1:6378"/>
    </redisson:client>
</beans>

配置Redisson引用类

package com.rqb.redisson.service;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * Created by baiguantao on 2017/4/18.
 * 这里写具体的功能
 */
@Service
public class RedissonUtils {
    @Autowired
    private RedissonClient redissonClient;
    public void getRedissonClient() throws IOException {
        Config config=((Redisson)redissonClient).getConfig();
        System.out.println(config.toJSON().toString());
    }
}

启动服务,调用改方法,打印结果

{"singleServerConfig":{"idleConnectionTimeout":10000,"pingTimeout":1000,"connectTimeout":10000,"timeout":3000,"retryAttempts":3,"retryInterval":1500,"reconnectionTimeout":3000,"failedAttempts":3,"subscriptionsPerConnection":5,"address":"redis://127.0.0.1:6378","subscriptionConnectionMinimumIdleSize":1,"subscriptionConnectionPoolSize":50,"connectionMinimumIdleSize":10,"connectionPoolSize":64,"database":0,"dnsMonitoring":false,"dnsMonitoringInterval":5000},"threads":0,"nettyThreads":0,"codec":{"class":"org.redisson.codec.JsonJacksonCodec"},"codecProvider":{"class":"org.redisson.codec.DefaultCodecProvider"},"resolverProvider":{"class":"org.redisson.liveobject.provider.DefaultResolverProvider"},"redissonReferenceEnabled":true,"useLinuxNativeEpoll":false}

demo文件下载:

http://pan.baidu.com/s/1miSamzm

 不懂的可以加群询问:244930845

posted @ 2017-04-18 17:07  石奈子0314  阅读(6986)  评论(0编辑  收藏  举报