Example usage for org.springframework.data.redis.serializer StringRedisSerializer StringRedisSerializer

List of usage examples for org.springframework.data.redis.serializer StringRedisSerializer StringRedisSerializer

Introduction

In this page you can find the example usage for org.springframework.data.redis.serializer StringRedisSerializer StringRedisSerializer.

Prototype

public StringRedisSerializer() 

Source Link

Document

Creates a new StringRedisSerializer using StandardCharsets#UTF_8 UTF-8 .

Usage

From source file:org.springframework.data.redis.cache.RedisCache.java

/**
 * Constructs a new <code>RedisCache</code> instance.
 * //from   w ww .j a v a 2s  .co m
 * @param name cache name
 * @param prefix
 * @param template
 * @param expiration
 */
RedisCache(String name, byte[] prefix, RedisTemplate<? extends Object, ? extends Object> template,
        long expiration) {

    Assert.hasText(name, "non-empty cache name is required");
    this.name = name;
    this.template = template;
    this.prefix = prefix;
    this.expiration = expiration;

    StringRedisSerializer stringSerializer = new StringRedisSerializer();

    // name of the set holding the keys
    this.setName = ArrayUtils.addAll(prefix, stringSerializer.serialize(name + "~keys"));
    this.cacheLockName = ArrayUtils.addAll(prefix, stringSerializer.serialize(name + "~lock"));

}

From source file:org.springframework.data.redis.connection.DefaultStringRedisConnection.java

/**
 * Constructs a new <code>DefaultStringRedisConnection</code> instance. Uses {@link StringRedisSerializer} as
 * underlying serializer.//  ww  w  .  j  a  va2  s .c om
 * 
 * @param connection Redis connection
 */
public DefaultStringRedisConnection(RedisConnection connection) {
    Assert.notNull(connection, "connection is required");
    this.delegate = connection;
    this.serializer = new StringRedisSerializer();
}

From source file:org.springframework.data.redis.listener.adapter.MessageListenerAdapter.java

/**
 * Initialize the default implementations for the adapter's strategies.
 * /*from  www  .  j a  v  a 2s .  c o  m*/
 * @see #setSerializer(RedisSerializer)
 * @see JdkSerializationRedisSerializer
 */
protected void initDefaultStrategies() {
    RedisSerializer<String> serializer = new StringRedisSerializer();
    setSerializer(serializer);
    setStringSerializer(serializer);
}

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 .  jav a 2s  .  c o 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;
        }//  ww  w  .j a  v  a  2s  .c o  m
        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.
 *//* w w  w.  java  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 ww w. ja v 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);
    }//ww w  . j a  va2 s.c  o 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  ww  .  j  a  v a2s.com
    return template;
}

From source file:org.springframework.xd.samples.ProductCategoryEnricherTest.java

@Before
public void setUp() {
    JedisConnectionFactory redisConnectionFactory = new JedisConnectionFactory();
    redisConnectionFactory.afterPropertiesSet();

    redisTemplate = new RedisTemplate<>();
    redisTemplate.setConnectionFactory(redisConnectionFactory);
    redisTemplate.setDefaultSerializer(new StringRedisSerializer());
    redisTemplate.afterPropertiesSet();/* w  ww .j a va 2s .c o m*/
    productCategoryEnricher = new ProductCategoryEnricher(redisTemplate);

}