List of usage examples for org.springframework.data.redis.core RedisTemplate afterPropertiesSet
@Override public void afterPropertiesSet()
From source file:locksdemo.RedisUtils.java
static <K, V> RedisTemplate<K, V> createRedisTemplate(RedisConnectionFactory connectionFactory, Class<V> valueClass) { RedisTemplate<K, V> redisTemplate = new RedisTemplate<K, V>(); redisTemplate.setKeySerializer(new StringRedisSerializer()); redisTemplate.setValueSerializer(new GenericToStringSerializer<V>(valueClass)); // avoids proxy redisTemplate.setExposeConnection(true); redisTemplate.setConnectionFactory(connectionFactory); redisTemplate.afterPropertiesSet(); return redisTemplate; }
From source file:com.miko.demo.mongo.service.RedisRemovalTest.java
@Test public void removalKeyValueTest() { RedisTemplate<String, Long> redis = new RedisTemplate<>(); redis.setConnectionFactory(connectionFactory); redis.setKeySerializer(RedisStringSerializer.INSTANCE); redis.setValueSerializer(RedisLongSerializer.INSTANCE); redis.afterPropertiesSet(); ValueOperations<String, Long> ops = redis.opsForValue(); String key1 = "miko-spring-mongo:counter-test"; String key2 = "miko-spring-mongo:counter-test-2"; Set<String> keys = redis.keys(key1); for (String foundKey : keys) { logger.debug("Found Key= " + foundKey + " value= " + ops.get(foundKey)); }//from ww w .ja v a 2s.c o m redis.delete(key2); }
From source file:com.miko.demo.postgresql.service.RedisRemovalTest.java
@Test public void removalKeyValueTest() { RedisTemplate<String, Long> redis = new RedisTemplate<>(); redis.setConnectionFactory(connectionFactory); redis.setKeySerializer(RedisStringSerializer.INSTANCE); redis.setValueSerializer(RedisLongSerializer.INSTANCE); redis.afterPropertiesSet(); ValueOperations<String, Long> ops = redis.opsForValue(); String key1 = "miko-spring-postgresql:counter-test"; String key2 = "miko-spring-postgresql:counter-test-2"; Set<String> keys = redis.keys(key1); for (String foundKey : keys) { logger.debug("Found Key= " + foundKey + " value= " + ops.get(foundKey)); }//from ww w.ja va 2s . c o m redis.delete(key2); }
From source file:com.miko.demo.mongo.service.RedisInitTest.java
@Test public void testKeyValue() { RedisTemplate<String, Long> redis = new RedisTemplate<>(); redis.setConnectionFactory(connectionFactory); redis.setKeySerializer(RedisStringSerializer.INSTANCE); redis.setValueSerializer(RedisLongSerializer.INSTANCE); redis.afterPropertiesSet(); ValueOperations<String, Long> ops = redis.opsForValue(); String key = "spring-postgresql:counter-test"; Long value = ops.get(key);/* w ww . ja v a 2 s . c o m*/ logger.debug("VALUE = " + value); assertThat(value, notNullValue()); }
From source file:com.miko.demo.postgresql.service.RedisInitTest.java
@Test public void testKeyValue() { RedisTemplate<String, Long> redis = new RedisTemplate<>(); redis.setConnectionFactory(connectionFactory); redis.setKeySerializer(RedisStringSerializer.INSTANCE); redis.setValueSerializer(RedisLongSerializer.INSTANCE); redis.afterPropertiesSet(); ValueOperations<String, Long> ops = redis.opsForValue(); String key = "miko-spring-postgresql:counter-test"; Long value = ops.get(key);// ww w. j a va 2 s .co m logger.debug("VALUE = " + value); assertThat(value, notNullValue()); }
From source file:com.miko.demo.mongo.service.RedisInitTest.java
@Test public void testRedisTemplate() { RedisTemplate<String, Long> redis = new RedisTemplate<>(); redis.setConnectionFactory(connectionFactory); redis.setKeySerializer(RedisStringSerializer.INSTANCE); redis.setValueSerializer(RedisLongSerializer.INSTANCE); redis.afterPropertiesSet(); ValueOperations<String, Long> ops = redis.opsForValue(); String key1 = "miko-spring-mongo:counter-test"; String key2 = "miko-spring-mongo:counter-test-2"; logger.debug("redistTemplate ops = " + ops); ops.setIfAbsent(key1, 1L);/*from w ww. j a v a 2 s . c om*/ ops.setIfAbsent(key2, 22L); Long l = ops.increment(key1, 1); logger.debug("redistTemplate L = " + l); assertThat(l, is(greaterThan(0L))); }
From source file:com.miko.demo.postgresql.service.RedisInitTest.java
@Test public void testRedisTemplate() { RedisTemplate<String, Long> redis = new RedisTemplate<>(); redis.setConnectionFactory(connectionFactory); redis.setKeySerializer(RedisStringSerializer.INSTANCE); redis.setValueSerializer(RedisLongSerializer.INSTANCE); redis.afterPropertiesSet(); ValueOperations<String, Long> ops = redis.opsForValue(); String key1 = "miko-spring-postgresql:counter-test"; String key2 = "miko-spring-postgresql:counter-test-2"; logger.debug("redistTemplate ops = " + ops); ops.setIfAbsent(key1, 1L);/*from w ww. j ava2 s. c o m*/ ops.setIfAbsent(key2, 22L); Long l = ops.increment(key1, 1); logger.debug("redistTemplate L = " + l); assertThat(l, is(greaterThan(0L))); }
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(); redis.setEnableTransactionSupport(true);//???redistemplate? redis.multi();// ww w. ja v a2s .co m redis.boundValueOps("somevkey").increment(1); redis.boundZSetOps("somezkey").add("zvalue", 11); redis.exec(); redis.setEnableTransactionSupport(false); }
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(); 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 w ww . ja v a2 s . co m redisTemplate.setConnectionFactory(this.redisConnectionFactory); redisTemplate.setBeanClassLoader(this.classLoader); redisTemplate.afterPropertiesSet(); return redisTemplate; }