use of org.springframework.data.redis.serializer.RedisSerializer in project study by youbl.
the class RedisConfiguration method initSerializer.
private static void initSerializer(RedisTemplate template) {
// Key用StringRedisSerializer,避免写入Redis的Key和Value,前缀都会出现 \xAC\xED\x00\x05t\x00\x03
RedisSerializer keySerializer = new StringRedisSerializer();
template.setKeySerializer(keySerializer);
template.setHashKeySerializer(keySerializer);
RedisSerializer valSerializer = new JsonRedisSerializer<>(Object.class);
// template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
template.setValueSerializer(valSerializer);
template.setHashValueSerializer(valSerializer);
}
use of org.springframework.data.redis.serializer.RedisSerializer in project study by youbl.
the class RedisFactoryBean method initSerializer.
private static void initSerializer(RedisTemplate redis1) {
// Key用StringRedisSerializer,避免写入Redis的Key和Value,前缀都会出现 \xAC\xED\x00\x05t\x00\x03
RedisSerializer keySerializer = new StringRedisSerializer();
redis1.setKeySerializer(keySerializer);
redis1.setHashKeySerializer(keySerializer);
BeinetJsonRedisSerializer valSerializer = new BeinetJsonRedisSerializer(Object.class);
redis1.setValueSerializer(valSerializer);
redis1.setHashValueSerializer(valSerializer);
}
use of org.springframework.data.redis.serializer.RedisSerializer in project spring-data-redis by spring-projects.
the class DefaultStreamMessageListenerContainer method getReadFunction.
@SuppressWarnings("unchecked")
private Function<ReadOffset, List<ByteRecord>> getReadFunction(StreamReadRequest<K> streamRequest) {
byte[] rawKey = ((RedisSerializer<K>) template.getKeySerializer()).serialize(streamRequest.getStreamOffset().getKey());
if (streamRequest instanceof StreamMessageListenerContainer.ConsumerStreamReadRequest) {
ConsumerStreamReadRequest<K> consumerStreamRequest = (ConsumerStreamReadRequest<K>) streamRequest;
StreamReadOptions readOptions = consumerStreamRequest.isAutoAcknowledge() ? this.readOptions.autoAcknowledge() : this.readOptions;
Consumer consumer = consumerStreamRequest.getConsumer();
return (offset) -> template.execute((RedisCallback<List<ByteRecord>>) connection -> connection.streamCommands().xReadGroup(consumer, readOptions, StreamOffset.create(rawKey, offset)));
}
return (offset) -> template.execute((RedisCallback<List<ByteRecord>>) connection -> connection.streamCommands().xRead(readOptions, StreamOffset.create(rawKey, offset)));
}
Aggregations