zoukankan      html  css  js  c++  java
  • 使用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;
    	} 
    

      

  • 相关阅读:
    PHP ftp_nb_continue() 函数
    PHP ftp_mkdir() 函数
    PHP ftp_mdtm() 函数
    普通索引和唯一索引,应该怎么选择
    [学习笔记]拉格朗日中值定理
    asp dotnet core 通过图片统计 csdn 用户访问
    WPF 使用 SharpDx 异步渲染
    WPF 使用 SharpDx 异步渲染
    win10 uwp 解决 SerialDevice.FromIdAsync 返回空
    win10 uwp 解决 SerialDevice.FromIdAsync 返回空
  • 原文地址:https://www.cnblogs.com/acme6/p/9609306.html
Copyright © 2011-2022 走看看