田源
2024-03-07 4b4083fd73dc27ece42f4835483565eef0e4f608
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.vci.server.cache.redis;
 
import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;
import com.vci.common.log.ServerWithLog4j;
 
/**
 * 读取redis配置
 * 
 * @author zhengzhiyuan
 * @since May 20, 2016
 */
public final class RedisConfig {
    private static final String DEFAULT_REDIS_PROPERTIES = "properties/redis.properties";
    private static Properties redisProperties = null;
    
//    private static final String DEFAULT_REDIS_PROPERTIES = "redis.properties";
//    private static ResourceBundle REDIS_CONFIG = ResourceBundle.getBundle(DEFAULT_REDIS_PROPERTIES);
 
    static {
        try {
            File file = new File(DEFAULT_REDIS_PROPERTIES);
            
            ServerWithLog4j.logger.debug("初始化Redis配置文件");
            
            if (file.exists()) {
                FileInputStream confPropertiesStream = new FileInputStream(DEFAULT_REDIS_PROPERTIES);
                redisProperties = new Properties();
                redisProperties.load(confPropertiesStream);
            }
        } catch(Exception ee) {
            ee.printStackTrace();
            ServerWithLog4j.logger.info("初始化Redis配置文件出错,请检查文件后重新启动");
        }
    }
    
    public static String getConfigProperty(String key) {
        return redisProperties.getProperty(key);
    }
}