Skip to content

Cannot scan binary keys with Jedis #2006

Closed
@n12c

Description

@n12c

In org.springframework.data:spring-data-redis:2.4.5, in org.springframework.data.redis.connection.jedis.JedisKeyCommands#scan(long, org.springframework.data.redis.core.ScanOptions)[1] we round trip keys through String, corrupting them. This makes it impossible scan top level keys using Jedis.

Specifically, we call redis.clients.jedis.Jedis#scan(java.lang.String, redis.clients.jedis.ScanParams) which decodes keys as strings, interpreting the binary data as UTF-8. On the next line, we encode the strings back into byte arrays using JedisConverters.stringListToByteList(), which renders UTF-8 again. This generally results in any non-UTF-8 sequences in a binary key being replaced with efbfbd (the UTF-8 serialization of the Unicode replacement character).

Instead, we should call redis.clients.jedis.BinaryJedis#scan(byte[], redis.clients.jedis.ScanParams) and remove the second conversion using JedisConverters.stringListToByteList().

[1] https://github.com/spring-projects/spring-data-redis/blob/master/src/main/java/org/springframework/data/redis/connection/jedis/JedisKeyCommands.java#L159

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions