當前位置: 首頁>>代碼示例>>Java>>正文


Java RedisTemplate.setValueSerializer方法代碼示例

本文整理匯總了Java中org.springframework.data.redis.core.RedisTemplate.setValueSerializer方法的典型用法代碼示例。如果您正苦於以下問題:Java RedisTemplate.setValueSerializer方法的具體用法?Java RedisTemplate.setValueSerializer怎麽用?Java RedisTemplate.setValueSerializer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.data.redis.core.RedisTemplate的用法示例。


在下文中一共展示了RedisTemplate.setValueSerializer方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: redisTemplate

import org.springframework.data.redis.core.RedisTemplate; //導入方法依賴的package包/類
@Bean(name="redisTemplate")
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {

    RedisTemplate<String, String> template = new RedisTemplate<>();


    RedisSerializer<String> redisSerializer = new StringRedisSerializer();

    Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
    ObjectMapper om = new ObjectMapper();
    om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
    om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
    jackson2JsonRedisSerializer.setObjectMapper(om);

    template.setConnectionFactory(factory);
    //key序列化方式
    template.setKeySerializer(redisSerializer);
    //value序列化
    template.setValueSerializer(jackson2JsonRedisSerializer);
    //value hashmap序列化
    template.setHashValueSerializer(jackson2JsonRedisSerializer);

    return template;
}
 
開發者ID:cwenao,項目名稱:springboot_cwenao,代碼行數:25,代碼來源:RedisConfig.java

示例2: buildRedisTemplate

import org.springframework.data.redis.core.RedisTemplate; //導入方法依賴的package包/類
public static RedisTemplate buildRedisTemplate(byte[] redisProperties){
    JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(
            RedisConfUtils.getClusterConfiguration(
                    (RedisProperties) Serializer.INSTANCE.deserialize(redisProperties)));
    RedisTemplate<String, Long> redisTemplate = new RedisTemplate<>();
    redisTemplate.setConnectionFactory(jedisConnectionFactory);
    jedisConnectionFactory.afterPropertiesSet();

    GenericJackson2JsonRedisSerializer genericJackson2JsonRedisSerializer = new GenericJackson2JsonRedisSerializer();
    StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
    redisTemplate.setKeySerializer(stringRedisSerializer);
    redisTemplate.setValueSerializer(genericJackson2JsonRedisSerializer);
    redisTemplate.setHashKeySerializer(stringRedisSerializer);
    redisTemplate.setHashValueSerializer(genericJackson2JsonRedisSerializer);
    redisTemplate.afterPropertiesSet();
    return redisTemplate;
}
 
開發者ID:Paleozoic,項目名稱:storm_spring_boot_demo,代碼行數:18,代碼來源:RedisConfUtils.java

示例3: redisTemplate

import org.springframework.data.redis.core.RedisTemplate; //導入方法依賴的package包/類
@Bean
@Primary
RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory rcf) {
	AitLogger.debug(logger, "Serializer overriding ");

	RedisTemplate<String, Object> template = new RedisTemplate<>();
	template.setConnectionFactory(rcf);

	GenericJackson2JsonRedisSerializer valSerializer = new GenericJackson2JsonRedisSerializer();

	template.setValueSerializer(valSerializer);
	template.setKeySerializer(new RedisSerializer<Object>() {

		@Override
		public byte[] serialize(Object t) throws SerializationException {
			return (t == null ? null : (":" + t.toString()).getBytes());
		}

		@Override
		public Object deserialize(byte[] bytes) throws SerializationException {
			return (bytes == null ? null : new String(bytes));
		}
	});
	template.setHashValueSerializer(valSerializer);
	return template;
}
 
開發者ID:allianzit,項目名稱:ait-platform,代碼行數:27,代碼來源:AitCacheConfigBase.java

示例4: redisTemplate

import org.springframework.data.redis.core.RedisTemplate; //導入方法依賴的package包/類
@Bean
public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
    RedisTemplate<Object, Object> template = new RedisTemplate<>();
    template.setConnectionFactory(connectionFactory);

    //使用Jackson2JsonRedisSerializer來序列化和反序列化redis的value值
    Jackson2JsonRedisSerializer serializer = new Jackson2JsonRedisSerializer(Object.class);

    ObjectMapper mapper = new ObjectMapper();
    mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
    mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
    serializer.setObjectMapper(mapper);

    template.setValueSerializer(serializer);
    //使用StringRedisSerializer來序列化和反序列化redis的key值
    template.setKeySerializer(new StringRedisSerializer());
    template.afterPropertiesSet();
    return template;
}
 
開發者ID:fanqinghui,項目名稱:action,代碼行數:20,代碼來源:RedisUtil.java

示例5: jsonRedisTemplate

import org.springframework.data.redis.core.RedisTemplate; //導入方法依賴的package包/類
private RedisTemplate jsonRedisTemplate(JedisConnectionFactory jedisConnectionFactory, Class<?> clazz) {
    RedisTemplate template = new RedisTemplate();
    template.setKeySerializer(new StringRedisSerializer());
    template.setValueSerializer(new Jackson2JsonRedisSerializer(clazz));
    template.setHashKeySerializer(new StringRedisSerializer());
    template.setHashValueSerializer(new Jackson2JsonRedisSerializer(clazz));
    template.setConnectionFactory(jedisConnectionFactory);
    return template;
}
 
開發者ID:veritasware,項目名稱:neto,代碼行數:10,代碼來源:AppConfig.java

示例6: redisTemplate

import org.springframework.data.redis.core.RedisTemplate; //導入方法依賴的package包/類
@Bean
public <K, V> RedisTemplate<K, V> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
    RedisTemplate<K, V> template = new RedisTemplate<>();
    template.setConnectionFactory(redisConnectionFactory);
    template.setKeySerializer(new StringRedisSerializer());
    template.setHashKeySerializer(new StringRedisSerializer());
    template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
    template.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
    template.setEnableTransactionSupport(true);
    template.afterPropertiesSet();
    return template;
}
 
開發者ID:tong12580,項目名稱:OutsourcedProject,代碼行數:13,代碼來源:RedisConfig.java

示例7: redisTemplate

import org.springframework.data.redis.core.RedisTemplate; //導入方法依賴的package包/類
@Bean
public RedisTemplate<String, Object> redisTemplate() {
    final RedisTemplate<String, Object> template = new RedisTemplate<String, Object>();
    template.setConnectionFactory(jedisConnectionFactory());
    template.setValueSerializer(new GenericToStringSerializer<Object>(Object.class));
    return template;
}
 
開發者ID:iyzico,項目名稱:boot-mon,代碼行數:8,代碼來源:BootmonServerRedisConfig.java

示例8: redisListTemplate

import org.springframework.data.redis.core.RedisTemplate; //導入方法依賴的package包/類
@Bean(name = "redisListTemplate")
RedisTemplate<String, Long> redisListTemplate() {
    RedisTemplate<String, Long> redisTemplate = new RedisTemplate<>();
    redisTemplate.setConnectionFactory(jedisConnectionFactory());
    redisTemplate.setKeySerializer(new StringRedisSerializer());
    redisTemplate.setValueSerializer(new GenericToStringSerializer<>(Long.class));
    return redisTemplate;
}
 
開發者ID:ugouku,項目名稱:shoucang,代碼行數:9,代碼來源:RedisConfiguration.java

示例9: initRedisTemplate

import org.springframework.data.redis.core.RedisTemplate; //導入方法依賴的package包/類
/**
 * 序列化設置
 */
private void initRedisTemplate(RedisTemplate<String, String> redisTemplate, RedisConnectionFactory factory) {
    redisTemplate.setKeySerializer(new StringRedisSerializer());
    redisTemplate.setHashKeySerializer(new StringRedisSerializer());
    redisTemplate.setHashValueSerializer(new JdkSerializationRedisSerializer());
    redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer());
    redisTemplate.setConnectionFactory(factory);
}
 
開發者ID:SnackMen,項目名稱:DanmuChat,代碼行數:11,代碼來源:RedisConfig.java

示例10: createCacheRedisTemplate

import org.springframework.data.redis.core.RedisTemplate; //導入方法依賴的package包/類
private RedisTemplate<String, String> createCacheRedisTemplate(final RedisConnectionFactory redisConnectionFactory,
        final String redisTemplateType) {
    RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
    redisTemplate.setConnectionFactory(redisConnectionFactory);
    redisTemplate.setDefaultSerializer(new StringRedisSerializer());
    redisTemplate.setKeySerializer(new StringRedisSerializer());
    redisTemplate.setValueSerializer(new StringRedisSerializer());
    LOGGER.info("Successfully created {} Redis template.", redisTemplateType);
    return redisTemplate;
}
 
開發者ID:eclipse,項目名稱:keti,代碼行數:11,代碼來源:CommonRedisConfig.java

示例11: getRedisTemplate

import org.springframework.data.redis.core.RedisTemplate; //導入方法依賴的package包/類
@Bean("redisTemplate")
public RedisTemplate<?, ?> getRedisTemplate(){
    RedisTemplate<?,?> template = new StringRedisTemplate(jedisConnectionFactory);
    GenericJackson2JsonRedisSerializer genericJackson2JsonRedisSerializer = new GenericJackson2JsonRedisSerializer();
    StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
    template.setKeySerializer(stringRedisSerializer);
    template.setValueSerializer(genericJackson2JsonRedisSerializer);
    template.setHashKeySerializer(stringRedisSerializer);
    template.setHashValueSerializer(genericJackson2JsonRedisSerializer);
    return template;
}
 
開發者ID:Paleozoic,項目名稱:storm_spring_boot_demo,代碼行數:12,代碼來源:RedisConfig.java

示例12: stringRedisTemplate

import org.springframework.data.redis.core.RedisTemplate; //導入方法依賴的package包/類
@Bean
public RedisTemplate stringRedisTemplate(RedisConnectionFactory redisConnectionFactory) {
    RedisTemplate redisTemplate = new RedisTemplate();
    redisTemplate.setConnectionFactory(redisConnectionFactory);
    redisTemplate.setEnableDefaultSerializer(true);
    redisTemplate.setDefaultSerializer(new StringRedisSerializer());
    redisTemplate.setKeySerializer(new StringRedisSerializer());
    redisTemplate.setValueSerializer(new StringRedisSerializer());
    //redisTemplate.setEnableTransactionSupport(true);
    redisTemplate.afterPropertiesSet();
    return redisTemplate;
}
 
開發者ID:lupindong,項目名稱:xq_seckill_microservice,代碼行數:13,代碼來源:CachingConfig.java

示例13: redisTemplate

import org.springframework.data.redis.core.RedisTemplate; //導入方法依賴的package包/類
@Bean
public RedisTemplate<String, User> redisTemplate(RedisConnectionFactory factory) {
    RedisTemplate<String, User> template = new RedisTemplate<>();
    template.setConnectionFactory(jedisConnectionFactory());
    template.setKeySerializer(new StringRedisSerializer());
    template.setValueSerializer(new RedisObjectSerializer());
    return template;
}
 
開發者ID:nellochen,項目名稱:springboot-start,代碼行數:9,代碼來源:RedisConfig.java

示例14: redisTemplate

import org.springframework.data.redis.core.RedisTemplate; //導入方法依賴的package包/類
@Bean(name = "redisTemplate")
public RedisTemplate<String, SysUserEntity> redisTemplate(RedisConnectionFactory factory) {
    RedisTemplate<String, SysUserEntity> template = new RedisTemplate<String, SysUserEntity>();
    template.setConnectionFactory(jedisConnectionFactory());
    template.setKeySerializer(new StringRedisSerializer());
    template.setValueSerializer(new RedisObjectSerializer());
    return template;
}
 
開發者ID:guolf,項目名稱:pds,代碼行數:9,代碼來源:RedisConfig.java

示例15: redisTemplate

import org.springframework.data.redis.core.RedisTemplate; //導入方法依賴的package包/類
@Bean
public RedisTemplate<Object, Object> redisTemplate() {
  RedisTemplate<Object, Object> template = new RedisTemplate<>();
  template.setConnectionFactory(connectionFactory());
  template.setHashKeySerializer(new GenericToStringSerializer<>(UUID.class));
  template.setKeySerializer(new GenericToStringSerializer<>(UUID.class));
  template.setHashValueSerializer(new GenericToStringSerializer<>(Object.class));
  template.setValueSerializer(new GenericToStringSerializer<>(Object.class));
  return template;
}
 
開發者ID:dembros,項目名稱:containerized,代碼行數:11,代碼來源:DemoApplication.java


注:本文中的org.springframework.data.redis.core.RedisTemplate.setValueSerializer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。