Skip to main content

Result Reading

Choose the result method by the command's returned columns:

CommandColumnsdbVisitor method
GETVALUEqueryForString
INCRVALUEqueryForLong
LRANGEELEMENTqueryForList
HGETALLFIELD, VALUEqueryForPairs
MGETKEY, VALUEqueryForPairs

Read Key-Value Pairs

Map<String, String> values = jdbc.queryForPairs(
"MGET ? ?", String.class, String.class,
new Object[] { "user:1001:name", "user:1002:name" });

Read a Popped List Item

BLPOP and BRPOP return two ELEMENT rows: the list key first, then the item. Do not use a scalar method, which reads only the first row:

jdbc.executeUpdate("LPUSH ? ?", new Object[] { "queue:demo", "hello" });
List<String> result = jdbc.queryForList("BRPOP ? ?", new Object[] { "queue:demo", 5 }, String.class);
String key = result.get(0);
String message = result.get(1);
Note

This example preloads an item. The current adapter does not normalize a blocking timeout into an empty result set. For consumers that must reliably handle empty queues and timeouts, use the Redis client directly.

Complete return types are listed in Command Syntax.

Custom result handling

See Result Handling for API availability and configuration of RowMapper, RowCallbackHandler, and ResultSetExtractor. Read the actual result columns listed above.