本文整理汇总了Java中org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer类的典型用法代码示例。如果您正苦于以下问题:Java GenericJackson2JsonRedisSerializer类的具体用法?Java GenericJackson2JsonRedisSerializer怎么用?Java GenericJackson2JsonRedisSerializer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GenericJackson2JsonRedisSerializer类属于org.springframework.data.redis.serializer包,在下文中一共展示了GenericJackson2JsonRedisSerializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildRedisTemplate
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; //导入依赖的package包/类
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;
}
示例2: redisTemplate
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; //导入依赖的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: savingAndDeletingNodes
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; //导入依赖的package包/类
@Test
public void savingAndDeletingNodes() throws UnsupportedEncodingException {
GenericJackson2JsonRedisSerializer serializer = new GenericJackson2JsonRedisSerializer(new ObjectMapper());
Node node1 = new Node("some id");
simpleStore.saveNode(new String(serializer.serialize(node1), "UTF-8"));
assertThat(simpleStore.getAllNodes().size()).isEqualTo(1);
Node node2 = new Node("another id");
simpleStore.saveNode(new String(serializer.serialize(node2), "UTF-8"));
simpleStore.deleteNode("some id");
assertThat(simpleStore.getAllNodes().iterator().next().getId()).isEqualTo("another id");
simpleStore.deleteAllNodes();
assertThat(simpleStore.getAllNodes().size()).isEqualTo(0);
Node node3 = new Node("again another id");
simpleStore.saveNode(new String(serializer.serialize(node3), "UTF-8"));
assertThat(simpleStore.getAllNodesAsObservable()).isNotNull();
simpleStore.flushDB();
assertThat(simpleStore.getAllNodes().size()).isEqualTo(0);
}
示例4: getStringRedisTemplate
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; //导入依赖的package包/类
@Bean
public RedisTemplate getStringRedisTemplate() {
StringRedisTemplate clusterTemplate = new StringRedisTemplate();
clusterTemplate.setConnectionFactory(jedisConnectionFactory());
clusterTemplate.setKeySerializer(new StringRedisSerializer());
clusterTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
return clusterTemplate;
}
示例5: redisTemplate
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; //导入依赖的package包/类
@Bean
public <K, V> RedisTemplate<K, V> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<K, V> template = new RedisTemplate<>();
template.setConnectionFactory(redisConnectionFactory);
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
template.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
template.setEnableTransactionSupport(true);
template.afterPropertiesSet();
return template;
}
示例6: getRedisTemplate
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; //导入依赖的package包/类
@Bean("redisTemplate")
public RedisTemplate<?, ?> getRedisTemplate(){
RedisTemplate<?,?> template = new StringRedisTemplate(jedisConnectionFactory);
GenericJackson2JsonRedisSerializer genericJackson2JsonRedisSerializer = new GenericJackson2JsonRedisSerializer();
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
template.setKeySerializer(stringRedisSerializer);
template.setValueSerializer(genericJackson2JsonRedisSerializer);
template.setHashKeySerializer(stringRedisSerializer);
template.setHashValueSerializer(genericJackson2JsonRedisSerializer);
return template;
}
示例7: redisTemplate
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; //导入依赖的package包/类
@Bean
@Primary
public StringRedisTemplate redisTemplate(RedisConnectionFactory connectionFactory) {
StringRedisTemplate template = new StringRedisTemplate();
template.setConnectionFactory(connectionFactory);
template.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
return template;
}
示例8: redisTemplate
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; //导入依赖的package包/类
@Bean
RedisTemplate< String, Long > redisTemplate() {
final RedisTemplate template = new RedisTemplate();
template.setConnectionFactory( jedisConnectionFactory() );
template.setKeySerializer( new StringRedisSerializer() );
template.setDefaultSerializer(new GenericJackson2JsonRedisSerializer());
return template;
}
示例9: init
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; //导入依赖的package包/类
private void init(RedisConnectionFactory connectionFactory, Jackson2JsonRedisSerializer jsonRedisSerializer) {
RedisSerializer<String> stringSerializer = new StringRedisSerializer();
setKeySerializer(new GenericJackson2JsonRedisSerializer());
setHashKeySerializer(stringSerializer);
setHashValueSerializer(stringSerializer);
setValueSerializer(jsonRedisSerializer);
setConnectionFactory(connectionFactory);
afterPropertiesSet();
}
示例10: redisTemplate
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; //导入依赖的package包/类
@Bean
public RedisTemplate<String, Object> redisTemplate(final RedisConnectionFactory factory){
RedisTemplate<String, Object> virtualNodeTemplate = new RedisTemplate<>();
virtualNodeTemplate.setConnectionFactory(factory);
virtualNodeTemplate.setKeySerializer(new StringRedisSerializer());
virtualNodeTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
return virtualNodeTemplate;
}
示例11: retrieveGraph
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; //导入依赖的package包/类
@Test
public void retrieveGraph() throws FileNotFoundException, UnsupportedEncodingException {
when(healthIndicatorsAggregator.aggregateNodes())
.thenReturn(Observable.from(newHashSet(
node().withId("service1").havingLinkedToNodeIds(newHashSet("backend1")).build(),
node().withId("service2").havingLinkedToNodeIds(newHashSet("backend2")).build(),
node().withId("backend1").havingLinkedFromNodeIds(newHashSet("service1")).build(),
node().withId("backend2").havingLinkedFromNodeIds(newHashSet("service2")).build())));
when(indexesAggregator.aggregateNodes())
.thenReturn(Observable.from(newHashSet(
node().withId("svc1rsc1").havingLinkedToNodeIds(newHashSet("service1")).build(),
node().withId("svc1rsc2").havingLinkedToNodeIds(newHashSet("service1")).build(),
node().withId("svc2rsc1").havingLinkedToNodeIds(newHashSet("service2")).build(),
node().withId("service1").withDetail("test", "test").build(),
node().withId("service2").build())));
when(pactsAggregator.aggregateNodes())
.thenReturn(Observable.from(newHashSet(
node().withId("svc1rsc2").build(),
node().withId("svc2rsc1").build(),
node().withId("service1").havingLinkedToNodeIds(newHashSet("svc2rsc1")).build(),
node().withId("service2").havingLinkedToNodeIds(newHashSet("svc1rsc2")).build())));
when(redisService.getAllNodes())
.thenReturn(newHashSet());
when(graphProperties.getUi()).thenReturn("UI Components");
when(graphProperties.getResources()).thenReturn("Resources");
when(graphProperties.getMicroservices()).thenReturn("Microservices");
when(graphProperties.getBackends()).thenReturn("Backends");
when(graphProperties.getTypes()).thenReturn(Arrays.asList(DB, MICROSERVICE, REST, SOAP, JMS, RESOURCE));
long startTime = System.currentTimeMillis();
Map<String, Object> graph = graphRetriever.retrieve();
long totalTime = System.currentTimeMillis() - startTime;
logger.info("Time spent waiting for processing: " + totalTime);
GenericJackson2JsonRedisSerializer serializer = new GenericJackson2JsonRedisSerializer(new ObjectMapper());
String nodeAsJson = new String(serializer.serialize(graph), "UTF-8");
JSONAssert.assertEquals(removeBlankNodes(load("src/test/resources/GraphRetrieverTest.json")),
removeBlankNodes(nodeAsJson), JSONCompareMode.LENIENT);
}
示例12: testRedisTemplate
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; //导入依赖的package包/类
@Test
public void testRedisTemplate() {
assertThat(this.sessionRedisTemplate).isNotNull();
assertThat(this.sessionRedisTemplate.getDefaultSerializer()).isNotNull();
assertThat(this.sessionRedisTemplate.getDefaultSerializer())
.isInstanceOf(GenericJackson2JsonRedisSerializer.class);
}
示例13: redisTemplate
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; //导入依赖的package包/类
@Bean
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
RedisTemplate template = new RedisTemplate();
template.setConnectionFactory(factory);
RedisSerializer keySerializer = new StringRedisSerializer();
// 设置key序列化类,否则key前面会多了一些乱码
template.setKeySerializer(keySerializer);
template.setHashKeySerializer(keySerializer);
// FIXME 有些版本有bug,没有序列化的只能序列化,但无法反序列化
GenericJackson2JsonRedisSerializer jsonSerializer = new GenericJackson2JsonRedisSerializer();
// 设置内容序列化类
template.setValueSerializer(jsonSerializer);
template.afterPropertiesSet();
return template;
}
示例14: setSerializer
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; //导入依赖的package包/类
private void setSerializer(RedisTemplate<String, String> template) {
template.setDefaultSerializer(new GenericJackson2JsonRedisSerializer());
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new GenericJackson2JsonRedisSerializer());
template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
}
示例15: jacksonRedisSerializer
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; //导入依赖的package包/类
/**
* JSON序列化
*/
@Bean
public GenericJackson2JsonRedisSerializer jacksonRedisSerializer() {
return new GenericJackson2JsonRedisSerializer();
}