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);
}
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;
}
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();
}
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;
}
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;
}
Aggregations