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