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;
}
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;
}
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);
}
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;
}
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);
}
Aggregations