org.springframework.data.redis.connection.jedis.JedisConnectionFactory Java Examples

The following examples show how to use org.springframework.data.redis.connection.jedis.JedisConnectionFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RedisConfUtils.java    From storm_spring_boot_demo with MIT License 7 votes vote down vote up
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;
}
 
Example #2
Source File: RedisApplication.java    From redis-admin with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #3
Source File: RedisConfig.java    From charging_pile_cloud with MIT License 6 votes vote down vote up
@Bean
JedisConnectionFactory jedisConnectionFactory2() {
    RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration ();
    redisStandaloneConfiguration.setHostName(redisProperties.getHost());
    redisStandaloneConfiguration.setPort(redisProperties.getPort());
    redisStandaloneConfiguration.setPassword(RedisPassword.of(redisProperties.getPassword()));
    redisStandaloneConfiguration.setDatabase(RedisDbIndexConst.DB_INDEX_2);
    JedisClientConfiguration.JedisClientConfigurationBuilder jedisClientConfiguration = JedisClientConfiguration.builder();

    JedisConnectionFactory factory = new JedisConnectionFactory(redisStandaloneConfiguration,
            jedisClientConfiguration.usePooling().poolConfig(jedisPoolConfig()).build());
    return factory;
}
 
Example #4
Source File: RedisConfig.java    From demo-project with MIT License 6 votes vote down vote up
@Bean
public JedisConnectionFactory jedisConnectionFactory() {
    logger.info("jedisConnectionFactory:初始化了");
    JedisPoolConfig config = new JedisPoolConfig();
    config.setMaxIdle(maxIdle);
    config.setMinIdle(minIdle);
    config.setMaxWaitMillis(maxWaitMillis);
    config.setMaxTotal(maxActive);
    //链接耗尽时是否阻塞,默认true
    config.setBlockWhenExhausted(true);
    //是否启用pool的jmx管理功能,默认true
    config.setJmxEnabled(true);
    JedisConnectionFactory factory = new JedisConnectionFactory();
    factory.setPoolConfig(config);
    factory.setHostName(host);
    factory.setPort(port);
    factory.setPassword(password);
    factory.setDatabase(database);
    factory.setTimeout(timeout);
    return factory;
}
 
Example #5
Source File: RedisCacheFactory.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Override
protected RedisConnectionFactory createConnectionClient(String hostName, int port) {
	RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration();
	configuration.setHostName(hostName);
	configuration.setPort(port);
	if (JEDIS_AVAILABLE) {
		return new JedisConnectionFactory(configuration);
	}
	else if (LETTUCE_AVAILABLE) {
		return new LettuceConnectionFactory(configuration);
	}
	else {
		throw new IllegalArgumentException("No Jedis or lettuce client on classpath. "
				+ "Please add one of the implementation to your classpath");
	}
}
 
Example #6
Source File: RedisContextConfig.java    From onetwo with Apache License 2.0 5 votes vote down vote up
@Bean
  @OnMissingBean(JedisConnectionFactory.class)
  public JedisConnectionFactory securityRedisConnectionFactory() throws Exception {
int port = securityConfig.getRedis().getPort();
String hostName = securityConfig.getRedis().getHostName();
JedisConnectionFactory jf = new JedisConnectionFactory();
jf.setPort(port);
jf.setHostName(hostName);
SpringUtils.newBeanWrapper(jf).setPropertyValues(securityConfig.getRedis());
if(securityConfig.getRedis().getPool()!=null){
	jf.setPoolConfig(securityConfig.getRedis().getPool());
}
return jf;
  }
 
Example #7
Source File: JedisLockProviderIntegrationTest.java    From ShedLock with Apache License 2.0 5 votes vote down vote up
private static RedisConnectionFactory createJedisConnectionFactory() {
    JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory();
    jedisConnectionFactory.setHostName(HOST);
    jedisConnectionFactory.setPort(PORT);
    jedisConnectionFactory.afterPropertiesSet();
    return jedisConnectionFactory;
}
 
Example #8
Source File: RedisUtils.java    From onetwo with Apache License 2.0 5 votes vote down vote up
static public RedisTemplate<String, Object> createStringRedisTemplate(JedisConnectionFactory jedisConnectionFactory, boolean init) {
	RedisTemplate<String, Object> template = new RedisTemplate<>();
	template.setKeySerializer(new StringRedisSerializer());
	template.setHashKeySerializer(new StringRedisSerializer());
	template.setConnectionFactory(jedisConnectionFactory);
	if (init) {
		template.afterPropertiesSet();
	}
	return template;
}
 
Example #9
Source File: RedisLocalConfig.java    From bearchoke with Apache License 2.0 5 votes vote down vote up
@Bean
public RedisConnectionFactory redisConnectionFactory() throws Exception {
    JedisConnectionFactory jcf = new JedisConnectionFactory();
    jcf.setHostName(environment.getProperty("redis.hostname"));
    jcf.setPassword(environment.getProperty("redis.password"));
    jcf.setPort(environment.getProperty("redis.port", Integer.class));

    return jcf;
}
 
Example #10
Source File: RedisConfiguration.java    From onetwo with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnProperty(name=JFishRedisProperties.SERIALIZER_KEY, havingValue="jackson2", matchIfMissing=true)
public JsonRedisTemplate jsonRedisTemplate(@Autowired JedisConnectionFactory jedisConnectionFactory) throws Exception  {
	JsonRedisTemplate template = new JsonRedisTemplate();
	template.setConnectionFactory(jedisConnectionFactory);
	return template;
}
 
Example #11
Source File: RedisConfiguration.java    From onetwo with Apache License 2.0 5 votes vote down vote up
/***
	 * 和StringRedisSerializer不同,只有key使用string
	 * @author wayshall
	 * @param jedisConnectionFactory
	 * @return
	 * @throws Exception
	 */
	@Bean
//	@ConditionalOnMissingBean(name="stringKeyRedisTemplate")
	@ConditionalOnProperty(name=JFishRedisProperties.SERIALIZER_KEY, havingValue="stringKey", matchIfMissing=false)
//	@ConditionalOnProperty(name=JFishRedisProperties.ENABLED_KEY, havingValue="true")
	public RedisTemplate<String, Object> stringKeyRedisTemplate(@Autowired JedisConnectionFactory jedisConnectionFactory) throws Exception  {
		RedisTemplate<String, Object> template = RedisUtils.createStringRedisTemplate(jedisConnectionFactory, false);
		return template;
	}
 
Example #12
Source File: RedisConfig.java    From konker-platform with Apache License 2.0 5 votes vote down vote up
@Bean
public RedisConnectionFactory redisConnectionFactory() {
    JedisConnectionFactory cf = new JedisConnectionFactory();
    cf.setHostName(getHost());
    cf.setPort(getPort());
    cf.afterPropertiesSet();
    return cf;
}
 
Example #13
Source File: EmailEmbeddedRedisConfigurationTest.java    From spring-boot-email-tools with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldEmailEmbeddedRedisConfigurationBeCreated() throws Exception {
    //Arrange
    int port = 6381;
    List<String> settings = ImmutableList.of("appendfilename email_appendonly.aof",
            "save 900 1");

    //Act
    EmailEmbeddedRedisConfiguration emailEmbeddedRedisConfiguration = new EmailEmbeddedRedisConfiguration(port, settings);

    //Assert
    assertions.assertThat(emailEmbeddedRedisConfiguration.emailEmbeddedRedis())
            .isNotNull();
    assertions.assertThat(emailEmbeddedRedisConfiguration.redisConnectionFactory())
            .isNotNull()
            .isInstanceOf(JedisConnectionFactory.class);


    //Act
    TimeUnit.SECONDS.sleep(3);
    emailEmbeddedRedisConfiguration.preDestroy();

    TimeUnit.SECONDS.sleep(1);
    //Assert
    assertions.assertThat(emailEmbeddedRedisConfiguration.emailEmbeddedRedis().isActive()).isFalse();

    exportException.expect(RedisConnectionFailureException.class);
    emailEmbeddedRedisConfiguration.redisConnectionFactory().getConnection();
}
 
Example #14
Source File: ApplicationConfig.java    From docker-kubernetes-by-example-java with Apache License 2.0 5 votes vote down vote up
@Bean
JedisConnectionFactory jedisConnectionFactory() throws URISyntaxException {
  URI uri = new URI(redisEndpoint);
  JedisConnectionFactory factory = new JedisConnectionFactory();
  factory.setHostName(uri.getHost());
  factory.setPort(uri.getPort());

  return factory;
}
 
Example #15
Source File: HomeController.java    From hello-spring-cloud with Apache License 2.0 5 votes vote down vote up
private String toString(RedisConnectionFactory redisConnectionFactory) {
    if (redisConnectionFactory == null) {
        return "<none>";
    } else {
        if (redisConnectionFactory instanceof JedisConnectionFactory) {
            JedisConnectionFactory jcf = (JedisConnectionFactory) redisConnectionFactory;
            return jcf.getHostName().toString() + ":" + jcf.getPort();
        } else if (redisConnectionFactory instanceof LettuceConnectionFactory) {
            LettuceConnectionFactory lcf = (LettuceConnectionFactory) redisConnectionFactory;
            return lcf.getHostName().toString() + ":" + lcf.getPort();
        }
        return "<unknown> " + redisConnectionFactory.getClass();
    }
}
 
Example #16
Source File: RedisConfiguration.java    From spring-boot-with-multi-redis with MIT License 5 votes vote down vote up
@Primary
@Bean(name = "userRedisConnectionFactory")
public RedisConnectionFactory userRedisConnectionFactory() {
    JedisConnectionFactory redisConnectionFactory = new JedisConnectionFactory();
    redisConnectionFactory.setHostName(userRedisProperty.getHost());
    redisConnectionFactory.setPort(userRedisProperty.getPort());
    redisConnectionFactory.setDatabase(userRedisProperty.getDatabase());
    return redisConnectionFactory;
}
 
Example #17
Source File: RedisConfiguration.java    From spring-boot-with-multi-redis with MIT License 5 votes vote down vote up
@Bean(name = "roleRedisConnectionFactory")
public RedisConnectionFactory roleRedisConnectionFactory() {
    JedisConnectionFactory redisConnectionFactory = new JedisConnectionFactory();
    redisConnectionFactory.setHostName(roleRedisProperty.getHost());
    redisConnectionFactory.setPort(roleRedisProperty.getPort());
    redisConnectionFactory.setDatabase(roleRedisProperty.getDatabase());
    return redisConnectionFactory;
}
 
Example #18
Source File: RedisConfig.java    From hot-crawler with MIT License 5 votes vote down vote up
@Bean
JedisConnectionFactory jedisConnectionFactory()
{
    RedisProperties properties = redisProperties();
    RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration();
    configuration.setHostName(properties.getHost());
    configuration.setPort(properties.getPort());
    configuration.setPassword(properties.getPassword());
    configuration.setDatabase(properties.getDatabase());
    return new JedisConnectionFactory(configuration);
}
 
Example #19
Source File: RedisCacheConfig.java    From konker-platform with Apache License 2.0 5 votes vote down vote up
@Bean
public JedisConnectionFactory jedisConnectionFactory() {
    JedisConnectionFactory factory = new JedisConnectionFactory();
    factory.setHostName(host);
    factory.setPort(port);
    return factory;
}
 
Example #20
Source File: SecurityConfig.java    From vics with MIT License 5 votes vote down vote up
@Bean
public JedisConnectionFactory connectionFactory(Environment env) {
    String host = env.getProperty("spring.redis.host", "localhost");
    JedisConnectionFactory jedis = new JedisConnectionFactory();
    jedis.setHostName(host);
    return jedis;
}
 
Example #21
Source File: RedisConfig.java    From sds with Apache License 2.0 5 votes vote down vote up
@Bean
@ConfigurationProperties(prefix = "spring.redis")
public JedisConnectionFactory getConnectionFactory() {
    JedisConnectionFactory factory = new JedisConnectionFactory();
    JedisPoolConfig config = getRedisConfig();
    factory.setPoolConfig(config);
    logger.info("JedisConnectionFactory bean init success.");
    return factory;
}
 
Example #22
Source File: CacheService.java    From springboot-learn with MIT License 5 votes vote down vote up
/**
 * redis 数据库连接池
 *
 * @return
 */

@Bean
public JedisConnectionFactory redisConnectionFactory() {
    JedisConnectionFactory factory = new JedisConnectionFactory();
    factory.setHostName(redisConn.getHost());
    factory.setPort(redisConn.getPort());
    factory.setPassword(redisConn.getPassword());
    factory.setTimeout(redisConn.getTimeout()); // 设置连接超时时间
    factory.setDatabase(redisConn.getDatabase());
    return factory;
}
 
Example #23
Source File: RedisConfig.java    From spring-boot-start-current with Apache License 2.0 5 votes vote down vote up
@Bean
  public RedisConnectionFactory redisConnectionFactory () {
RedisStandaloneConfiguration standaloneConfig = new RedisStandaloneConfiguration(  );
standaloneConfig.setHostName( host );
standaloneConfig.setPort( port );
standaloneConfig.setPassword( RedisPassword.of( password ) );
standaloneConfig.setDatabase( database );
      return new JedisConnectionFactory(standaloneConfig);
  }
 
Example #24
Source File: RedisConfig.java    From Resource with GNU General Public License v3.0 5 votes vote down vote up
@Bean
public RedisConnectionFactory redisConnectionFactory()
{
    JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
    JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory();
    jedisConnectionFactory.setHostName(env.getProperty("redis.host").trim());
    jedisConnectionFactory.setPort(Integer.parseInt(env.getProperty("redis.port").trim()));
    jedisConnectionFactory.setPassword(env.getProperty("redis.password").trim());
    jedisConnectionFactory.setDatabase(Integer.parseInt(env.getProperty("redis.database").trim()));
    jedisConnectionFactory.setUsePool(true);
    jedisConnectionFactory.setPoolConfig(jedisPoolConfig);
    return jedisConnectionFactory;
}
 
Example #25
Source File: BootmonServerRedisConfig.java    From boot-mon with Apache License 2.0 5 votes vote down vote up
@Bean
JedisConnectionFactory jedisConnectionFactory() {
    JedisConnectionFactory jedisConFactory = new JedisConnectionFactory();
    jedisConFactory.setHostName(host);
    jedisConFactory.setPort(port);
    return jedisConFactory;
}
 
Example #26
Source File: SessionConfig.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
@Primary
public JedisConnectionFactory connectionFactory() {
    JedisConnectionFactory factory = new JedisConnectionFactory();
    factory.setHostName(properties.getProperty("spring.redis.host","localhost"));
    factory.setPort(properties.getProperty("spring.redis.port", Integer.TYPE,6379));
    factory.afterPropertiesSet();
    factory.setUsePool(true);
    return factory;
}
 
Example #27
Source File: RedisConfig.java    From tx-lcn with Apache License 2.0 5 votes vote down vote up
@Bean
@ConfigurationProperties(prefix = "spring.redis")
public JedisConnectionFactory getConnectionFactory() {
    JedisConnectionFactory factory = new JedisConnectionFactory();
    JedisPoolConfig config = getRedisConfig();
    factory.setPoolConfig(config);
    logger.info("JedisConnectionFactory bean init success.");
    return factory;
}
 
Example #28
Source File: RedisConfig.java    From demo-project with MIT License 5 votes vote down vote up
/**
 * 设置缓存管理器,这里可以配置默认过期时间等
 *
 * @param connectionFactory 连接池
 * @return
 */
@Bean
public CacheManager cacheManager(JedisConnectionFactory jedisConnectionFactory) {
    RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration
            .defaultCacheConfig()
            .entryTtl(Duration.ofSeconds(60));
    RedisCacheWriter redisCacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(jedisConnectionFactory);
    RedisCacheManager manager = new RedisCacheManager(redisCacheWriter, redisCacheConfiguration);
    return manager;
}
 
Example #29
Source File: RedisConfiguration.java    From WTFDYUM with Apache License 2.0 5 votes vote down vote up
@Bean
public RedisConnectionFactory redisConnectionFactory() {
    final JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory();
    jedisConnectionFactory.setHostName(env.getProperty("wtfdyum.redis.server"));
    jedisConnectionFactory.setPort(env.getProperty("wtfdyum.redis.port", Integer.class));
    jedisConnectionFactory.setDatabase(env.getProperty("wtfdyum.redis.database", Integer.class));
    return jedisConnectionFactory;
}
 
Example #30
Source File: RedisConfiguration.java    From heimdall with Apache License 2.0 5 votes vote down vote up
/**
 * Configures and returns a {@link JedisConnectionFactory}.
 * 
 * @return {@link JedisConnectionFactory}
 */
@Bean
public JedisConnectionFactory jedisConnectionFactory() {
     
     JedisConnectionFactory factory = new JedisConnectionFactory();
     
     factory.setHostName(property.getRedis().getHost());
     factory.setPort(property.getRedis().getPort());
     factory.setUsePool(true);
     factory.setPoolConfig(jediPoolConfig());
     return factory;
}