当前位置: 首页>>代码示例>>Java>>正文


Java RedisConnectionFactory类代码示例

本文整理汇总了Java中org.springframework.data.redis.connection.RedisConnectionFactory的典型用法代码示例。如果您正苦于以下问题:Java RedisConnectionFactory类的具体用法?Java RedisConnectionFactory怎么用?Java RedisConnectionFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RedisConnectionFactory类属于org.springframework.data.redis.connection包,在下文中一共展示了RedisConnectionFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: redisTemplate

import org.springframework.data.redis.connection.RedisConnectionFactory; //导入依赖的package包/类
@Bean(name="redisTemplate")
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {

    RedisTemplate<String, String> template = new RedisTemplate<>();


    RedisSerializer<String> redisSerializer = new StringRedisSerializer();

    Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
    ObjectMapper om = new ObjectMapper();
    om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
    om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
    jackson2JsonRedisSerializer.setObjectMapper(om);

    template.setConnectionFactory(factory);
    //key序列化方式
    template.setKeySerializer(redisSerializer);
    //value序列化
    template.setValueSerializer(jackson2JsonRedisSerializer);
    //value hashmap序列化
    template.setHashValueSerializer(jackson2JsonRedisSerializer);

    return template;
}
 
开发者ID:cwenao,项目名称:springboot_cwenao,代码行数:25,代码来源:RedisConfig.java

示例2: redisTemplate

import org.springframework.data.redis.connection.RedisConnectionFactory; //导入依赖的package包/类
@Bean
@Primary
RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory rcf) {
	AitLogger.debug(logger, "Serializer overriding ");

	RedisTemplate<String, Object> template = new RedisTemplate<>();
	template.setConnectionFactory(rcf);

	GenericJackson2JsonRedisSerializer valSerializer = new GenericJackson2JsonRedisSerializer();

	template.setValueSerializer(valSerializer);
	template.setKeySerializer(new RedisSerializer<Object>() {

		@Override
		public byte[] serialize(Object t) throws SerializationException {
			return (t == null ? null : (":" + t.toString()).getBytes());
		}

		@Override
		public Object deserialize(byte[] bytes) throws SerializationException {
			return (bytes == null ? null : new String(bytes));
		}
	});
	template.setHashValueSerializer(valSerializer);
	return template;
}
 
开发者ID:allianzit,项目名称:ait-platform,代码行数:27,代码来源:AitCacheConfigBase.java

示例3: testParentConnectionFactoryInheritedByDefault

import org.springframework.data.redis.connection.RedisConnectionFactory; //导入依赖的package包/类
@Test
public void testParentConnectionFactoryInheritedByDefault() {
	context = SpringApplication.run(SimpleProcessor.class, "--server.port=0");
	BinderFactory<?> binderFactory = context.getBean(BinderFactory.class);
	Binder binder = binderFactory.getBinder(null);
	assertThat(binder, instanceOf(RedisMessageChannelBinder.class));
	DirectFieldAccessor binderFieldAccessor = new DirectFieldAccessor(binder);
	RedisConnectionFactory binderConnectionFactory =
			(RedisConnectionFactory) binderFieldAccessor.getPropertyValue("connectionFactory");
	assertThat(binderConnectionFactory, instanceOf(RedisConnectionFactory.class));
	RedisConnectionFactory connectionFactory = context.getBean(RedisConnectionFactory.class);
	assertThat(binderConnectionFactory, is(connectionFactory));
	CompositeHealthIndicator bindersHealthIndicator =
			context.getBean("bindersHealthIndicator", CompositeHealthIndicator.class);
	assertNotNull(bindersHealthIndicator);
	DirectFieldAccessor directFieldAccessor = new DirectFieldAccessor(bindersHealthIndicator);
	@SuppressWarnings("unchecked")
	Map<String,HealthIndicator> healthIndicators =
			(Map<String, HealthIndicator>) directFieldAccessor.getPropertyValue("indicators");
	assertThat(healthIndicators, hasKey("redis"));
	assertThat(healthIndicators.get("redis").health().getStatus(), equalTo(Status.UP));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-redis,代码行数:23,代码来源:RedisBinderModuleTests.java

示例4: redisConnectionFactory

import org.springframework.data.redis.connection.RedisConnectionFactory; //导入依赖的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: redisTemplate

import org.springframework.data.redis.connection.RedisConnectionFactory; //导入依赖的package包/类
/**
 * RedisTemplate配置
 * @param factory
 * @return
 */
@Bean
@SuppressWarnings({"rawtypes", "unchecked"})
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
    StringRedisTemplate template = new StringRedisTemplate(factory);
    //定义value的序列化方式
    Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
    ObjectMapper om = new ObjectMapper();
    om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
    om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
    jackson2JsonRedisSerializer.setObjectMapper(om);
    
    template.setValueSerializer(jackson2JsonRedisSerializer);
    template.setHashValueSerializer(jackson2JsonRedisSerializer);
    template.afterPropertiesSet();
    return template;
}
 
开发者ID:SnailFastGo,项目名称:springboot_op,代码行数:22,代码来源:RedisConfiguration.java

示例6: redisTemplate

import org.springframework.data.redis.connection.RedisConnectionFactory; //导入依赖的package包/类
@Bean("redisTemplate")  //新家的这个注解 10-26 12:06
@SuppressWarnings({ "rawtypes", "unchecked" })
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory redisFactory){
	StringRedisTemplate template = new StringRedisTemplate(redisFactory);
	Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new 
			Jackson2JsonRedisSerializer(Object.class);
	
	ObjectMapper om = new ObjectMapper();
	om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
	om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
	jackson2JsonRedisSerializer.setObjectMapper(om);
	
	template.setValueSerializer(jackson2JsonRedisSerializer);
	template.afterPropertiesSet();
	return template;
}
 
开发者ID:duanyaxin,项目名称:springboot-smart,代码行数:17,代码来源:RedisConfiguration.java

示例7: redisTemplate

import org.springframework.data.redis.connection.RedisConnectionFactory; //导入依赖的package包/类
@Bean
public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
    RedisTemplate<Object, Object> template = new RedisTemplate<>();
    template.setConnectionFactory(connectionFactory);

    //使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值
    Jackson2JsonRedisSerializer serializer = new Jackson2JsonRedisSerializer(Object.class);

    ObjectMapper mapper = new ObjectMapper();
    mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
    mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
    serializer.setObjectMapper(mapper);

    template.setValueSerializer(serializer);
    //使用StringRedisSerializer来序列化和反序列化redis的key值
    template.setKeySerializer(new StringRedisSerializer());
    template.afterPropertiesSet();
    return template;
}
 
开发者ID:fanqinghui,项目名称:action,代码行数:20,代码来源:RedisUtil.java

示例8: redisConnectionFactory

import org.springframework.data.redis.connection.RedisConnectionFactory; //导入依赖的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

示例9: redisTemplate

import org.springframework.data.redis.connection.RedisConnectionFactory; //导入依赖的package包/类
@Bean(name = "redisTemplate")
public RedisTemplate<String,?> redisTemplate(@Qualifier("mafConnectionFactory") RedisConnectionFactory factory) {
    RedisTemplate<String,?> template = new RedisTemplate<>();
    template.setConnectionFactory(factory);
    template.setKeySerializer(new StringRedisSerializer());
    template.afterPropertiesSet();
    return template;
}
 
开发者ID:slking1987,项目名称:mafia,代码行数:9,代码来源:RedisConfig.java

示例10: setUp

import org.springframework.data.redis.connection.RedisConnectionFactory; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
   RedisConnectionFactory connectionFactory = TestRedis.connectionFactory();

   WorkerDaoImpl workerDao = new WorkerDaoImpl();
   workerDao.setConnectionFactory(connectionFactory);
   workerDao.setNamespace("test");
   workerDao.afterPropertiesSet();

   FifoDaoImpl fifoDao = new FifoDaoImpl();
   fifoDao.setConnectionFactory(connectionFactory);
   fifoDao.setNamespace("test");
   fifoDao.setExecutions(new TestExecutionRedisSerializer(TestJob.class));
   fifoDao.afterPropertiesSet();

   FifoWorkerFactoryBean factory = new FifoWorkerFactoryBean();
   factory.setWorkerDao(workerDao);
   factory.setFifoDao(fifoDao);
   factory.setQueues("test-queue");
   factory.setJobRunnerFactory(new TestJobRunnerFactory());
   factory.setApplicationEventPublisher(eventBus);
   factory.afterPropertiesSet();

   worker = factory.getObject();
   this.fifoDao = worker.getFifoDao();
}
 
开发者ID:shopping24,项目名称:redjob,代码行数:27,代码来源:FifoWorkerImplIT.java

示例11: RedisMessageChannelBinder

import org.springframework.data.redis.connection.RedisConnectionFactory; //导入依赖的package包/类
public RedisMessageChannelBinder(RedisConnectionFactory connectionFactory, String... headersToMap) {
	Assert.notNull(connectionFactory, "connectionFactory must not be null");
	this.connectionFactory = connectionFactory;
	StringRedisTemplate template = new StringRedisTemplate(connectionFactory);
	template.afterPropertiesSet();
	this.redisOperations = template;
	if (headersToMap != null && headersToMap.length > 0) {
		String[] combinedHeadersToMap =
				Arrays.copyOfRange(BinderHeaders.STANDARD_HEADERS, 0, BinderHeaders.STANDARD_HEADERS.length
						+ headersToMap.length);
		System.arraycopy(headersToMap, 0, combinedHeadersToMap, BinderHeaders.STANDARD_HEADERS.length,
				headersToMap.length);
		this.headersToMap = combinedHeadersToMap;
	}
	else {
		this.headersToMap = BinderHeaders.STANDARD_HEADERS;
	}
	this.errorAdapter = new RedisQueueOutboundChannelAdapter(
			parser.parseExpression("headers['" + ERROR_HEADER + "']"), connectionFactory);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-redis,代码行数:21,代码来源:RedisMessageChannelBinder.java

示例12: RedisTestBinder

import org.springframework.data.redis.connection.RedisConnectionFactory; //导入依赖的package包/类
public RedisTestBinder(RedisConnectionFactory connectionFactory) {
	RedisMessageChannelBinder binder = new RedisMessageChannelBinder(connectionFactory);
	GenericApplicationContext context = new GenericApplicationContext();
	context.getBeanFactory().registerSingleton(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME,
			new DefaultMessageBuilderFactory());
	DefaultHeaderChannelRegistry channelRegistry = new DefaultHeaderChannelRegistry();
	channelRegistry.setReaperDelay(Long.MAX_VALUE);
	ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
	taskScheduler.afterPropertiesSet();
	channelRegistry.setTaskScheduler(taskScheduler);
	context.getBeanFactory().registerSingleton(
			IntegrationContextUtils.INTEGRATION_HEADER_CHANNEL_REGISTRY_BEAN_NAME,
			channelRegistry);
	context.refresh();
	binder.setApplicationContext(context);
	binder.setCodec(new PojoCodec());
	setBinder(binder);
	template = new StringRedisTemplate(connectionFactory);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-redis,代码行数:20,代码来源:RedisTestBinder.java

示例13: redisTemplate

import org.springframework.data.redis.connection.RedisConnectionFactory; //导入依赖的package包/类
@Bean
public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory factory) throws UnknownHostException {
	RedisTemplate<Object, Object> template = new RedisTemplate<>();
	template.setConnectionFactory(factory);

	Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
	ObjectMapper mapper = new ObjectMapper();
	mapper.findAndRegisterModules();
	mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE);
	mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
	jackson2JsonRedisSerializer.setObjectMapper(mapper);

	template.setValueSerializer(jackson2JsonRedisSerializer);
	template.setKeySerializer(new StringRedisSerializer());

	template.afterPropertiesSet();

	return template;
}
 
开发者ID:nonocast,项目名称:todolist,代码行数:20,代码来源:CacheConfig.java

示例14: RedisMetricRepository

import org.springframework.data.redis.connection.RedisConnectionFactory; //导入依赖的package包/类
/**
 * Allows user to set the prefix and key to use to store the index of other keys. The
 * redis store will hold a zset under the key just so the metric names can be
 * enumerated. Read operations, especially {@link #findAll()} and {@link #count()},
 * will only be accurate if the key is unique to the prefix of this repository.
 *
 * @param redisConnectionFactory the redis connection factory
 * @param prefix the prefix to set for all metrics keys
 * @param key the key to set
 */
public RedisMetricRepository(RedisConnectionFactory redisConnectionFactory,
		String prefix, String key) {
	if (prefix == null) {
		prefix = DEFAULT_METRICS_PREFIX;
		if (key == null) {
			key = DEFAULT_KEY;
		}
	}
	else if (key == null) {
		key = "keys." + prefix;
	}
	Assert.notNull(redisConnectionFactory, "RedisConnectionFactory must not be null");
	this.redisOperations = RedisUtils.stringTemplate(redisConnectionFactory);
	if (!prefix.endsWith(".")) {
		prefix = prefix + ".";
	}
	this.prefix = prefix;
	if (key.endsWith(".")) {
		key = key.substring(0, key.length() - 1);
	}
	this.key = key;
	this.zSetOperations = this.redisOperations.boundZSetOps(this.key);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:34,代码来源:RedisMetricRepository.java

示例15: redisIsUp

import org.springframework.data.redis.connection.RedisConnectionFactory; //导入依赖的package包/类
@Test
public void redisIsUp() throws Exception {
	Properties info = new Properties();
	info.put("redis_version", "2.8.9");
	RedisConnection redisConnection = mock(RedisConnection.class);
	RedisConnectionFactory redisConnectionFactory = mock(
			RedisConnectionFactory.class);
	given(redisConnectionFactory.getConnection()).willReturn(redisConnection);
	given(redisConnection.info()).willReturn(info);
	RedisHealthIndicator healthIndicator = new RedisHealthIndicator(
			redisConnectionFactory);
	Health health = healthIndicator.health();
	assertThat(health.getStatus()).isEqualTo(Status.UP);
	assertThat(health.getDetails().get("version")).isEqualTo("2.8.9");
	verify(redisConnectionFactory).getConnection();
	verify(redisConnection).info();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:18,代码来源:RedisHealthIndicatorTests.java


注:本文中的org.springframework.data.redis.connection.RedisConnectionFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。