本文整理匯總了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;
}
示例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;
}
示例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));
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}
示例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;
}
示例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