/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ifish.config;

import com.ifish.util.IfishFilePath;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
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.core.StringRedisTemplate;

/**
 *
 * @author Administrator
 */
@Configuration
public class RedisConfig {

    @Bean
    public RedisConnectionFactory redisCF() {
        JedisConnectionFactory cf = new JedisConnectionFactory();

//        //获取当前操作系统(servers_os为服务器设置的属性JAVA_OPTS=%JAVA_OPTS% -Dservers_os=online84)
//        String servers_os = System.getProperty("servers_os") == null ? "" : System.getProperty("servers_os");
        if (IfishFilePath.link_img_head.contains("ifish7")) {
            //站点线上服务器 
            cf.setHostName("120.55.190.56");
            cf.setPort(3796);
            cf.setPassword("ifish7myredis");
        } else {
            //站点测试服务器  
            cf.setHostName("139.196.24.156");
            cf.setPort(3796);
            cf.setPassword("ifish7myredis");
//            FileUtil.writeLinesByLog("测试缓存连接");
        }

        return cf;
    }

    @Bean
    public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory cf) {
        RedisTemplate<String, String> redis = new RedisTemplate<String, String>();
        redis.setConnectionFactory(cf);
        return redis;
    }

    @Bean
    public StringRedisTemplate stringRedisTemplate(RedisConnectionFactory cf) {
        StringRedisTemplate redis = new StringRedisTemplate();
        redis.setConnectionFactory(cf);
        return redis;
    }
}
