本文整理汇总了Java中org.springframework.data.redis.serializer.StringRedisSerializer类的典型用法代码示例。如果您正苦于以下问题:Java StringRedisSerializer类的具体用法?Java StringRedisSerializer怎么用?Java StringRedisSerializer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StringRedisSerializer类属于org.springframework.data.redis.serializer包,在下文中一共展示了StringRedisSerializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: redisTemplate
import org.springframework.data.redis.serializer.StringRedisSerializer; //导入依赖的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: buildRedisTemplate
import org.springframework.data.redis.serializer.StringRedisSerializer; //导入依赖的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;
}
示例3: redisTemplate
import org.springframework.data.redis.serializer.StringRedisSerializer; //导入依赖的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;
}
示例4: redisTemplate
import org.springframework.data.redis.serializer.StringRedisSerializer; //导入依赖的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;
}
示例5: testDefaultPayloadSerializer
import org.springframework.data.redis.serializer.StringRedisSerializer; //导入依赖的package包/类
@Test
public void testDefaultPayloadSerializer() throws Exception {
RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(connectionFactory);
template.setKeySerializer(new StringRedisSerializer());
template.afterPropertiesSet();
adapter.afterPropertiesSet();
adapter.start();
template.boundListOps(currentQueueName).rightPush("message1");
@SuppressWarnings("unchecked")
Message<String> message = (Message<String>) messages.poll((int)(1000 * timeoutMultiplier), TimeUnit.MILLISECONDS);
assertNotNull(message);
assertEquals("message1", message.getPayload());
}
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-redis,代码行数:17,代码来源:RedisQueueInboundChannelAdapterTests.java
示例6: testDefaultMsgSerializer
import org.springframework.data.redis.serializer.StringRedisSerializer; //导入依赖的package包/类
@Test
public void testDefaultMsgSerializer() throws Exception {
RedisTemplate<String, Message<String>> template = new RedisTemplate<String, Message<String>>();
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new JdkSerializationRedisSerializer());
template.setConnectionFactory(connectionFactory);
template.afterPropertiesSet();
adapter.setExpectMessage(true);
adapter.afterPropertiesSet();
adapter.start();
Map<String, Object> headers = new HashMap<>();
headers.put("header1", "foo");
template.boundListOps(currentQueueName).rightPush(new GenericMessage<>("message2", headers));
@SuppressWarnings("unchecked")
Message<String> message = (Message<String>) messages.poll((int)(1000 * timeoutMultiplier), TimeUnit.MILLISECONDS);
assertEquals("message2", message.getPayload());
assertEquals("foo", message.getHeaders().get("header1"));
}
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-redis,代码行数:21,代码来源:RedisQueueInboundChannelAdapterTests.java
示例7: testNoSerializer
import org.springframework.data.redis.serializer.StringRedisSerializer; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testNoSerializer() throws Exception {
RedisTemplate<String, byte[]> template = new RedisTemplate<>();
template.setEnableDefaultSerializer(false);
template.setKeySerializer(new StringRedisSerializer());
template.setConnectionFactory(connectionFactory);
template.afterPropertiesSet();
adapter.setSerializer(null);
adapter.afterPropertiesSet();
adapter.start();
template.boundListOps(currentQueueName).rightPush("message3".getBytes());
Message<byte[]> message = (Message<byte[]>) messages.poll((int)(1000 * timeoutMultiplier), TimeUnit.MILLISECONDS);
assertEquals("message3", new String(message.getPayload()));
}
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-redis,代码行数:18,代码来源:RedisQueueInboundChannelAdapterTests.java
示例8: testCustomPayloadSerializer
import org.springframework.data.redis.serializer.StringRedisSerializer; //导入依赖的package包/类
@Test
public void testCustomPayloadSerializer() throws Exception {
RedisTemplate<String, Long> template = new RedisTemplate<>();
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new GenericToStringSerializer<>(Long.class));
template.setConnectionFactory(connectionFactory);
template.afterPropertiesSet();
adapter.setSerializer(new GenericToStringSerializer<Long>(Long.class));
adapter.afterPropertiesSet();
adapter.start();
template.boundListOps(currentQueueName).rightPush(5l);
@SuppressWarnings("unchecked")
Message<Long> message = (Message<Long>) messages.poll((int)(1000 * timeoutMultiplier), TimeUnit.MILLISECONDS);
assertEquals(5L, (long) message.getPayload());
}
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-redis,代码行数:18,代码来源:RedisQueueInboundChannelAdapterTests.java
示例9: testCustomMessageSerializer
import org.springframework.data.redis.serializer.StringRedisSerializer; //导入依赖的package包/类
@Test
public void testCustomMessageSerializer() throws Exception {
RedisTemplate<String, Message<?>> template = new RedisTemplate<>();
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new TestMessageSerializer());
template.setConnectionFactory(connectionFactory);
template.afterPropertiesSet();
adapter.setSerializer(new TestMessageSerializer());
adapter.setExpectMessage(true);
adapter.afterPropertiesSet();
adapter.start();
template.boundListOps(currentQueueName).rightPush(new GenericMessage<>(10l));
@SuppressWarnings("unchecked")
Message<Long> message = (Message<Long>) messages.poll((int)(1000 * timeoutMultiplier), TimeUnit.MILLISECONDS);
assertEquals(10L, (long) message.getPayload());
}
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-redis,代码行数:19,代码来源:RedisQueueInboundChannelAdapterTests.java
示例10: testDefaultMsgSerializer
import org.springframework.data.redis.serializer.StringRedisSerializer; //导入依赖的package包/类
@Test
public void testDefaultMsgSerializer() throws Exception {
RedisTemplate<String, Message<?>> template = new RedisTemplate<String, Message<?>>();
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new JdkSerializationRedisSerializer());
template.setConnectionFactory(connectionFactory);
template.afterPropertiesSet();
adapter.setExtractPayload(false);
adapter.afterPropertiesSet();
Map<String, Object> headers = new HashMap<String, Object>();
headers.put("header1", "foo");
adapter.handleMessage(new GenericMessage<String>("message2", headers));
Message<?> message = template.boundListOps(QUEUE_NAME).rightPop();
assertEquals("message2", message.getPayload());
assertEquals("foo", message.getHeaders().get("header1"));
}
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-redis,代码行数:19,代码来源:RedisQueueOutboundChannelAdapterTests.java
示例11: redisTemplate
import org.springframework.data.redis.serializer.StringRedisSerializer; //导入依赖的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;
}
示例12: convertByteToString
import org.springframework.data.redis.serializer.StringRedisSerializer; //导入依赖的package包/类
public static void convertByteToString(RedisConnection connection, Set<byte[]> keysSet, List<RKey> tempList) {
StringRedisSerializer stringSerializer = new StringRedisSerializer(Charset.forName("UTF8"));
for(byte[] byteArray: keysSet) {
String converted = stringSerializer.deserialize(byteArray);
DataType dateType = null;
switch(RedisApplication.showType) {
case show:
dateType = connection.type(byteArray);
break;
case hide:
dateType = DataType.NONE;
break;
default:
dateType = connection.type(byteArray);
break;
}
RKey rkey = new RKey(converted, dateType);
tempList.add(rkey);
}
}
示例13: stringReactiveRedisTemplate
import org.springframework.data.redis.serializer.StringRedisSerializer; //导入依赖的package包/类
@Bean
//TODO: replace with ReactiveStringRedisTemplate in future
public ReactiveRedisTemplate<String, String> stringReactiveRedisTemplate(
ReactiveRedisConnectionFactory reactiveRedisConnectionFactory,
ResourceLoader resourceLoader) {
RedisSerializer<String> serializer = new StringRedisSerializer();
RedisSerializationContext<String , String> serializationContext = RedisSerializationContext
.<String, String>newSerializationContext()
.key(serializer)
.value(serializer)
.hashKey(serializer)
.hashValue(serializer)
.build();
return new ReactiveRedisTemplate<>(reactiveRedisConnectionFactory,
serializationContext);
}
示例14: redisTemplate
import org.springframework.data.redis.serializer.StringRedisSerializer; //导入依赖的package包/类
@Bean
public RedisOperations<String, Request> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<String, Request> template = new RedisTemplate<String, Request>();
template.setConnectionFactory(redisConnectionFactory);
RedisSerializer<String> keySerializer = new StringRedisSerializer();
Jackson2JsonRedisSerializer<Request> requestSerializer = new Jackson2JsonRedisSerializer<Request>(Request.class);
template.setKeySerializer(keySerializer);
template.setValueSerializer(requestSerializer);
template.setHashKeySerializer(keySerializer);
template.setHashValueSerializer(requestSerializer);
return template;
}
示例15: redisTemplate
import org.springframework.data.redis.serializer.StringRedisSerializer; //导入依赖的package包/类
@Bean
public RedisTemplate<String, Album> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<String, Album> template = new RedisTemplate<String, Album>();
template.setConnectionFactory(redisConnectionFactory);
RedisSerializer<String> stringSerializer = new StringRedisSerializer();
RedisSerializer<Album> albumSerializer = new JacksonJsonRedisSerializer<Album>(Album.class);
template.setKeySerializer(stringSerializer);
template.setValueSerializer(albumSerializer);
template.setHashKeySerializer(stringSerializer);
template.setHashValueSerializer(albumSerializer);
return template;
}