zoukankan      html  css  js  c++  java
  • 常用代码1

    1.获取特定的日期格式

    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");  
    String datetime = sdf.format(new Date()); 
    String dateStr = datetime.substring(0, 7) ;
    String timeStr = datetime.substring(8) ;

    2.先从redis.properties文件读取redis的配置,然后通过手动创建Redis连接读取Redis中的配置

    Properties props = new Properties();
    ClassLoader loader = RedisConfigurer.class.getClassLoader();
    InputStream in = loader.getResourceAsStream("redis.properties");
    props.load(in);
    // 创建redis连接
    String host = props.getProperty("redis.host").trim();
    int port = Integer.parseInt(props.getProperty("redis.port").trim());
    String password = props.getProperty("redis.password");
    int database = Integer.parseInt(props.getProperty("redis.database"));
    Jedis jedis = null ;
    try{
          jedis =new Jedis(host, port);
    // 鉴权信息
    jedis.auth(password);
    jedis.select(database);
        
          Set<String> set = jedis.keys( prefix + ".*") ;
                
          Iterator<String> iterator = set.iterator() ;
          while(iterator.hasNext()){
                    String key = iterator.next() ;
                    String value = jedis.get(key) ;
                    LOGGER.debug("redis key=" + key + ",value=" + value);
                    props.put(key.substring(prefix.length()+1), value) ;
         }
    }catch(Exception e){
         e.printStackTrace();
    }finally{
         if(jedis != null){
              jedis.quit(); 
              jedis.close();
         }
    }
  • 相关阅读:
    Data Structure and Algorithm
    Data Structure and Algorithm
    Data Structure and Algorithm
    Data Structure and Algorithm
    Data Structure and Algorithm
    Data Structure and Algorithm
    Data Structure and Algorithm
    Data Structure and Algorithm
    Data Structure and Algorithm
    Data Structure and Algorithm
  • 原文地址:https://www.cnblogs.com/hzhuxin/p/8477331.html
Copyright © 2011-2022 走看看