Search in sources :

Example 1 with StringRedisSerializer

use of org.springframework.data.redis.serializer.StringRedisSerializer in project rdbcache by rdbcache.

the class RedisConfig method keyInfoRedisTemplate.

@Bean
public KeyInfoRedisTemplate keyInfoRedisTemplate() {
    KeyInfoRedisTemplate template = new KeyInfoRedisTemplate();
    template.setConnectionFactory(redisConnectionFactory());
    template.setKeySerializer(new StringRedisSerializer());
    template.setHashKeySerializer(new StringRedisSerializer());
    template.setHashValueSerializer(new Jackson2JsonRedisSerializer<KeyInfo>(KeyInfo.class));
    return template;
}
Also used : StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) KeyInfo(com.rdbcache.models.KeyInfo) Bean(org.springframework.context.annotation.Bean)

Example 2 with StringRedisSerializer

use of org.springframework.data.redis.serializer.StringRedisSerializer in project free-framework by a601942905git.

the class RedisConfig method redisTemplate.

/**
 * 自定义redisTemplate
 * @param redisConnectionFactory    spring自动注入
 * @return
 */
@Bean
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
    RedisTemplate redisTemplate = new RedisTemplate();
    redisTemplate.setConnectionFactory(redisConnectionFactory);
    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);
    redisTemplate.setKeySerializer(new StringRedisSerializer());
    redisTemplate.setValueSerializer(jackson2JsonRedisSerializer);
    redisTemplate.afterPropertiesSet();
    return redisTemplate;
}
Also used : StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) Jackson2JsonRedisSerializer(org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Bean(org.springframework.context.annotation.Bean)

Example 3 with StringRedisSerializer

use of org.springframework.data.redis.serializer.StringRedisSerializer in project spring-integration by spring-projects.

the class RedisStoreOutboundChannelAdapterIntegrationTests method testMapToMapNoKey.

// key is not provided
@Test(expected = MessageHandlingException.class)
@RedisAvailable
public void testMapToMapNoKey() {
    RedisTemplate<String, Map<String, Map<String, String>>> redisTemplate = new RedisTemplate<String, Map<String, Map<String, String>>>();
    redisTemplate.setKeySerializer(new StringRedisSerializer());
    redisTemplate.setHashKeySerializer(new StringRedisSerializer());
    redisTemplate.setConnectionFactory(getConnectionFactoryForTest());
    redisTemplate.afterPropertiesSet();
    RedisMap<String, Map<String, String>> redisMap = new DefaultRedisMap<String, Map<String, String>>("pepboys", redisTemplate);
    assertEquals(0, redisMap.size());
    Map<String, String> pepboys = new HashMap<String, String>();
    pepboys.put("1", "Manny");
    pepboys.put("2", "Moe");
    pepboys.put("3", "Jack");
    Message<Map<String, String>> message = MessageBuilder.withPayload(pepboys).build();
    this.mapToMapBChannel.send(message);
}
Also used : StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) StringRedisTemplate(org.springframework.data.redis.core.StringRedisTemplate) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) HashMap(java.util.HashMap) DefaultRedisMap(org.springframework.data.redis.support.collections.DefaultRedisMap) HashMap(java.util.HashMap) Map(java.util.Map) RedisMap(org.springframework.data.redis.support.collections.RedisMap) DefaultRedisMap(org.springframework.data.redis.support.collections.DefaultRedisMap) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 4 with StringRedisSerializer

use of org.springframework.data.redis.serializer.StringRedisSerializer in project tutorials-java by Artister.

the class RedisConfig method redisTemplate.

@Bean
public RedisTemplate<String, Person> redisTemplate(RedisConnectionFactory factory) {
    RedisTemplate<String, Person> template = new RedisTemplate<>();
    template.setConnectionFactory(factory);
    template.setKeySerializer(new StringRedisSerializer());
    template.setValueSerializer(new RedisObjectSerializer());
    return template;
}
Also used : StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) Person(org.ko.web.domain.Person) Bean(org.springframework.context.annotation.Bean)

Example 5 with StringRedisSerializer

use of org.springframework.data.redis.serializer.StringRedisSerializer in project spring-integration by spring-projects.

the class RedisStoreOutboundChannelAdapterParserTests method validateWithStringObjectTemplate.

@Test
public void validateWithStringObjectTemplate() {
    RedisStoreWritingMessageHandler withStringObjectTemplate = TestUtils.getPropertyValue(context.getBean("withStringObjectTemplate.adapter"), "handler", RedisStoreWritingMessageHandler.class);
    assertEquals("pepboys", ((LiteralExpression) TestUtils.getPropertyValue(withStringObjectTemplate, "keyExpression")).getExpressionString());
    assertEquals("PROPERTIES", (TestUtils.getPropertyValue(withStringObjectTemplate, "collectionType")).toString());
    assertFalse(TestUtils.getPropertyValue(withStringObjectTemplate, "redisTemplate") instanceof StringRedisTemplate);
    assertTrue(TestUtils.getPropertyValue(withStringObjectTemplate, "redisTemplate.keySerializer") instanceof StringRedisSerializer);
    assertTrue(TestUtils.getPropertyValue(withStringObjectTemplate, "redisTemplate.hashKeySerializer") instanceof StringRedisSerializer);
    assertTrue(TestUtils.getPropertyValue(withStringObjectTemplate, "redisTemplate.valueSerializer") instanceof JdkSerializationRedisSerializer);
    assertTrue(TestUtils.getPropertyValue(withStringObjectTemplate, "redisTemplate.hashValueSerializer") instanceof JdkSerializationRedisSerializer);
}
Also used : StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) RedisStoreWritingMessageHandler(org.springframework.integration.redis.outbound.RedisStoreWritingMessageHandler) JdkSerializationRedisSerializer(org.springframework.data.redis.serializer.JdkSerializationRedisSerializer) StringRedisTemplate(org.springframework.data.redis.core.StringRedisTemplate) Test(org.junit.Test)

Aggregations

StringRedisSerializer (org.springframework.data.redis.serializer.StringRedisSerializer)43 RedisTemplate (org.springframework.data.redis.core.RedisTemplate)29 StringRedisTemplate (org.springframework.data.redis.core.StringRedisTemplate)16 Bean (org.springframework.context.annotation.Bean)15 Test (org.junit.Test)14 JdkSerializationRedisSerializer (org.springframework.data.redis.serializer.JdkSerializationRedisSerializer)14 RedisAvailable (org.springframework.integration.redis.rules.RedisAvailable)13 DataAccessException (org.springframework.dao.DataAccessException)7 RedisConnection (org.springframework.data.redis.connection.RedisConnection)7 RedisCallback (org.springframework.data.redis.core.RedisCallback)7 BeanFactory (org.springframework.beans.factory.BeanFactory)5 Date (java.util.Date)4 QueueChannel (org.springframework.integration.channel.QueueChannel)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Jackson2JsonRedisSerializer (org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer)3 Message (org.springframework.messaging.Message)3 PollableChannel (org.springframework.messaging.PollableChannel)3 ErrorMessage (org.springframework.messaging.support.ErrorMessage)3 HashMap (java.util.HashMap)2