当前位置: 首页>>代码示例>>Java>>正文


Java RedisTemplate类代码示例

本文整理汇总了Java中org.springframework.data.redis.core.RedisTemplate的典型用法代码示例。如果您正苦于以下问题:Java RedisTemplate类的具体用法?Java RedisTemplate怎么用?Java RedisTemplate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RedisTemplate类属于org.springframework.data.redis.core包,在下文中一共展示了RedisTemplate类的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包/类
/**
 * RedisTemplate配置
 * @param factory
 * @return
 */
@Bean
@SuppressWarnings({"rawtypes", "unchecked"})
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
    StringRedisTemplate template = new StringRedisTemplate(factory);
    //定义value的序列化方式
    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.setValueSerializer(jackson2JsonRedisSerializer);
    template.setHashValueSerializer(jackson2JsonRedisSerializer);
    template.afterPropertiesSet();
    return template;
}
 
开发者ID:SnailFastGo,项目名称:springboot_op,代码行数:22,代码来源:RedisConfiguration.java

示例5: cacheManager

import org.springframework.data.redis.core.RedisTemplate; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
@Bean
public CacheManager cacheManager(RedisTemplate redisTemplate) {
    RedisCacheManager rcm = new RedisCacheManager(redisTemplate);
    //设置缓存过期时间
    //rcm.setDefaultExpiration(60);//秒
    return rcm;
}
 
开发者ID:ChinaLHR,项目名称:JavaQuarkBBS,代码行数:9,代码来源:RedisConfig.java

示例6: redisTemplate

import org.springframework.data.redis.core.RedisTemplate; //导入依赖的package包/类
@Bean("redisTemplate")  //新家的这个注解 10-26 12:06
@SuppressWarnings({ "rawtypes", "unchecked" })
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory redisFactory){
	StringRedisTemplate template = new StringRedisTemplate(redisFactory);
	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.setValueSerializer(jackson2JsonRedisSerializer);
	template.afterPropertiesSet();
	return template;
}
 
开发者ID:duanyaxin,项目名称:springboot-smart,代码行数:17,代码来源:RedisConfiguration.java

示例7: 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

示例8: cacheManager

import org.springframework.data.redis.core.RedisTemplate; //导入依赖的package包/类
@Bean
public CacheManager cacheManager ( RedisTemplate redisTemplate ) {
	RedisCacheManager redisCacheManager = new RedisCacheManager( redisTemplate );
	// 默认30分钟
	redisCacheManager.setDefaultExpiration( defaultExpiration );
	redisCacheManager.setExpires( expires );
	redisCacheManager.setUsePrefix( usePrefix );
	return redisCacheManager;
}
 
开发者ID:yujunhao8831,项目名称:spring-boot-start-current,代码行数:10,代码来源:SpringCacheConfig.java

示例9: createAttributeCache

import org.springframework.data.redis.core.RedisTemplate; //导入依赖的package包/类
private AttributeCache createAttributeCache(final String cacheType, final long maxCachedIntervalMinutes,
        final String zoneName, final RedisTemplate<String, String> cacheRedisTemplate,
        final BiFunction<String, String, String> getKey, final boolean enableAttributeCaching) {
    String[] profiles = environment.getActiveProfiles();

    if (!enableAttributeCaching) {
        LOGGER.info("Caching disabled for {} attributes.", cacheType);
        return new NonCachingAttributeCache();
    }
    if (ArrayUtils.contains(profiles, "redis") || ArrayUtils.contains(profiles, "cloud-redis")) {
        LOGGER.info("Redis caching enabled for {} attributes.", cacheType);
        return new RedisAttributeCache(maxCachedIntervalMinutes, zoneName, getKey, cacheRedisTemplate);
    }
    LOGGER.info("In-memory caching enabled for {} attributes.", cacheType);
    return new InMemoryAttributeCache(maxCachedIntervalMinutes, zoneName, getKey);
}
 
开发者ID:eclipse,项目名称:keti,代码行数:17,代码来源:AttributeCacheFactory.java

示例10: redisTemplate

import org.springframework.data.redis.core.RedisTemplate; //导入依赖的package包/类
@Bean(name = "redisTemplate")
public RedisTemplate<String,?> redisTemplate(@Qualifier("mafConnectionFactory") RedisConnectionFactory factory) {
    RedisTemplate<String,?> template = new RedisTemplate<>();
    template.setConnectionFactory(factory);
    template.setKeySerializer(new StringRedisSerializer());
    template.afterPropertiesSet();
    return template;
}
 
开发者ID:slking1987,项目名称:mafia,代码行数:9,代码来源:RedisConfig.java

示例11: getStringRedisTemplate

import org.springframework.data.redis.core.RedisTemplate; //导入依赖的package包/类
@Bean
public RedisTemplate getStringRedisTemplate() {
    StringRedisTemplate clusterTemplate = new StringRedisTemplate();
    clusterTemplate.setConnectionFactory(jedisConnectionFactory());
    clusterTemplate.setKeySerializer(new StringRedisSerializer());
    clusterTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
    return clusterTemplate;
}
 
开发者ID:yu199195,项目名称:happylifeplat-transaction,代码行数:9,代码来源:RedisClusterConfig.java

示例12: test

import org.springframework.data.redis.core.RedisTemplate; //导入依赖的package包/类
@org.junit.Test
public void test(){
    String  user_prefix="user_";
    User user=new User(1,"aric");
    ApplicationContext atc=new AnnotationConfigApplicationContext(RedisStartConfig.class);
    RedisTemplate<String,User> obj = (RedisTemplate) atc.getBean("redisTemplate");
    PrinterUtils.printILog(obj.getKeySerializer());
    obj.opsForValue().set(user_prefix+user.getId(),user);
    RedisSentinelConfiguration RedisSentinelConfiguration = (RedisSentinelConfiguration) atc.getBean("sentinelConfig");
    PrinterUtils.printILog(RedisSentinelConfiguration);
    User value=obj.opsForValue().get(user_prefix+1);
    PrinterUtils.printELog(value.getUsername());
}
 
开发者ID:tomoncle,项目名称:JavaStudy,代码行数:14,代码来源:Test.java

示例13: redisTemplate

import org.springframework.data.redis.core.RedisTemplate; //导入依赖的package包/类
@SuppressWarnings({"unchecked","rawtypes"})
@Bean  
   public RedisTemplate<String, String> redisTemplate(  
           RedisConnectionFactory factory) {  
       StringRedisTemplate template = new StringRedisTemplate(factory);  
	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.setValueSerializer(jackson2JsonRedisSerializer);  
       template.afterPropertiesSet();  
       return template;  
   }
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:15,代码来源:RedisConfig.java

示例14: redisTemplate

import org.springframework.data.redis.core.RedisTemplate; //导入依赖的package包/类
@Bean
public RedisTemplate<String, Phrase> redisTemplate() {
    @SuppressWarnings("unchecked")
	RedisTemplate<String, Phrase> template = mock(RedisTemplate.class);
    opsHash = new HashOperationsMock();
	when(template.opsForHash()).thenReturn(opsHash);
    return template;
}
 
开发者ID:davidgamez,项目名称:parrot-rest,代码行数:9,代码来源:ApplicationTestConfiguration.java

示例15: redisTemplate

import org.springframework.data.redis.core.RedisTemplate; //导入依赖的package包/类
@Bean
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
    StringRedisTemplate template = new StringRedisTemplate(factory);
    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.setValueSerializer(jackson2JsonRedisSerializer);
    template.afterPropertiesSet();
    return template;
}
 
开发者ID:ChinaLHR,项目名称:JavaQuarkBBS,代码行数:13,代码来源:RedisConfig.java


注:本文中的org.springframework.data.redis.core.RedisTemplate类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。