當前位置: 首頁>>代碼示例>>Java>>正文


Java JedisConnectionFactory類代碼示例

本文整理匯總了Java中org.springframework.data.redis.connection.jedis.JedisConnectionFactory的典型用法代碼示例。如果您正苦於以下問題:Java JedisConnectionFactory類的具體用法?Java JedisConnectionFactory怎麽用?Java JedisConnectionFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JedisConnectionFactory類屬於org.springframework.data.redis.connection.jedis包,在下文中一共展示了JedisConnectionFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: buildRedisTemplate

import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; //導入依賴的package包/類
public static RedisTemplate buildRedisTemplate(byte[] redisProperties){
    JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(
            RedisConfUtils.getClusterConfiguration(
                    (RedisProperties) Serializer.INSTANCE.deserialize(redisProperties)));
    RedisTemplate<String, Long> redisTemplate = new RedisTemplate<>();
    redisTemplate.setConnectionFactory(jedisConnectionFactory);
    jedisConnectionFactory.afterPropertiesSet();

    GenericJackson2JsonRedisSerializer genericJackson2JsonRedisSerializer = new GenericJackson2JsonRedisSerializer();
    StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
    redisTemplate.setKeySerializer(stringRedisSerializer);
    redisTemplate.setValueSerializer(genericJackson2JsonRedisSerializer);
    redisTemplate.setHashKeySerializer(stringRedisSerializer);
    redisTemplate.setHashValueSerializer(genericJackson2JsonRedisSerializer);
    redisTemplate.afterPropertiesSet();
    return redisTemplate;
}
 
開發者ID:Paleozoic,項目名稱:storm_spring_boot_demo,代碼行數:18,代碼來源:RedisConfUtils.java

示例2: jedisConnConfig

import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; //導入依賴的package包/類
private void jedisConnConfig(final JedisConnectionFactory jedisConnectionFactory) {
    JedisPoolConfig poolConfig = new JedisPoolConfig();
    try {
        poolConfig.setMaxTotal(Integer.parseInt(REDIS_MAXTOTAL.getValue()));
        poolConfig.setMaxIdle(Integer.parseInt(REDIS_MAXIDLE.getValue()));
        poolConfig.setBlockWhenExhausted(true);
        if (!"".equals(REDIS_PASSWORD.getValue())) {
            jedisConnectionFactory.setPassword(REDIS_PASSWORD.getValue());
        }
        if (!"".equals(REDIS_DATABASE.getValue())) {
            jedisConnectionFactory.setDatabase(Integer.parseInt(REDIS_DATABASE.getValue()));
        }
        jedisConnectionFactory.setPoolConfig(poolConfig);
        jedisConnectionFactory.setUsePool(true);
        jedisConnectionFactory.setTimeout(Integer.parseInt(REDIS_TIMEOUT.getValue()));
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
}
 
開發者ID:globocom,項目名稱:groot,代碼行數:20,代碼來源:RedisConfiguration.java

示例3: createRedisConnection

import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; //導入依賴的package包/類
protected void createRedisConnection(String name, String host, int port, String password) {
	JedisConnectionFactory connectionFactory = new JedisConnectionFactory();
	connectionFactory.setHostName(host);
	connectionFactory.setPort(port);
	if(!StringUtils.isEmpty(password))
		connectionFactory.setPassword(password);
	connectionFactory.afterPropertiesSet();
	RedisTemplate redisTemplate = new MyStringRedisTemplate();
	redisTemplate.setConnectionFactory(connectionFactory);
	redisTemplate.afterPropertiesSet();
	RedisApplication.redisTemplatesMap.put(name, redisTemplate);
	
	Map<String, Object> redisServerMap = new HashMap<String, Object>();
	redisServerMap.put("name", name);
	redisServerMap.put("host", host);
	redisServerMap.put("port", port);
	redisServerMap.put("password", password);
	RedisApplication.redisServerCache.add(redisServerMap);
	
	initRedisKeysCache(redisTemplate, name);
	
	RedisZtreeUtil.initRedisNavigateZtree(name);
}
 
開發者ID:mauersu,項目名稱:redis-admin,代碼行數:24,代碼來源:RedisApplication.java

示例4: redisConnectionFactory

import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; //導入依賴的package包/類
@Bean
@RefreshScope
public RedisConnectionFactory redisConnectionFactory() {
    final RedisTicketRegistryProperties redis = casProperties.getTicket().getRegistry().getRedis();
    final JedisPoolConfig poolConfig = redis.getPool() != null ? jedisPoolConfig() : new JedisPoolConfig();

    final JedisConnectionFactory factory = new JedisConnectionFactory(poolConfig);
    factory.setHostName(redis.getHost());
    factory.setPort(redis.getPort());
    if (redis.getPassword() != null) {
        factory.setPassword(redis.getPassword());
    }
    factory.setDatabase(redis.getDatabase());
    if (redis.getTimeout() > 0) {
        factory.setTimeout(redis.getTimeout());
    }
    return factory;
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:19,代碼來源:RedisTicketRegistryConfiguration.java

示例5: afterPropertiesSet

import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; //導入依賴的package包/類
@Override
public void afterPropertiesSet() throws Exception {
    new Thread(() -> {
        while (true) {
            try {
                template.opsForValue().set("test", "configx");
                String value = template.opsForValue().get("test");

                JedisConnectionFactory connectionFactory = ((JedisConnectionFactory) template.getConnectionFactory());

                System.out.println("Redis: value=" + value + ", host=" + connectionFactory.getHostName() + ", port=" + connectionFactory.getPort());

                TimeUnit.SECONDS.sleep(5);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }).start();
}
 
開發者ID:zouzhirong,項目名稱:configx,代碼行數:20,代碼來源:RedisExample.java

示例6: afterPropertiesSet

import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; //導入依賴的package包/類
@Override
public void afterPropertiesSet() throws Exception {
    new Thread(() -> {
        while (true) {
            try {
                redisTemplate.opsForValue().set("test", "configx");
                String value = redisTemplate.opsForValue().get("test");

                JedisConnectionFactory connectionFactory = ((JedisConnectionFactory) redisTemplate.getConnectionFactory());

                System.out.println("Redis: value=" + value + ", host=" + connectionFactory.getHostName() + ", port=" + connectionFactory.getPort());

                TimeUnit.SECONDS.sleep(5);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }).start();
}
 
開發者ID:zouzhirong,項目名稱:configx,代碼行數:20,代碼來源:RedisExample.java

示例7: redisConnectionFactory

import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; //導入依賴的package包/類
@Bean
public RedisConnectionFactory redisConnectionFactory() {
    String default_host = "localhost";
    int port = 6379;
    String host = null;
    { // setup the host using the env vars
        host = System.getenv().get(SELDON_CLUSTER_MANAGER_REDIS_HOST_KEY);
        if (host == null) {
            logger.error(String.format("FAILED to find env var [%s]", SELDON_CLUSTER_MANAGER_REDIS_HOST_KEY));
            host = default_host;
        }
    }

    logger.info(String.format("setting up connection factory, host[%s] port[%d]", host, port));
    JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory();
    jedisConnectionFactory.setHostName(host);
    jedisConnectionFactory.setPort(port);
    jedisConnectionFactory.setPassword("");
    jedisConnectionFactory.setUsePool(true);
    jedisConnectionFactory.setPoolConfig(new JedisPoolConfig());
    return jedisConnectionFactory;
}
 
開發者ID:SeldonIO,項目名稱:seldon-core,代碼行數:23,代碼來源:RedisConfig.java

示例8: afterPropertiesSet

import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; //導入依賴的package包/類
@Override
public void afterPropertiesSet() throws Exception {
    int redisCount = Integer.parseInt(RedisProperties.getPropertie("redis.count").toString());
    factories = new ArrayList<JedisConnectionFactory>(redisCount);
    for (int i = 0; i < redisCount; i++) {
        int dbSize = 1;
        Object dbSizeObj = RedisProperties.getPropertie("redis.db.size" + i);
        if (dbSizeObj != null) {
            dbSize = Integer.valueOf(dbSizeObj.toString());
        }
        for (int j = 0; j < dbSize; j++) {
            JedisConnectionFactory factory = new JedisConnectionFactory(sentinelConfig,poolConfig);
            factory.setHostName(RedisProperties.getPropertie("redis.host" + i).toString());
            factory.setPort(Integer.parseInt(RedisProperties.getPropertie("redis.port" + i).toString()));
            factory.setPassword(RedisProperties.getPropertie("reids.passwd" + i).toString());
            factory.setTimeout(Integer.parseInt(RedisProperties.getPropertie("redis.timeout").toString()));
            factory.setDatabase(j);
            // 執行必要方法
            factory.afterPropertiesSet();
            factories.add(factory);
        }
    }
}
 
開發者ID:Fourwenwen,項目名稱:consistent-hashing-redis,代碼行數:24,代碼來源:HwRedisConnectionFactory.java

示例9: connectionFactory

import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; //導入依賴的package包/類
@Bean
public JedisConnectionFactory connectionFactory() {
  JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
  jedisPoolConfig.setMaxTotal(Integer.parseInt(env.getProperty(REDIS_POOL_MAX_ACTIVE)));
  jedisPoolConfig.setMaxIdle(Integer.parseInt(env.getProperty(REDIS_POOL_MAX_IDLE)));
  jedisPoolConfig.setMinIdle(Integer.parseInt(env.getProperty(REDIS_POOL_MIN_IDLE)));
  jedisPoolConfig.setMaxWaitMillis(Long.parseLong(env.getProperty(REDIS_POOL_MAX_WAIT)));
  jedisPoolConfig.setTestOnBorrow(true);
  jedisPoolConfig.setTestOnReturn(true);
  jedisPoolConfig.setTestWhileIdle(true);

  JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(jedisPoolConfig);
  jedisConnectionFactory.setUsePool(true);
  jedisConnectionFactory.setHostName(env.getProperty((REDIS_REMOTE_HOST)));
  return jedisConnectionFactory;
}
 
開發者ID:chuangxian,項目名稱:lib-edge,代碼行數:17,代碼來源:RedisSessionConfiguration.java

示例10: jedisConnectionFactory

import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; //導入依賴的package包/類
@Bean
JedisConnectionFactory jedisConnectionFactory() {
    JedisConnectionFactory factory = new JedisConnectionFactory();
    factory.setHostName(redisHost);
    factory.setPort(redisPort);
    factory.setUsePool(true);
    if(StringUtils.isNotBlank(password)) {
    	factory.setPassword(password);
    }
    JedisPoolConfig config = new JedisPoolConfig();
    if(maxIdle!=null) {
    	config.setMaxIdle(maxIdle);
    }
    factory.setPoolConfig(config);
    return factory;
}
 
開發者ID:panguixiang,項目名稱:my-spring-cache-redis,代碼行數:17,代碼來源:SpringConfig.java

示例11: configureConnectionFromUrl

import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; //導入依賴的package包/類
private void configureConnectionFromUrl(JedisConnectionFactory factory) {
	String url = this.properties.getUrl();
	if (url.startsWith("rediss://")) {
		factory.setUseSsl(true);
	}
	try {
		URI uri = new URI(url);
		factory.setHostName(uri.getHost());
		factory.setPort(uri.getPort());
		if (uri.getUserInfo() != null) {
			String password = uri.getUserInfo();
			int index = password.lastIndexOf(":");
			if (index >= 0) {
				password = password.substring(index + 1);
			}
			factory.setPassword(password);
		}
	}
	catch (URISyntaxException ex) {
		throw new IllegalArgumentException("Malformed 'spring.redis.url' " + url,
				ex);
	}
}
 
開發者ID:easycodebox,項目名稱:easycode,代碼行數:24,代碼來源:ShiroRedisAutoConfiguration.java

示例12: createJedisConnectionFactory

import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; //導入依賴的package包/類
/**
 * 建立
 * 
 * i=0, port(6379)
 * 
 * i=1, port(6379)+i=6380
 * 
 * @param i
 * @param jedisPoolConfig
 * @return
 */
protected JedisConnectionFactory createJedisConnectionFactory(int i, JedisPoolConfig jedisPoolConfig)
		throws Exception {
	JedisConnectionFactory result = new JedisConnectionFactory();
	String hostName = extendedProperties.getString(HOSTNAME, DEFAULT_HOSTNAME);
	//
	int port = extendedProperties.getInt(PORT, DEFAULT_PORT);
	port += i;
	LOGGER.info("redis[" + i + "]: " + hostName + ":" + port);
	//
	result.setHostName(hostName);
	result.setPort(port);
	//
	result.setPassword(extendedProperties.getString(PASSWORD, DEFAULT_PASSWORD));
	//
	result.setPoolConfig(jedisPoolConfig);
	result.afterPropertiesSet();
	//
	return result;
}
 
開發者ID:mixaceh,項目名稱:openyu-commons,代碼行數:31,代碼來源:JedisConnectionFactoryFactorySupporter.java

示例13: createJedisConnectionFactorys

import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; //導入依賴的package包/類
public JedisConnectionFactory[] createJedisConnectionFactorys(JedisPoolConfig[] jedisPoolConfigs) throws Exception {
	JedisConnectionFactory[] result = null;
	try {
		int size = jedisPoolConfigs.length;
		result = new JedisConnectionFactory[size];
		//
		for (int i = 0; i < size; i++) {
			JedisConnectionFactory jedisConnectionFactory = createJedisConnectionFactory(i,
					jedisPoolConfigs[i]);
			result[i] = jedisConnectionFactory;
		}

	} catch (Exception e) {
		LOGGER.error(new StringBuilder("Exception encountered during createJedisConnectionFactorys()").toString(),
				e);
		try {
			result = (JedisConnectionFactory[]) shutdownJedisConnectionFactorys();
		} catch (Exception sie) {
			throw sie;
		}
		throw e;
	}
	return result;
}
 
開發者ID:mixaceh,項目名稱:openyu-commons,代碼行數:25,代碼來源:JedisConnectionFactoryGroupFactoryBean.java

示例14: shutdownJedisConnectionFactorys

import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; //導入依賴的package包/類
/**
 * 關閉
 *
 * @return
 */
protected JedisConnectionFactory[] shutdownJedisConnectionFactorys() throws Exception {
	try {
		if (this.jedisConnectionFactorys != null) {
			for (int i = 0; i < this.jedisConnectionFactorys.length; i++) {
				JedisConnectionFactory oldInstance = this.jedisConnectionFactorys[i];
				// oldInstance.close();
				oldInstance.destroy();
				this.jedisConnectionFactorys[i] = null;
			}
			//
			this.jedisConnectionFactorys = null;
		}
	} catch (Exception e) {
		LOGGER.error(new StringBuilder("Exception encountered during shutdownJedisConnectionFactorys()").toString(),
				e);
		throw e;
	}
	return this.jedisConnectionFactorys;
}
 
開發者ID:mixaceh,項目名稱:openyu-commons,代碼行數:25,代碼來源:JedisConnectionFactoryGroupFactoryBean.java

示例15: shutdownJedisConnectionFactory

import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; //導入依賴的package包/類
/**
 * 關閉
 *
 * @return
 */
protected JedisConnectionFactory shutdownJedisConnectionFactory() throws Exception {
	try {
		if (this.jedisConnectionFactory != null) {
			JedisConnectionFactory oldInstance = this.jedisConnectionFactory;
			// oldInstance.close();
			oldInstance.destroy();
			//
			this.jedisConnectionFactory = null;
		}
	} catch (Exception e) {
		LOGGER.error(new StringBuilder("Exception encountered during shutdownJedisConnectionFactory()").toString(),
				e);
		throw e;
	}
	return this.jedisConnectionFactory;
}
 
開發者ID:mixaceh,項目名稱:openyu-commons,代碼行數:22,代碼來源:JedisConnectionFactoryFactoryBean.java


注:本文中的org.springframework.data.redis.connection.jedis.JedisConnectionFactory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。