使用yml配置文件形式配置redis连接, 也可直接使用RedisTemplate默认配置,就可不用创建以下代码内容,只需编写yml文件即可。
至此就可以使用
RedisTemplate的自带API进行与redis的交互。
RedisClusterConf.java
package cn.com.xxx.config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.MapPropertySource;
import org.springframework.data.redis.connection.RedisClusterConfiguration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import redis.clients.jedis.JedisPoolConfig;
import java.util.HashMap;
import java.util.Map;
/**
* @description RedisConf 配置
* @author qijunyu
* @date 2017/11/15 10:59
*/
@Configuration
public class RedisClusterConf {
private static final Logger logger = LoggerFactory.getLogger(RedisClusterConf.class);
@Value("${redis.cluster.nodes}")
private String clusterNodes;
// Redis服务器地址
@Value("${redis.host}")
private String host;
// Redis服务器连接端口
@Value("${redis.port}")
private int
|