List of usage examples for org.springframework.data.redis.core RedisTemplate RedisTemplate
public RedisTemplate()
RedisTemplate
instance. From source file:be.ordina.msdashboard.config.RedisConfiguration.java
@Bean public RedisTemplate<String, Object> redisTemplate(final RedisConnectionFactory factory) { RedisTemplate<String, Object> virtualNodeTemplate = new RedisTemplate<>(); virtualNodeTemplate.setConnectionFactory(factory); virtualNodeTemplate.setKeySerializer(new StringRedisSerializer()); virtualNodeTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer()); return virtualNodeTemplate; }
From source file:com.ge.predix.acs.config.CloudRedisConfig.java
@Bean public RedisTemplate<String, String> redisTemplate() { 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."); return redisTemplate; }
From source file:com.company.project.config.DataConfig.java
@Bean public RedisTemplate<String, Object> redisTemplate() { // RedisTemplate<String, Blog> template = new RedisTemplate<>(); // template.setConnectionFactory(redisConfig.redisConnectionFactory()); // template.setKeySerializer(new StringRedisSerializer()); // template.setValueSerializer(new JacksonJsonRedisSerializer<>(Blog.class)); // template.setHashKeySerializer(new StringRedisSerializer()); // template.setHashValueSerializer(new JacksonJsonRedisSerializer<>(Blog.class)); // return template; //RedisTemplate<String, String> template = new StringRedisTemplate(redisConnectionFactory()); RedisTemplate<String, Object> template = new RedisTemplate(); template.setConnectionFactory(redisConnectionFactory()); // explicitly enable transaction support - 4.9.1. @Transactional Support http://docs.spring.io/spring-data/redis/docs/current/reference/html/ template.setEnableTransactionSupport(true); return template; }
From source file:org.shareok.data.redis.UserDaoImpl.java
@Transactional public void test2() { RedisTemplate<String, Object> redis = new RedisTemplate<>(); redis.setConnectionFactory(connectionFactory); // redis.setKeySerializer(ApplicationConfig.StringSerializer.INSTANCE); // redis.setValueSerializer(new JacksonJsonRedisSerializer<User>(UserDaoImpl.class)); redis.afterPropertiesSet();//from w ww. ja v a2 s .c o m redis.setEnableTransactionSupport(true);//???redistemplate? redis.multi(); redis.boundValueOps("somevkey").increment(1); redis.boundZSetOps("somezkey").add("zvalue", 11); redis.exec(); redis.setEnableTransactionSupport(false); }
From source file:org.springframework.integration.redis.outbound.RedisCollectionPopulatingMessageHandler.java
/** * Will construct this instance using the provided {@link RedisConnectionFactory} and {@link #keyExpression} * It will create an instance of {@link RedisTemplate} initializing it with a * {@link StringRedisSerializer} for the keySerializer and a {@link JdkSerializationRedisSerializer} * for each of valueSerializer, hasKeySerializer, and hashValueSerializer. * * If {@link #keyExpression} is null, the default expression 'headers.{@link RedisHeaders#KEY}' * will be used./*from w w w . j a v a 2 s . co m*/ * * @param connectionFactory * @param keyExpression */ public RedisCollectionPopulatingMessageHandler(RedisConnectionFactory connectionFactory, Expression keyExpression) { Assert.notNull(connectionFactory, "'connectionFactory' must not be null"); RedisTemplate<String, Object> redisTemplate = new RedisTemplate<String, Object>(); redisTemplate.setConnectionFactory(connectionFactory); redisTemplate.setKeySerializer(new StringRedisSerializer()); redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer()); redisTemplate.setHashKeySerializer(new JdkSerializationRedisSerializer()); redisTemplate.setHashValueSerializer(new JdkSerializationRedisSerializer()); this.redisTemplate = redisTemplate; if (keyExpression != null) { this.keyExpression = keyExpression; } }
From source file:org.springframework.integration.redis.outbound.RedisStoreWritingMessageHandler.java
@Override protected void onInit() throws Exception { this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(this.getBeanFactory()); Assert.state(!this.mapKeyExpressionExplicitlySet || (this.collectionType == CollectionType.MAP || this.collectionType == CollectionType.PROPERTIES), "'mapKeyExpression' can only be set for CollectionType.MAP or CollectionType.PROPERTIES"); if (!this.redisTemplateExplicitlySet) { if (!this.extractPayloadElements) { RedisTemplate<String, Object> template = new RedisTemplate<String, Object>(); StringRedisSerializer serializer = new StringRedisSerializer(); template.setKeySerializer(serializer); template.setHashKeySerializer(serializer); this.redisTemplate = template; }// w w w .j a v a2s. com this.redisTemplate.setConnectionFactory(this.connectionFactory); this.redisTemplate.afterPropertiesSet(); } this.initialized = true; }
From source file:org.springframework.integration.redis.util.RedisLockRegistry.java
/** * Constructs a lock registry with the supplied lock expiration and a custom local {@link LockRegistry}. * @param connectionFactory The connection factory. * @param registryKey The key prefix for locks. * @param expireAfter The expiration in milliseconds. * @param localRegistry The local registry used to reduce wait time, * {@link DefaultLockRegistry} is used by default. *///from ww w. j a va 2 s.c o m public RedisLockRegistry(RedisConnectionFactory connectionFactory, String registryKey, long expireAfter, LockRegistry localRegistry) { Assert.notNull(connectionFactory, "'connectionFactory' cannot be null"); Assert.notNull(registryKey, "'registryKey' cannot be null"); Assert.notNull(localRegistry, "'localRegistry' cannot be null"); this.redisTemplate = new RedisTemplate<>(); this.redisTemplate.setConnectionFactory(connectionFactory); this.redisTemplate.setKeySerializer(new StringRedisSerializer()); this.redisTemplate.setValueSerializer(this.lockSerializer); this.redisTemplate.afterPropertiesSet(); this.registryKey = registryKey; this.expireAfter = expireAfter; this.localRegistry = localRegistry; }
From source file:org.springframework.integration.redis.util.RedisLockRegistryTests.java
private RedisTemplate<String, ?> createTemplate() { RedisTemplate<String, ?> template = new RedisTemplate<>(); template.setConnectionFactory(this.getConnectionFactoryForTest()); template.setKeySerializer(new StringRedisSerializer()); template.afterPropertiesSet();/*from w ww .j av a 2 s . c o m*/ return template; }
From source file:org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration.java
private RedisTemplate<Object, Object> createRedisTemplate() { RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<>(); redisTemplate.setKeySerializer(new StringRedisSerializer()); redisTemplate.setHashKeySerializer(new StringRedisSerializer()); if (this.defaultRedisSerializer != null) { redisTemplate.setDefaultSerializer(this.defaultRedisSerializer); }/*from ww w . j a v a 2s . co m*/ redisTemplate.setConnectionFactory(this.redisConnectionFactory); redisTemplate.setBeanClassLoader(this.classLoader); redisTemplate.afterPropertiesSet(); return redisTemplate; }
From source file:org.springframework.session.data.redis.RedisOperationsSessionRepository.java
private static RedisTemplate<Object, Object> createDefaultTemplate(RedisConnectionFactory connectionFactory) { Assert.notNull(connectionFactory, "connectionFactory cannot be null"); RedisTemplate<Object, Object> template = new RedisTemplate<Object, Object>(); template.setKeySerializer(new StringRedisSerializer()); template.setHashKeySerializer(new StringRedisSerializer()); template.setConnectionFactory(connectionFactory); template.afterPropertiesSet();//from w w w . j ava 2s .c om return template; }