Example usage for org.springframework.data.redis.core RedisCallback RedisCallback

List of usage examples for org.springframework.data.redis.core RedisCallback RedisCallback

Introduction

In this page you can find the example usage for org.springframework.data.redis.core RedisCallback RedisCallback.

Prototype

RedisCallback

Source Link

Usage

From source file:com.mauersu.util.redis.DefaultSetOperations.java

public Long intersectAndStore(K key, Collection<K> otherKeys, K destKey) {
    final byte[][] rawKeys = rawKeys(key, otherKeys);
    final byte[] rawDestKey = rawKey(destKey);
    return execute(new RedisCallback<Long>() {

        public Long doInRedis(RedisConnection connection) {
            connection.select(dbIndex);//from www  .  ja va 2  s .c  om
            connection.sInterStore(rawDestKey, rawKeys);
            return null;
        }
    }, true);
}

From source file:com.mauersu.util.redis.DefaultValueOperations.java

public List<V> multiGet(Collection<K> keys) {
    if (keys.isEmpty()) {
        return Collections.emptyList();
    }//  w w  w  .  jav  a2  s  .c o m

    final byte[][] rawKeys = new byte[keys.size()][];

    int counter = 0;
    for (K hashKey : keys) {
        rawKeys[counter++] = rawKey(hashKey);
    }

    List<byte[]> rawValues = execute(new RedisCallback<List<byte[]>>() {

        public List<byte[]> doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            return connection.mGet(rawKeys);
        }
    }, true);

    return deserializeValues(rawValues);
}

From source file:com.zxy.commons.cache.RedisCache.java

@Override
public void clear() {
    redisTemplate.execute(new RedisCallback<String>() {
        public String doInRedis(RedisConnection connection) throws DataAccessException {
            connection.flushDb();/*from w  ww . ja  va 2s .  co  m*/
            return "ok";
        }
    });
}

From source file:com.mauersu.util.redis.DefaultListOperations.java

public Long size(K key) {
    final byte[] rawKey = rawKey(key);
    return execute(new RedisCallback<Long>() {

        public Long doInRedis(RedisConnection connection) {
            connection.select(dbIndex);//ww  w.java2  s  .c  o  m
            return connection.lLen(rawKey);
        }
    }, true);
}

From source file:com.mauersu.util.redis.DefaultZSetOperations.java

public Set<V> reverseRange(K key, final long start, final long end) {
    final byte[] rawKey = rawKey(key);

    Set<byte[]> rawValues = execute(new RedisCallback<Set<byte[]>>() {

        public Set<byte[]> doInRedis(RedisConnection connection) {
            connection.select(dbIndex);//from w  ww  . ja  v  a  2  s . c  o  m
            return connection.zRevRange(rawKey, start, end);
        }
    }, true);

    return deserializeValues(rawValues);
}

From source file:org.shareok.data.redis.UserDaoImpl.java

@Override
public RedisUser updateUser(final RedisUser user) {
    try {/*from  w  ww.j  a v  a 2 s .  c o m*/
        long uid = user.getUserId();
        redisTemplate.setConnectionFactory(connectionFactory);
        final String userKey = RedisUtil.getUserQueryKey(uid);
        List<Object> pipelinedResults = redisTemplate.executePipelined(new RedisCallback() {
            public Object doInRedis(RedisConnection connection) throws DataAccessException {
                String uid = String.valueOf(user.getUserId());
                Map userInfo = redisTemplate.opsForHash().entries(userKey);
                String oldUserEmail = (String) userInfo.get("email");
                HashOperations operations = redisTemplate.opsForHash();
                operations.put(userKey, "userName",
                        (null != user.getUserName() ? user.getUserName() : user.getEmail()));
                operations.put(userKey, "email", user.getEmail());
                operations.put(userKey, "password", user.getPassword());
                operations.put(userKey, "isActive", String.valueOf(true));
                operations.put(userKey, "sessionKey",
                        (null != user.getSessionKey() ? user.getSessionKey() : ""));

                if (!oldUserEmail.equals(user.getEmail())) {
                    operations.delete("users", oldUserEmail);
                    operations.put("users", user.getEmail(), uid);
                }
                return null;
            }
        });
    } catch (Exception ex) {
        logger.error("Cannot update a user", ex);
    }
    return user;
}

From source file:com.mauersu.util.redis.DefaultSetOperations.java

public Boolean isMember(K key, Object o) {
    final byte[] rawKey = rawKey(key);
    final byte[] rawValue = rawValue(o);
    return execute(new RedisCallback<Boolean>() {

        public Boolean doInRedis(RedisConnection connection) {
            connection.select(dbIndex);// w  w  w  .  j  a  va  2  s .  co  m
            return connection.sIsMember(rawKey, rawValue);
        }
    }, true);
}

From source file:com.ge.predix.acs.policy.evaluation.cache.RedisPolicyEvaluationCache.java

@Override
void setResourceTranslations(final Set<String> fromKeys, final String toKey) {
    this.redisTemplate.execute(new RedisCallback<List<Object>>() {
        @Override// www.  ja v  a 2  s.co m
        public List<Object> doInRedis(final RedisConnection connection) throws DataAccessException {
            StringRedisConnection stringRedisConn = new DefaultStringRedisConnection(connection);
            for (String fromKey : fromKeys) {
                stringRedisConn.sAdd(fromKey, toKey);
            }
            return null;
        }
    });
}

From source file:com.mauersu.util.redis.DefaultListOperations.java

public List<V> range(K key, final long start, final long end) {
    final byte[] rawKey = rawKey(key);
    return execute(new RedisCallback<List<V>>() {
        public List<V> doInRedis(RedisConnection connection) {
            connection.select(dbIndex);//from   w w  w . jav a2 s . c  o  m
            return deserializeValues(connection.lRange(rawKey, start, end));
        }
    }, true);
}

From source file:com.mauersu.util.redis.DefaultHashOperations.java

public void putAll(K key, Map<? extends HK, ? extends HV> m) {
    if (m.isEmpty()) {
        return;/*from w w w .j  av a 2  s  .  c om*/
    }

    final byte[] rawKey = rawKey(key);

    final Map<byte[], byte[]> hashes = new LinkedHashMap<byte[], byte[]>(m.size());

    for (Map.Entry<? extends HK, ? extends HV> entry : m.entrySet()) {
        hashes.put(rawHashKey(entry.getKey()), rawHashValue(entry.getValue()));
    }

    execute(new RedisCallback<Object>() {

        public Object doInRedis(RedisConnection connection) {
            connection.select(dbIndex);
            connection.hMSet(rawKey, hashes);
            return null;
        }
    }, true);
}