From 8b577951a60a4999ed43294c5bb289ab53dd748c Mon Sep 17 00:00:00 2001 From: John Blum Date: Fri, 17 Nov 2023 15:00:42 -0800 Subject: [PATCH] Polishing. Rename asString(:Object) to toString(:Object) for consistency with toBytes(..). Original pull request: #2774 --- .../data/redis/core/RedisKeyValueAdapter.java | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) 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 f1a3104fe1..76d9439207 100644 --- a/src/main/java/org/springframework/data/redis/core/RedisKeyValueAdapter.java +++ b/src/main/java/org/springframework/data/redis/core/RedisKeyValueAdapter.java @@ -271,7 +271,7 @@ public Object get(Object id, String keyspace) { @Override public T get(Object id, String keyspace, Class type) { - String stringId = asString(id); + String stringId = toString(id); byte[] binId = createKey(keyspace, stringId); RedisCallback> command = connection -> connection.hGetAll(binId); @@ -305,7 +305,7 @@ public T delete(Object id, String keyspace, Class type) { if (value != null) { - byte[] keyToDelete = createKey(keyspace, asString(id)); + byte[] keyToDelete = createKey(keyspace, toString(id)); redisOps.execute((RedisCallback) connection -> { @@ -383,6 +383,7 @@ public void deleteAllOf(String keyspace) { connection.del(toBytes(keyspace)); new IndexWriter(connection, converter).removeAllIndexes(keyspace); + return null; }); } @@ -503,7 +504,7 @@ private RedisUpdateObject fetchDeletePathsFromHashAndUpdateIndex(RedisUpdateObje for (byte[] field : existingFields) { - if (asString(field).startsWith(path + ".")) { + if (toString(field).startsWith(path + ".")) { redisUpdateObject.addFieldToRemove(field); value = connection.hGet(redisUpdateObject.targetKey, toBytes(field)); @@ -555,11 +556,13 @@ public void clear() { // nothing to do } - private String asString(Object value) { - return value instanceof String stringValue ? stringValue - : getConverter().getConversionService().convert(value, String.class); - } - + /** + * Creates a new {@link byte[] key} using the given {@link String keyspace} and {@link String id}. + * + * @param keyspace {@link String name} of the Redis {@literal keyspace}. + * @param id {@link String} identifying the key. + * @return a {@link byte[]} constructed from the {@link String keyspace} and {@link String id}. + */ public byte[] createKey(String keyspace, String id) { return toBytes(keyspace + ":" + id); } @@ -568,12 +571,13 @@ public byte[] createKey(String keyspace, String id) { * Convert given source to binary representation using the underlying {@link ConversionService}. */ public byte[] toBytes(Object source) { + return source instanceof byte[] bytes ? bytes + : getConverter().getConversionService().convert(source, byte[].class); + } - if (source instanceof byte[] bytes) { - return bytes; - } - - return converter.getConversionService().convert(source, byte[].class); + private String toString(Object value) { + return value instanceof String stringValue ? stringValue + : getConverter().getConversionService().convert(value, String.class); } /** @@ -734,6 +738,7 @@ private void initKeyExpirationListener() { MappingExpirationListener listener = new MappingExpirationListener(this.messageListenerContainer, this.redisOps, this.converter); + listener.setKeyspaceNotificationsConfigParameter(keyspaceNotificationsConfigParameter); if (this.eventPublisher != null) {