Search in sources :

Example 11 with RedisSerializer

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);
}
Also used : StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) RedisSerializer(org.springframework.data.redis.serializer.RedisSerializer) StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer)

Example 12 with RedisSerializer

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);
}
Also used : StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) RedisSerializer(org.springframework.data.redis.serializer.RedisSerializer) StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer)

Example 13 with RedisSerializer

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)));
}
Also used : RedisSerializer(org.springframework.data.redis.serializer.RedisSerializer) ByteRecord(org.springframework.data.redis.connection.stream.ByteRecord) RedisCallback(org.springframework.data.redis.core.RedisCallback) Consumer(org.springframework.data.redis.connection.stream.Consumer) Executor(java.util.concurrent.Executor) ObjectUtils(org.springframework.util.ObjectUtils) Record(org.springframework.data.redis.connection.stream.Record) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) StreamReadOptions(org.springframework.data.redis.connection.stream.StreamReadOptions) Function(java.util.function.Function) ArrayList(java.util.ArrayList) ReadOffset(org.springframework.data.redis.connection.stream.ReadOffset) ErrorHandler(org.springframework.util.ErrorHandler) List(java.util.List) MapRecord(org.springframework.data.redis.connection.stream.MapRecord) StreamOperations(org.springframework.data.redis.core.StreamOperations) TypeDescriptor(org.springframework.core.convert.TypeDescriptor) Duration(java.time.Duration) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) StreamOffset(org.springframework.data.redis.connection.stream.StreamOffset) RedisSerializer(org.springframework.data.redis.serializer.RedisSerializer) Assert(org.springframework.util.Assert) Consumer(org.springframework.data.redis.connection.stream.Consumer) ArrayList(java.util.ArrayList) List(java.util.List) StreamReadOptions(org.springframework.data.redis.connection.stream.StreamReadOptions)

Aggregations

RedisSerializer (org.springframework.data.redis.serializer.RedisSerializer)13 StringRedisSerializer (org.springframework.data.redis.serializer.StringRedisSerializer)8 RedisConnection (org.springframework.data.redis.connection.RedisConnection)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 ConditionalOnProperty (org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)2 Bean (org.springframework.context.annotation.Bean)2 RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 StreamMessage (com.hedera.mirror.common.domain.topic.StreamMessage)1 TopicMessage (com.hedera.mirror.common.domain.topic.TopicMessage)1 BatchEntityListenerTest (com.hedera.mirror.importer.parser.record.entity.BatchEntityListenerTest)1 RedisKeyWrapper (com.jn.agileway.redis.core.key.RedisKeyWrapper)1 DelegatableRedisSerializer (com.jn.agileway.redis.core.serialization.DelegatableRedisSerializer)1 RedisKeySerializer (com.jn.agileway.redis.core.serialization.RedisKeySerializer)1 Blog (com.myblog.model.Blog)1 KeyAndValue (com.myblog.model.KeyAndValue)1 Tag (com.myblog.model.Tag)1