diff --git a/src/main/java/org/springframework/data/redis/cache/BatchStrategies.java b/src/main/java/org/springframework/data/redis/cache/BatchStrategies.java index 047ef3834c..32892212dc 100644 --- a/src/main/java/org/springframework/data/redis/cache/BatchStrategies.java +++ b/src/main/java/org/springframework/data/redis/cache/BatchStrategies.java @@ -33,6 +33,7 @@ * @author Mark Paluch * @author Christoph Strobl * @author John Blum + * @author Mohammad Javad Imani * @since 2.6 */ public abstract class BatchStrategies { @@ -79,11 +80,11 @@ static class Keys implements BatchStrategy { @Override public long cleanCache(RedisConnection connection, String name, byte[] pattern) { - byte[][] keys = Optional.ofNullable(connection.keys(pattern)).orElse(Collections.emptySet()) + byte[][] keys = Optional.ofNullable(connection.keyCommands().keys(pattern)).orElse(Collections.emptySet()) .toArray(new byte[0][]); if (keys.length > 0) { - connection.del(keys); + connection.keyCommands().del(keys); } return keys.length; @@ -104,7 +105,7 @@ static class Scan implements BatchStrategy { @Override public long cleanCache(RedisConnection connection, String name, byte[] pattern) { - Cursor cursor = connection.scan(ScanOptions.scanOptions().count(batchSize).match(pattern).build()); + Cursor cursor = connection.keyCommands().scan(ScanOptions.scanOptions().count(batchSize).match(pattern).build()); long count = 0; @@ -116,8 +117,8 @@ public long cleanCache(RedisConnection connection, String name, byte[] pattern) count += keys.size(); - if (keys.size() > 0) { - connection.del(keys.toArray(new byte[0][])); + if (!keys.isEmpty()) { + connection.keyCommands().del(keys.toArray(new byte[0][])); } } diff --git a/src/main/java/org/springframework/data/redis/core/RedisKeyValueAdapter.java b/src/main/java/org/springframework/data/redis/core/RedisKeyValueAdapter.java index 69338587dd..b96df18d10 100644 --- a/src/main/java/org/springframework/data/redis/core/RedisKeyValueAdapter.java +++ b/src/main/java/org/springframework/data/redis/core/RedisKeyValueAdapter.java @@ -103,6 +103,7 @@ * @author Mark Paluch * @author Andrey Muchnik * @author John Blum + * @author Mohammad Javad Imani * @since 1.7 */ public class RedisKeyValueAdapter extends AbstractKeyValueAdapter @@ -228,7 +229,7 @@ public Object put(Object id, Object item, String keyspace) { byte[] key = toBytes(rdo.getId()); byte[] objectKey = createKey(rdo.getKeyspace(), rdo.getId()); - boolean isNew = connection.del(objectKey) == 0; + boolean isNew = connection.keyCommands().del(objectKey) == 0; connection.hMSet(objectKey, rdo.getBucket().rawMap()); @@ -245,11 +246,11 @@ public Object put(Object id, Object item, String keyspace) { byte[] phantomKey = ByteUtils.concat(objectKey, BinaryKeyspaceIdentifier.PHANTOM_SUFFIX); if (expires(rdo)) { - connection.del(phantomKey); + connection.keyCommands().del(phantomKey); connection.hMSet(phantomKey, rdo.getBucket().rawMap()); connection.expire(phantomKey, rdo.getTimeToLive() + PHANTOM_KEY_TTL); } else if (!isNew) { - connection.del(phantomKey); + connection.keyCommands().del(phantomKey); } } @@ -323,7 +324,7 @@ public T delete(Object id, String keyspace, Class type) { redisOps.execute((RedisCallback) connection -> { - connection.del(keyToDelete); + connection.keyCommands().del(keyToDelete); connection.sRem(binKeyspace, binId); new IndexWriter(connection, converter).removeKeyFromIndexes(keyspace, binId); @@ -335,7 +336,7 @@ public T delete(Object id, String keyspace, Class type) { byte[] phantomKey = ByteUtils.concat(keyToDelete, BinaryKeyspaceIdentifier.PHANTOM_SUFFIX); - connection.del(phantomKey); + connection.keyCommands().del(phantomKey); } } return null; @@ -395,7 +396,7 @@ public void deleteAllOf(String keyspace) { redisOps.execute((RedisCallback) connection -> { - connection.del(toBytes(keyspace)); + connection.keyCommands().del(toBytes(keyspace)); new IndexWriter(connection, converter).removeAllIndexes(keyspace); return null; @@ -485,7 +486,7 @@ public void update(PartialUpdate update) { connection.persist(redisKey); if (keepShadowCopy()) { - connection.del(ByteUtils.concat(redisKey, BinaryKeyspaceIdentifier.PHANTOM_SUFFIX)); + connection.keyCommands().del(ByteUtils.concat(redisKey, BinaryKeyspaceIdentifier.PHANTOM_SUFFIX)); } } } @@ -883,7 +884,7 @@ private Object readShadowCopy(byte[] key) { Map phantomValue = connection.hGetAll(phantomKey); if (!CollectionUtils.isEmpty(phantomValue)) { - connection.del(phantomKey); + connection.keyCommands().del(phantomKey); } return phantomValue;