Search in sources :

Example 1 with RedisTemplate

use of org.springframework.data.redis.core.RedisTemplate in project camel by apache.

the class RedisConfiguration method createDefaultTemplate.

private RedisTemplate createDefaultTemplate() {
    redisTemplate = new RedisTemplate();
    redisTemplate.setDefaultSerializer(getSerializer());
    redisTemplate.setConnectionFactory(getConnectionFactory());
    redisTemplate.afterPropertiesSet();
    return redisTemplate;
}
Also used : RedisTemplate(org.springframework.data.redis.core.RedisTemplate)

Example 2 with RedisTemplate

use of org.springframework.data.redis.core.RedisTemplate in project camel by apache.

the class RedisConsumerIntegrationTest method createRegistry.

@Override
protected JndiRegistry createRegistry() throws Exception {
    JndiRegistry registry = super.createRegistry();
    redisTemplate = new RedisTemplate();
    redisTemplate.setConnectionFactory(CONNECTION_FACTORY);
    redisTemplate.afterPropertiesSet();
    registry.bind("redisTemplate", redisTemplate);
    registry.bind("listenerContainer", LISTENER_CONTAINER);
    return registry;
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) RedisTemplate(org.springframework.data.redis.core.RedisTemplate)

Example 3 with RedisTemplate

use of org.springframework.data.redis.core.RedisTemplate in project spring-boot-mybatis-with-redis by Lovelcp.

the class RedisCache method putObject.

/**
     * Put query result to redis
     *
     * @param key
     * @param value
     */
@Override
@SuppressWarnings("unchecked")
public void putObject(Object key, Object value) {
    RedisTemplate redisTemplate = getRedisTemplate();
    ValueOperations opsForValue = redisTemplate.opsForValue();
    opsForValue.set(key, value, EXPIRE_TIME_IN_MINUTES, TimeUnit.MINUTES);
    logger.debug("Put query result to redis");
}
Also used : RedisTemplate(org.springframework.data.redis.core.RedisTemplate) ValueOperations(org.springframework.data.redis.core.ValueOperations)

Example 4 with RedisTemplate

use of org.springframework.data.redis.core.RedisTemplate in project spring-boot-mybatis-with-redis by Lovelcp.

the class RedisCache method clear.

/**
     * Clears this cache instance
     */
@Override
public void clear() {
    RedisTemplate redisTemplate = getRedisTemplate();
    redisTemplate.execute((RedisCallback) connection -> {
        connection.flushDb();
        return null;
    });
    logger.debug("Clear all the cached query result from redis");
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) ValueOperations(org.springframework.data.redis.core.ValueOperations) Logger(org.slf4j.Logger) RedisCallback(org.springframework.data.redis.core.RedisCallback) Cache(org.apache.ibatis.cache.Cache) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) LoggerFactory(org.slf4j.LoggerFactory) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) RedisTemplate(org.springframework.data.redis.core.RedisTemplate)

Example 5 with RedisTemplate

use of org.springframework.data.redis.core.RedisTemplate in project spring-boot-mybatis-with-redis by Lovelcp.

the class RedisCache method getObject.

/**
     * Get cached query result from redis
     *
     * @param key
     * @return
     */
@Override
public Object getObject(Object key) {
    RedisTemplate redisTemplate = getRedisTemplate();
    ValueOperations opsForValue = redisTemplate.opsForValue();
    logger.debug("Get cached query result from redis");
    return opsForValue.get(key);
}
Also used : RedisTemplate(org.springframework.data.redis.core.RedisTemplate) ValueOperations(org.springframework.data.redis.core.ValueOperations)

Aggregations

RedisTemplate (org.springframework.data.redis.core.RedisTemplate)9 JndiRegistry (org.apache.camel.impl.JndiRegistry)3 ValueOperations (org.springframework.data.redis.core.ValueOperations)3 TimeUnit (java.util.concurrent.TimeUnit)1 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1 Cache (org.apache.ibatis.cache.Cache)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 RedisCallback (org.springframework.data.redis.core.RedisCallback)1 StringRedisTemplate (org.springframework.data.redis.core.StringRedisTemplate)1 StringRedisSerializer (org.springframework.data.redis.serializer.StringRedisSerializer)1