• 使用redis存放 map数据


    效果

    实现

    public class JedisPoolUtil {
    	
    	/**
    	 * 获取一个redis实例
    	 * @param jedisConnectionFactory
    	 * @return
    	 */
    	public static Jedis getJedis(JedisConnectionFactory jedisConnectionFactory){
    		JedisPoolConfig config = jedisConnectionFactory.getPoolConfig();
    		JedisPool jedisPool = new JedisPool(config,jedisConnectionFactory.getHostName(),jedisConnectionFactory.getPort());
    		
    		 Jedis jedis=null;
             try{
                 jedis=jedisPool.getResource();
             }catch(Exception e){
                 e.printStackTrace();
             }finally{
                 if(jedis!=null){
                     jedis.close();
                 }
                 if(jedisPool!=null){
                     jedisPool.close();
                 }
             }
             return jedis;
    	}
    	
    
    }
    

      

      <bean id="jedisConnectionFactory"
    		class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
    		destroy-method="destroy">
        <property name="hostName" value="${redis.conn.hostName}" />
        <property name="port" value="${redis.conn.port}" />
        <property name="timeout" value="${redis.conn.timeout}" />
        <property name="database" value="${redis.conn.database}" />
        <property name="password" value="${redis.conn.password}" />
        <property name="usePool" value="${redis.conn.usePool}" />
        <property name="poolConfig" ref="jedisPoolConfig" />
      </bean>
    
    zookeeper注入
    

      

    	@Override
    	public String getSiteCodeByName(String SiteNameShort) {
    		List<BaseSiteDis> baseSites = baseSiteDao.getFomfSite();
    		Jedis jedis = JedisPoolUtil.getJedis(jedisConnectionFactory);
    		for (int i = 0; i < baseSites.size(); i++) {
    			BaseSiteDis site = baseSites.get(i);
    			String siteNameShort = site.getSiteNameShort();
    			String siteStr = JSONObject.toJSONString(site);
    			Map<String, String> map = new HashedMap<>();
    			map.put(siteNameShort, siteStr);
    			jedis.hmset("FOMF.BASESITE", map);
    			jedis.expire("FOMF.BASESITE", 30);//设置时效实现 秒
    		}
    		return null;
    	} 
    

      

  • 相关阅读:
    React Native商城项目实战08
    React Native商城项目实战07
    React Native商城项目实战05
    React Native商城项目实战06
    React Native商城项目实战04
    React Native商城项目实战03
    React Native商城项目实战02
    单选框input:radio
    myDate97用法
    STRUTS2配置动态页面
  • 原文地址:https://www.cnblogs.com/acme6/p/9609306.html
Copyright © 2020-2023  润新知