Creates records from the keys and values stored in a Redis database.

Note:
Currently only supports string and hash data types. For other data types, it will only extract the key name.

Constructors

You can use one of these constructors to create a new KeysReader object:

public KeysReader()

public KeysReader(String pattern)

public KeysReader(String prefix, boolean readValues)

public KeysReader(String pattern, boolean noScan, boolean readValues)

public KeysReader(String prefix, 
                  boolean readValues, 
                  String[] eventTypes, 
                  String[] keyTypes)

public KeysReader(String pattern, 
                  boolean noScan, 
                  boolean readValues, 
                  String[] eventTypes, 
                  String[] keyTypes)

Parameters

NameTypeDefault valueDescription
commandsarray of stringsnullThe commands that this reader is registered on
eventTypesarray of stringsnullThe event types to register on (usually the command name)
keyTypesarray of stringsnullThe key types to register on
noScanbooleanfalseWhether or not to scan the key space or just read the pattern as is
pattern/prefixstring“*” (match all keys)The reader will get all keys that match this pattern
readValuesbooleantrueWhether or not to read the keys’ values

Output records

Creates a KeysReaderRecord for each matching key in the database.

NameTypeDescription
keystringThe name of the key
typelongThe core Redis type: ‘string’, ‘hash’, ’list’, ‘set’, ‘zset’, or ‘stream’
eventstringThe event that triggered the execution (null if using the run function)
stringValstringThe key’s value for string data types
hashValMap<String,String>The key’s value for hash data types
listValListThe key’s value for list data types
setValSetThe key’s value for set data types

Examples

Here’s a basic example of a KeysReader that creates records for all keys in the database:

KeysReader reader = new KeysReader();

In the following example, the KeysReader creates records for all keys in the database that start with “person:”. When registered, it only runs for hashes after HSET and DEL events occur.

String[] eventTypes = {"HSET", "DEL"};
String[] keyTypes = {"HASH"};
KeysReader reader = new KeysReader("person:*", false, true, eventTypes, keyTypes);