Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated keys and del in BatchStrategies and RedisKeyValueAdapter #2995

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* @author Mark Paluch
* @author Christoph Strobl
* @author John Blum
* @author Mohammad Javad Imani
* @since 2.6
*/
public abstract class BatchStrategies {
Expand Down Expand Up @@ -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;
Expand All @@ -104,7 +105,7 @@ static class Scan implements BatchStrategy {
@Override
public long cleanCache(RedisConnection connection, String name, byte[] pattern) {

Cursor<byte[]> cursor = connection.scan(ScanOptions.scanOptions().count(batchSize).match(pattern).build());
Cursor<byte[]> cursor = connection.keyCommands().scan(ScanOptions.scanOptions().count(batchSize).match(pattern).build());

long count = 0;

Expand All @@ -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][]));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());

Expand All @@ -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);
}
}

Expand Down Expand Up @@ -323,7 +324,7 @@ public <T> T delete(Object id, String keyspace, Class<T> type) {

redisOps.execute((RedisCallback<Void>) connection -> {

connection.del(keyToDelete);
connection.keyCommands().del(keyToDelete);
connection.sRem(binKeyspace, binId);
new IndexWriter(connection, converter).removeKeyFromIndexes(keyspace, binId);

Expand All @@ -335,7 +336,7 @@ public <T> T delete(Object id, String keyspace, Class<T> type) {

byte[] phantomKey = ByteUtils.concat(keyToDelete, BinaryKeyspaceIdentifier.PHANTOM_SUFFIX);

connection.del(phantomKey);
connection.keyCommands().del(phantomKey);
}
}
return null;
Expand Down Expand Up @@ -395,7 +396,7 @@ public void deleteAllOf(String keyspace) {

redisOps.execute((RedisCallback<Void>) connection -> {

connection.del(toBytes(keyspace));
connection.keyCommands().del(toBytes(keyspace));
new IndexWriter(connection, converter).removeAllIndexes(keyspace);

return null;
Expand Down Expand Up @@ -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));
}
}
}
Expand Down Expand Up @@ -883,7 +884,7 @@ private Object readShadowCopy(byte[] key) {
Map<byte[], byte[]> phantomValue = connection.hGetAll(phantomKey);

if (!CollectionUtils.isEmpty(phantomValue)) {
connection.del(phantomKey);
connection.keyCommands().del(phantomKey);
}

return phantomValue;
Expand Down