List of usage examples for org.springframework.data.redis.core RedisTemplate setKeySerializer
public void setKeySerializer(RedisSerializer<?> serializer)
From source file:stormy.pythian.service.spring.ServiceConfiguration.java
@Bean public RedisTemplate<String, PythianToplogyConfiguration> redisTopologyTemplate() { RedisTemplate<String, PythianToplogyConfiguration> template = new RedisTemplate<>(); template.setConnectionFactory(redisConnectionFactory()); template.setKeySerializer(new StringRedisSerializer()); template.setHashKeySerializer(new StringRedisSerializer()); template.setHashValueSerializer(new JacksonJsonRedisSerializer<>(PythianToplogyConfiguration.class)); return template; }
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();/*from w w w .j a v a 2s. co m*/ ValueOperations<String, Long> ops = redis.opsForValue(); String key = "spring-postgresql:counter-test"; Long value = ops.get(key); 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();/*from w w w.jav a2 s.co m*/ ValueOperations<String, Long> ops = redis.opsForValue(); String key = "miko-spring-postgresql:counter-test"; Long value = ops.get(key); 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();/* ww w . j a v a 2 s. c o m*/ 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); 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();//from ww w .j a v a 2 s .c om 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); ops.setIfAbsent(key2, 22L); Long l = ops.increment(key1, 1); logger.debug("redistTemplate L = " + l); assertThat(l, is(greaterThan(0L))); }
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: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 va2s .c om * * @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; }//from w w w . j a v a2 s. co m this.redisTemplate.setConnectionFactory(this.connectionFactory); this.redisTemplate.afterPropertiesSet(); } this.initialized = true; }
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();/* w ww . jav a2 s.c om*/ return template; }