Example usage for org.springframework.data.redis.connection RedisConnection del

List of usage examples for org.springframework.data.redis.connection RedisConnection del

Introduction

In this page you can find the example usage for org.springframework.data.redis.connection RedisConnection del.

Prototype

@Nullable
Long del(byte[]... keys);

Source Link

Document

Delete given keys .

Usage

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

@Override
public void evict(Object key) {
    redisTemplate.execute(new RedisCallback<Long>() {
        public Long doInRedis(RedisConnection connection) throws DataAccessException {
            return connection.del(SerializationUtils.serialize(key));
        }/*from   w  w  w  .jav a2s . co  m*/
    });
}

From source file:grails.plugin.cache.redis.GrailsRedisCache.java

@SuppressWarnings("unchecked")
@Override//from  w  ww . j  a  v a  2  s . com
public void evict(Object key) {
    final byte[] k = computeKey(key);
    template.execute(new RedisCallback<Object>() {
        public Object doInRedis(RedisConnection connection) throws DataAccessException {
            connection.del(k);
            // remove key from set
            connection.zRem(setName, k);
            return null;
        }
    }, true);
}

From source file:grails.plugin.cache.redis.GrailsRedisCache.java

@SuppressWarnings("unchecked")
@Override/*from   w w  w . j  av a  2 s.com*/
public void clear() {
    // need to del each key individually
    template.execute(new RedisCallback<Object>() {
        public Object doInRedis(RedisConnection connection) throws DataAccessException {
            // another clear is on-going
            if (connection.exists(cacheLockName)) {
                return null;
            }

            try {
                connection.set(cacheLockName, cacheLockName);

                int offset = 0;
                boolean finished = false;

                do {
                    // need to paginate the keys
                    Set<byte[]> keys = connection.zRange(setName, (offset) * PAGE_SIZE,
                            (offset + 1) * PAGE_SIZE - 1);
                    finished = keys.size() < PAGE_SIZE;
                    offset++;
                    if (!keys.isEmpty()) {
                        connection.del(keys.toArray(new byte[keys.size()][]));
                    }
                } while (!finished);

                connection.del(setName);
                return null;

            } finally {
                connection.del(cacheLockName);
            }
        }
    }, true);
}

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

/**
 * Delete given {@code keys}./*w  w w . jav  a2s.co  m*/
 * <p>
 * See http://redis.io/commands/del
 * 
 * @param keys keys
 * @return The number of keys that were removed.
 */
public static Long del(byte[]... keys) {
    return redisTemplate.execute(new RedisCallback<Long>() {
        @Override
        public Long doInRedis(RedisConnection redis) throws DataAccessException {
            return redis.del(keys);
        }
    });
}

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

/**
 * Delete given {@code keys}./*from   ww  w .ja  v a2s.c  o m*/
 * <p>
 * See http://redis.io/commands/del
 * 
 * @param keys keys
 * @return The number of keys that were removed.
 */
public Long del(byte[]... keys) {
    return redisTemplate.execute(new RedisCallback<Long>() {
        @Override
        public Long doInRedis(RedisConnection redis) throws DataAccessException {
            return redis.del(keys);
        }
    });
}

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

public void evict(Object key) {
    final byte[] k = computeKey(key);

    template.execute(new RedisCallback<Object>() {
        public Object doInRedis(RedisConnection connection) throws DataAccessException {
            connection.del(k);
            // remove key from set
            connection.zRem(setName, k);
            return null;
        }/*from   ww w  .  j  a va  2 s .c om*/
    }, true);
}

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

public void clear() {
    // need to del each key individually
    template.execute(new RedisCallback<Object>() {
        public Object doInRedis(RedisConnection connection) throws DataAccessException {
            // another clear is on-going
            if (connection.exists(cacheLockName)) {
                return null;
            }/*from ww  w .  ja  va 2 s.  c o  m*/

            try {
                connection.set(cacheLockName, cacheLockName);

                int offset = 0;
                boolean finished = false;

                do {
                    // need to paginate the keys
                    Set<byte[]> keys = connection.zRange(setName, (offset) * PAGE_SIZE,
                            (offset + 1) * PAGE_SIZE - 1);
                    finished = keys.size() < PAGE_SIZE;
                    offset++;
                    if (!keys.isEmpty()) {
                        connection.del(keys.toArray(new byte[keys.size()][]));
                    }
                } while (!finished);

                connection.del(setName);
                return null;

            } finally {
                connection.del(cacheLockName);
            }
        }
    }, true);
}