Search in sources :

Example 1 with RedisSerializer

use of org.springframework.data.redis.serializer.RedisSerializer in project agileway by fangjinuo.

the class RedisTemplates method createRedisTemplate.

public static RedisTemplate<String, ?> createRedisTemplate(@NonNull RedisConnectionFactory connectionFactory, RedisTemplateProperties redisTemplateProperties, @Nullable ClassLoader beanClassLoader, @Nullable RedisLuaScriptRepository redisLuaScriptRepository, boolean initIt) {
    RedisKeyWrapper keyWrapper = new RedisKeyWrapper(redisTemplateProperties.getKey());
    RedisSerializer<String> keySerializer = new RedisKeySerializer(keyWrapper);
    Codec<?> codec = newCodec(redisTemplateProperties.getValueCodecType());
    RedisSerializer<?> valueSerializer = new DelegatableRedisSerializer(codec);
    RedisSerializer hashKeySerializer = new RedisKeySerializer();
    return createRedisTemplate(connectionFactory, keySerializer, valueSerializer, beanClassLoader, stringRedisSerializer, hashKeySerializer, valueSerializer, redisLuaScriptRepository, redisTemplateProperties.isTransactionEnabled(), initIt);
}
Also used : DelegatableRedisSerializer(com.jn.agileway.redis.core.serialization.DelegatableRedisSerializer) GenericJackson2JsonRedisSerializer(org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer) StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) RedisSerializer(org.springframework.data.redis.serializer.RedisSerializer) DelegatableRedisSerializer(com.jn.agileway.redis.core.serialization.DelegatableRedisSerializer) RedisKeyWrapper(com.jn.agileway.redis.core.key.RedisKeyWrapper) RedisKeySerializer(com.jn.agileway.redis.core.serialization.RedisKeySerializer)

Example 2 with RedisSerializer

use of org.springframework.data.redis.serializer.RedisSerializer in project conWasteJiNing by Yingjie-tian.

the class ShiroDao method setRedisTemplate.

/**
 * key值出现\xac\xed\x00\x05t\x00前缀
 * 查阅资料发现 RedisTemplate默认序列化方式用的是JdkSerializationRedisSerializer
 * 此处修改为 Jackson2JsonRedisSerializer 序列化
 */
@Autowired(required = false)
@SuppressWarnings("rawtypes")
public void setRedisTemplate(RedisTemplate redisTemplate) {
    // 序列化为String
    RedisSerializer stringSerializer = new StringRedisSerializer();
    // 序列化为Json
    Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
    redisTemplate.setKeySerializer(stringSerializer);
    redisTemplate.setValueSerializer(jackson2JsonRedisSerializer);
    redisTemplate.setHashKeySerializer(stringSerializer);
    redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer);
    this.redisTemplate = redisTemplate;
}
Also used : StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) Jackson2JsonRedisSerializer(org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer) RedisSerializer(org.springframework.data.redis.serializer.RedisSerializer) StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) Jackson2JsonRedisSerializer(org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer) Autowired(org.springframework.beans.factory.annotation.Autowired)

Example 3 with RedisSerializer

use of org.springframework.data.redis.serializer.RedisSerializer in project hedera-mirror-node by hashgraph.

the class RedisEntityListenerIntegrationTest method subscribe.

@Override
protected Flux<TopicMessage> subscribe(long topicId) {
    Sinks.Many<TopicMessage> sink = Sinks.many().unicast().onBackpressureBuffer();
    RedisSerializer stringSerializer = ((RedisTemplate<String, ?>) redisOperations).getStringSerializer();
    RedisSerializer<TopicMessage> serializer = (RedisSerializer<TopicMessage>) redisOperations.getValueSerializer();
    RedisCallback<TopicMessage> redisCallback = connection -> {
        byte[] channel = stringSerializer.serialize("topic." + topicId);
        connection.subscribe((message, pattern) -> sink.emitNext(serializer.deserialize(message.getBody()), Sinks.EmitFailureHandler.FAIL_FAST), channel);
        return null;
    };
    redisOperations.execute(redisCallback);
    return sink.asFlux();
}
Also used : RedisSerializer(org.springframework.data.redis.serializer.RedisSerializer) Sinks(reactor.core.publisher.Sinks) Flux(reactor.core.publisher.Flux) TestInstance(org.junit.jupiter.api.TestInstance) RedisCallback(org.springframework.data.redis.core.RedisCallback) RedisOperations(org.springframework.data.redis.core.RedisOperations) TopicMessage(com.hedera.mirror.common.domain.topic.TopicMessage) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) BatchEntityListenerTest(com.hedera.mirror.importer.parser.record.entity.BatchEntityListenerTest) Autowired(org.springframework.beans.factory.annotation.Autowired) StreamMessage(com.hedera.mirror.common.domain.topic.StreamMessage) RedisSerializer(org.springframework.data.redis.serializer.RedisSerializer) Sinks(reactor.core.publisher.Sinks) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) TopicMessage(com.hedera.mirror.common.domain.topic.TopicMessage)

Example 4 with RedisSerializer

use of org.springframework.data.redis.serializer.RedisSerializer in project IT-Demo by yanghaiji.

the class RedisConfiguration method getSingleRedisTemplate.

@Bean("redisTemplate")
@ConditionalOnProperty(name = "spring.redis.host", matchIfMissing = true)
public RedisTemplate<String, Object> getSingleRedisTemplate() {
    RedisTemplate<String, Object> redisTemplate = new RedisTemplate<String, Object>();
    RedisSerializer redisObjectSerializer = new RedisObjectSerializer();
    redisTemplate.setConnectionFactory(lettuceConnectionFactory);
    redisTemplate.setKeySerializer(new StringRedisSerializer());
    redisTemplate.setValueSerializer(redisObjectSerializer);
    redisTemplate.setHashValueSerializer(redisObjectSerializer);
    redisTemplate.afterPropertiesSet();
    return redisTemplate;
}
Also used : StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) RedisSerializer(org.springframework.data.redis.serializer.RedisSerializer) StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) Bean(org.springframework.context.annotation.Bean) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)

Example 5 with RedisSerializer

use of org.springframework.data.redis.serializer.RedisSerializer in project IT-Demo by yanghaiji.

the class RedisConfiguration method getSingleRedisTemplate.

@Bean("redisTemplate")
@ConditionalOnProperty(name = "spring.redis.host", matchIfMissing = true)
public RedisTemplate<String, Object> getSingleRedisTemplate() {
    RedisTemplate<String, Object> redisTemplate = new RedisTemplate<String, Object>();
    RedisSerializer redisObjectSerializer = new RedisObjectSerializer();
    redisTemplate.setConnectionFactory(lettuceConnectionFactory);
    redisTemplate.setKeySerializer(new StringRedisSerializer());
    redisTemplate.setValueSerializer(redisObjectSerializer);
    redisTemplate.setHashValueSerializer(redisObjectSerializer);
    redisTemplate.afterPropertiesSet();
    return redisTemplate;
}
Also used : StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) RedisSerializer(org.springframework.data.redis.serializer.RedisSerializer) StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) Bean(org.springframework.context.annotation.Bean) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)

Aggregations

RedisSerializer (org.springframework.data.redis.serializer.RedisSerializer)11 StringRedisSerializer (org.springframework.data.redis.serializer.StringRedisSerializer)7 RedisConnection (org.springframework.data.redis.connection.RedisConnection)3 Autowired (org.springframework.beans.factory.annotation.Autowired)2 ConditionalOnProperty (org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)2 Bean (org.springframework.context.annotation.Bean)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 TestInstance (org.junit.jupiter.api.TestInstance)1 DataAccessException (org.springframework.dao.DataAccessException)1 RedisCallback (org.springframework.data.redis.core.RedisCallback)1