org.springframework.data.redis.serializer.JdkSerializationRedisSerializer Java Examples
The following examples show how to use
org.springframework.data.redis.serializer.JdkSerializationRedisSerializer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RedisTemplateConfiguration.java From mica with GNU Lesser General Public License v3.0 | 6 votes |
/** * value 值 序列化 * * @return RedisSerializer */ @Bean @ConditionalOnMissingBean(RedisSerializer.class) public RedisSerializer<Object> redisSerializer(MicaRedisProperties properties, ObjectProvider<ObjectMapper> objectProvider) { MicaRedisProperties.SerializerType serializerType = properties.getSerializerType(); if (MicaRedisProperties.SerializerType.JDK == serializerType) { return new JdkSerializationRedisSerializer(); } // jackson findAndRegisterModules,use copy ObjectMapper objectMapper = objectProvider.getIfAvailable(ObjectMapper::new).copy(); // findAndRegisterModules objectMapper.findAndRegisterModules(); // class type info to json GenericJackson2JsonRedisSerializer.registerNullValueSerializer(objectMapper, null); objectMapper.activateDefaultTyping(objectMapper.getPolymorphicTypeValidator(), DefaultTyping.NON_FINAL, As.PROPERTY); return new GenericJackson2JsonRedisSerializer(objectMapper); }
Example #2
Source File: RedisIndexedSessionRepositoryTests.java From spring-session with Apache License 2.0 | 6 votes |
@Test void onMessageExpiredInOtherDatabase() { JdkSerializationRedisSerializer serializer = new JdkSerializationRedisSerializer(); this.redisRepository.setApplicationEventPublisher(this.publisher); this.redisRepository.setDefaultSerializer(serializer); MapSession session = this.cached; String channel = "__keyevent@1__:expired"; String body = "spring:session:sessions:expires:" + session.getId(); DefaultMessage message = new DefaultMessage(channel.getBytes(StandardCharsets.UTF_8), body.getBytes(StandardCharsets.UTF_8)); this.redisRepository.onMessage(message, "".getBytes(StandardCharsets.UTF_8)); assertThat(this.event.getAllValues()).isEmpty(); verifyZeroInteractions(this.publisher); }
Example #3
Source File: RedisIndexedSessionRepositoryTests.java From spring-session with Apache License 2.0 | 6 votes |
@Test void onMessageDeletedInOtherDatabase() { JdkSerializationRedisSerializer serializer = new JdkSerializationRedisSerializer(); this.redisRepository.setApplicationEventPublisher(this.publisher); this.redisRepository.setDefaultSerializer(serializer); MapSession session = this.cached; String channel = "__keyevent@1__:del"; String body = "spring:session:sessions:expires:" + session.getId(); DefaultMessage message = new DefaultMessage(channel.getBytes(StandardCharsets.UTF_8), body.getBytes(StandardCharsets.UTF_8)); this.redisRepository.onMessage(message, "".getBytes(StandardCharsets.UTF_8)); assertThat(this.event.getAllValues()).isEmpty(); verifyZeroInteractions(this.publisher); }
Example #4
Source File: RedisCacheAutoConfiguration.java From black-shop with Apache License 2.0 | 6 votes |
private RedisCacheConfiguration determineConfiguration(ClassLoader classLoader) { if (this.redisCacheConfiguration != null) { return this.redisCacheConfiguration; } else { CacheProperties.Redis redisProperties = this.cacheProperties.getRedis(); RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig(); config = config.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new JdkSerializationRedisSerializer(classLoader))); if (redisProperties.getTimeToLive() != null) { config = config.entryTtl(redisProperties.getTimeToLive()); } if (redisProperties.getKeyPrefix() != null) { config = config.prefixKeysWith(redisProperties.getKeyPrefix()); } if (!redisProperties.isCacheNullValues()) { config = config.disableCachingNullValues(); } if (!redisProperties.isUseKeyPrefix()) { config = config.disableKeyPrefix(); } return config; } }
Example #5
Source File: RedisCacheAutoConfiguration.java From faster-framework-project with Apache License 2.0 | 6 votes |
private org.springframework.data.redis.cache.RedisCacheConfiguration determineConfiguration( ClassLoader classLoader, CacheProperties cacheProperties ) { CacheProperties.Redis redisProperties = cacheProperties.getRedis(); org.springframework.data.redis.cache.RedisCacheConfiguration config = org.springframework.data.redis.cache.RedisCacheConfiguration .defaultCacheConfig(); config = config.serializeValuesWith(RedisSerializationContext.SerializationPair .fromSerializer(new JdkSerializationRedisSerializer(classLoader))); if (redisProperties.getTimeToLive() != null) { config = config.entryTtl(redisProperties.getTimeToLive()); } if (redisProperties.getKeyPrefix() != null) { config = config.prefixKeysWith(redisProperties.getKeyPrefix()); } if (!redisProperties.isCacheNullValues()) { config = config.disableCachingNullValues(); } if (!redisProperties.isUseKeyPrefix()) { config = config.disableKeyPrefix(); } return config; }
Example #6
Source File: RedisIndexedSessionRepositoryTests.java From spring-session with Apache License 2.0 | 6 votes |
@Test void onMessageCreatedInOtherDatabase() { JdkSerializationRedisSerializer serializer = new JdkSerializationRedisSerializer(); this.redisRepository.setApplicationEventPublisher(this.publisher); this.redisRepository.setDefaultSerializer(serializer); MapSession session = this.cached; String channel = "spring:session:event:created:1:" + session.getId(); byte[] body = serializer.serialize(new HashMap()); DefaultMessage message = new DefaultMessage(channel.getBytes(StandardCharsets.UTF_8), body); this.redisRepository.onMessage(message, "".getBytes(StandardCharsets.UTF_8)); assertThat(this.event.getAllValues()).isEmpty(); verifyZeroInteractions(this.publisher); }
Example #7
Source File: RedisIndexedSessionRepositoryTests.java From spring-session with Apache License 2.0 | 6 votes |
@Test void onMessageCreated() { MapSession session = this.cached; byte[] pattern = "".getBytes(StandardCharsets.UTF_8); String channel = "spring:session:event:0:created:" + session.getId(); JdkSerializationRedisSerializer defaultSerailizer = new JdkSerializationRedisSerializer(); this.redisRepository.setDefaultSerializer(defaultSerailizer); byte[] body = defaultSerailizer.serialize(new HashMap()); DefaultMessage message = new DefaultMessage(channel.getBytes(StandardCharsets.UTF_8), body); this.redisRepository.setApplicationEventPublisher(this.publisher); this.redisRepository.onMessage(message, pattern); verify(this.publisher).publishEvent(this.event.capture()); assertThat(this.event.getValue().getSessionId()).isEqualTo(session.getId()); }
Example #8
Source File: IndexDocTests.java From spring-session with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unused") void newReactiveRedisSessionRepository() { LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(); RedisSerializationContext<String, Object> serializationContext = RedisSerializationContext .<String, Object>newSerializationContext(new JdkSerializationRedisSerializer()).build(); // tag::new-reactiveredissessionrepository[] // ... create and configure connectionFactory and serializationContext ... ReactiveRedisTemplate<String, Object> redisTemplate = new ReactiveRedisTemplate<>(connectionFactory, serializationContext); ReactiveSessionRepository<? extends Session> repository = new ReactiveRedisSessionRepository(redisTemplate); // end::new-reactiveredissessionrepository[] }
Example #9
Source File: EmailRedisTemplateConfiguration.java From spring-boot-email-tools with Apache License 2.0 | 6 votes |
@Bean @Qualifier("valueTemplate") public RedisTemplate<String, EmailSchedulingData> createValueTemplate() throws IOException { RedisTemplate<String, EmailSchedulingData> template = new RedisTemplate<>(); RedisSerializer<String> stringSerializer = new StringRedisSerializer(); JdkSerializationRedisSerializer jdkSerializationRedisSerializer = new JdkSerializationRedisSerializer(); template.setKeySerializer(stringSerializer); template.setValueSerializer(jdkSerializationRedisSerializer); template.setHashKeySerializer(stringSerializer); template.setHashValueSerializer(stringSerializer); template.setConnectionFactory(redisConnectionFactory); template.setEnableTransactionSupport(true); template.afterPropertiesSet(); return template; }
Example #10
Source File: DefaultPersistenceService.java From spring-boot-email-tools with Apache License 2.0 | 6 votes |
@Autowired public DefaultPersistenceService(@Qualifier("orderingTemplate") @NonNull final StringRedisTemplate orderingTemplate, @Qualifier("valueTemplate") @NonNull final RedisTemplate<String, EmailSchedulingData> valueTemplate) { this.orderingTemplate = orderingTemplate; this.orderingTemplate.setEnableTransactionSupport(true); this.valueTemplate = valueTemplate; RedisSerializer<String> stringSerializer = new StringRedisSerializer(); JdkSerializationRedisSerializer jdkSerializationRedisSerializer = new JdkSerializationRedisSerializer(); this.valueTemplate.setKeySerializer(stringSerializer); this.valueTemplate.setValueSerializer(jdkSerializationRedisSerializer); this.valueTemplate.setHashKeySerializer(stringSerializer); this.valueTemplate.setHashValueSerializer(stringSerializer); this.valueTemplate.setEnableTransactionSupport(true); this.valueTemplate.afterPropertiesSet(); }
Example #11
Source File: JsonSerializerUtil.java From scaffold-cloud with MIT License | 5 votes |
/** * 默认方式序列化对象 * * @return */ public static byte[] serializeByDefaultSerializable(final Object object) { try { if (object != null) { return new JdkSerializationRedisSerializer().serialize(object); } } catch (Exception e) { LOGGER.error(e.getMessage(), e); } return new byte[0]; }
Example #12
Source File: RedisWebSessionConfiguration.java From spring-session with Apache License 2.0 | 5 votes |
private ReactiveRedisTemplate<String, Object> createReactiveRedisTemplate() { RedisSerializer<String> keySerializer = new StringRedisSerializer(); RedisSerializer<Object> defaultSerializer = (this.defaultRedisSerializer != null) ? this.defaultRedisSerializer : new JdkSerializationRedisSerializer(this.classLoader); RedisSerializationContext<String, Object> serializationContext = RedisSerializationContext .<String, Object>newSerializationContext(defaultSerializer).key(keySerializer).hashKey(keySerializer) .build(); return new ReactiveRedisTemplate<>(this.redisConnectionFactory, serializationContext); }
Example #13
Source File: EmailRedisTemplateConfigurationTest.java From spring-boot-email-tools with Apache License 2.0 | 5 votes |
@Test public void createValueTemplate() throws Exception { //Act RedisTemplate<String, EmailSchedulingData> template = emailRedisTemplateConfiguration.createValueTemplate(); //Assert assertions.assertThat(template).isNotNull(); assertions.assertThat(template.getKeySerializer()).isInstanceOf(StringRedisSerializer.class); assertions.assertThat(template.getHashKeySerializer()).isInstanceOf(StringRedisSerializer.class); assertions.assertThat(template.getHashValueSerializer()).isInstanceOf(StringRedisSerializer.class); assertions.assertThat(template.getValueSerializer()).isInstanceOf(JdkSerializationRedisSerializer.class); }
Example #14
Source File: BaseRedisTest.java From spring-boot-email-tools with Apache License 2.0 | 5 votes |
@Bean("valueTemplate") public RedisTemplate<String, EmailSchedulingData> createValueTemplate() throws IOException { RedisTemplate<String, EmailSchedulingData> template = new RedisTemplate<>(); RedisSerializer<String> stringSerializer = new StringRedisSerializer(); JdkSerializationRedisSerializer jdkSerializationRedisSerializer = new JdkSerializationRedisSerializer(); template.setKeySerializer(stringSerializer); template.setValueSerializer(jdkSerializationRedisSerializer); template.setHashKeySerializer(stringSerializer); template.setHashValueSerializer(stringSerializer); template.setConnectionFactory(connectionFactory); template.setEnableTransactionSupport(true); template.afterPropertiesSet(); return template; }
Example #15
Source File: RedisConfiguration.java From tx-lcn with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnClass(name = "org.springframework.data.redis.connection.RedisConnectionFactory") public RedisTemplate<String, Object> functionDomainRedisTemplate(RedisConnectionFactory redisConnectionFactory) { JdkSerializationRedisSerializer serializationRedisSerializer = new JdkSerializationRedisSerializer(); StringRedisSerializer stringRedisSerializer = new StringRedisSerializer(); RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>(); redisTemplate.setKeySerializer(stringRedisSerializer); redisTemplate.setHashKeySerializer(stringRedisSerializer); redisTemplate.setHashValueSerializer(serializationRedisSerializer); redisTemplate.setValueSerializer(serializationRedisSerializer); redisTemplate.setConnectionFactory(redisConnectionFactory); return redisTemplate; }
Example #16
Source File: RedisConfiguration.java From heimdall with Apache License 2.0 | 5 votes |
/** * Returns a configured {@link RedisTemplate}. * * @return {@link RedisTemplate} Object, Object */ @Bean public RedisTemplate<Object, Object> redisTemplateObject() { RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<Object, Object>(); redisTemplate.setConnectionFactory(jedisConnectionFactory()); redisTemplate.setKeySerializer(new StringRedisSerializer()); redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer()); redisTemplate.setHashKeySerializer(new StringRedisSerializer()); redisTemplate.setHashValueSerializer(new JdkSerializationRedisSerializer()); return redisTemplate; }
Example #17
Source File: RedisConfiguration.java From heimdall with Apache License 2.0 | 5 votes |
/** * Configures and returns {@link RedisTemplate} with Object and Object. * * @return {@link RedisTemplate} */ @Bean public RedisTemplate<Object, Object> redisTemplateObject() { RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<Object, Object>(); redisTemplate.setConnectionFactory(jedisConnectionFactory()); redisTemplate.setKeySerializer(new StringRedisSerializer()); redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer()); redisTemplate.setHashKeySerializer(new StringRedisSerializer()); redisTemplate.setHashValueSerializer(new JdkSerializationRedisSerializer()); return redisTemplate; }
Example #18
Source File: RedisCacheConfig.java From agile-service-old with Apache License 2.0 | 5 votes |
/** * 设置数据存入 redis 的序列化方式 * * @param redisTemplate redisTemplate * @param factory factory */ private void initDomainRedisTemplate(RedisTemplate<String, Object> redisTemplate, RedisConnectionFactory factory) { redisTemplate.setKeySerializer(new StringRedisSerializer()); redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer()); redisTemplate.setHashKeySerializer(new StringRedisSerializer()); redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer()); redisTemplate.setConnectionFactory(factory); }
Example #19
Source File: RedisCacheConfig.java From pig with MIT License | 5 votes |
@Bean public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) { RedisTemplate<String, Object> template = new RedisTemplate<>(); template.setConnectionFactory(factory); template.setKeySerializer(new StringRedisSerializer()); template.setValueSerializer(new JdkSerializationRedisSerializer()); return template; }
Example #20
Source File: TcpChannelMsgManage.java From jt809-tcp-server with MIT License | 5 votes |
@Autowired public void setRedisTemplate(RedisTemplate redisTemplate) { RedisSerializer stringSerializer = new StringRedisSerializer(); RedisSerializer jdkSerializer = new JdkSerializationRedisSerializer(); redisTemplate.setKeySerializer(stringSerializer); redisTemplate.setValueSerializer(stringSerializer); redisTemplate.setHashKeySerializer(stringSerializer); redisTemplate.setHashValueSerializer(jdkSerializer); redisTemplate.afterPropertiesSet(); this.redisTemplate = redisTemplate; }
Example #21
Source File: JsonSerializerUtil.java From scaffold-cloud with MIT License | 5 votes |
/** * 默认方式反序列化对象 * * @param bytes * @return */ public static Object unserializeByDefaultSerializable(byte[] bytes) { try { if (bytes != null && bytes.length > 0) { return new JdkSerializationRedisSerializer().deserialize(bytes); } } catch (Exception e) { LOGGER.error(e.getMessage(), e); } return null; }
Example #22
Source File: RedisTokenManager.java From SpringCloud-Shop with Apache License 2.0 | 4 votes |
@Autowired public void setRedis (@Qualifier("stringRedisTemplate") RedisTemplate redis) { this.redis = redis; // 泛型设置成 Long 后必须更改对应的序列 化方案 redis.setKeySerializer (new JdkSerializationRedisSerializer()); }
Example #23
Source File: RedisTemplateConfiguration.java From blade-tool with GNU Lesser General Public License v3.0 | 4 votes |
/** * value 值 序列化 * * @return RedisSerializer */ @Bean @ConditionalOnMissingBean(RedisSerializer.class) public RedisSerializer<Object> redisSerializer() { return new JdkSerializationRedisSerializer(); }
Example #24
Source File: JedisCacheService.java From howsun-javaee-framework with Apache License 2.0 | 4 votes |
public JdkSerializationRedisSerializer getSerializer() { return serializer; }
Example #25
Source File: JedisCacheService.java From howsun-javaee-framework with Apache License 2.0 | 4 votes |
public void setSerializer(JdkSerializationRedisSerializer serializer) { this.serializer = serializer; }