Polishing.

Rename asString(:Object) to toString(:Object) for consistency with toBytes(..).

Original pull request: #2774
This commit is contained in:
John Blum
2023-11-17 15:00:42 -08:00
parent 482eab9224
commit 76cdf48afa

View File

@@ -271,7 +271,7 @@ public class RedisKeyValueAdapter extends AbstractKeyValueAdapter
@Override @Override
public <T> T get(Object id, String keyspace, Class<T> type) { public <T> T get(Object id, String keyspace, Class<T> type) {
String stringId = asString(id); String stringId = toString(id);
byte[] binId = createKey(keyspace, stringId); byte[] binId = createKey(keyspace, stringId);
RedisCallback<Map<byte[], byte[]>> command = connection -> connection.hGetAll(binId); RedisCallback<Map<byte[], byte[]>> command = connection -> connection.hGetAll(binId);
@@ -305,7 +305,7 @@ public class RedisKeyValueAdapter extends AbstractKeyValueAdapter
if (value != null) { if (value != null) {
byte[] keyToDelete = createKey(keyspace, asString(id)); byte[] keyToDelete = createKey(keyspace, toString(id));
redisOps.execute((RedisCallback<Void>) connection -> { redisOps.execute((RedisCallback<Void>) connection -> {
@@ -383,6 +383,7 @@ public class RedisKeyValueAdapter extends AbstractKeyValueAdapter
connection.del(toBytes(keyspace)); connection.del(toBytes(keyspace));
new IndexWriter(connection, converter).removeAllIndexes(keyspace); new IndexWriter(connection, converter).removeAllIndexes(keyspace);
return null; return null;
}); });
} }
@@ -503,7 +504,7 @@ public class RedisKeyValueAdapter extends AbstractKeyValueAdapter
for (byte[] field : existingFields) { for (byte[] field : existingFields) {
if (asString(field).startsWith(path + ".")) { if (toString(field).startsWith(path + ".")) {
redisUpdateObject.addFieldToRemove(field); redisUpdateObject.addFieldToRemove(field);
value = connection.hGet(redisUpdateObject.targetKey, toBytes(field)); value = connection.hGet(redisUpdateObject.targetKey, toBytes(field));
@@ -555,11 +556,13 @@ public class RedisKeyValueAdapter extends AbstractKeyValueAdapter
// nothing to do // nothing to do
} }
private String asString(Object value) { /**
return value instanceof String stringValue ? stringValue * Creates a new {@link byte[] key} using the given {@link String keyspace} and {@link String id}.
: getConverter().getConversionService().convert(value, String.class); *
} * @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) { public byte[] createKey(String keyspace, String id) {
return toBytes(keyspace + ":" + id); return toBytes(keyspace + ":" + id);
} }
@@ -568,12 +571,13 @@ public class RedisKeyValueAdapter extends AbstractKeyValueAdapter
* Convert given source to binary representation using the underlying {@link ConversionService}. * Convert given source to binary representation using the underlying {@link ConversionService}.
*/ */
public byte[] toBytes(Object source) { public byte[] toBytes(Object source) {
return source instanceof byte[] bytes ? bytes
: getConverter().getConversionService().convert(source, byte[].class);
}
if (source instanceof byte[] bytes) { private String toString(Object value) {
return bytes; return value instanceof String stringValue ? stringValue
} : getConverter().getConversionService().convert(value, String.class);
return converter.getConversionService().convert(source, byte[].class);
} }
/** /**
@@ -734,6 +738,7 @@ public class RedisKeyValueAdapter extends AbstractKeyValueAdapter
MappingExpirationListener listener = new MappingExpirationListener(this.messageListenerContainer, this.redisOps, MappingExpirationListener listener = new MappingExpirationListener(this.messageListenerContainer, this.redisOps,
this.converter); this.converter);
listener.setKeyspaceNotificationsConfigParameter(keyspaceNotificationsConfigParameter); listener.setKeyspaceNotificationsConfigParameter(keyspaceNotificationsConfigParameter);
if (this.eventPublisher != null) { if (this.eventPublisher != null) {