{
  "id": "keysreader",
  "title": "KeysReader",
  "url": "https://redis.io/docs/latest/operate/oss_and_stack/stack-with-enterprise/deprecated-features/gears-v1/jvm/classes/readers/keysreader/",
  "summary": "Gets keys and their values from a database.",
  "tags": [
    "docs",
    "operate",
    "stack"
  ],
  "last_updated": "2026-04-22T11:55:45+02:00",
  "page_type": "content",
  "content_hash": "97cb787667547c9e3dd76961498d376911f5debc7baa46bcc2b534419542e733",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "Creates records from the keys and values stored in a Redis database.\n\n\n Currently only supports string and hash data types. For other data types, it will only extract the key name."
    },
    {
      "id": "constructors",
      "title": "Constructors",
      "role": "content",
      "text": "You can use one of these constructors to create a new `KeysReader` object:\n\n[code example]"
    },
    {
      "id": "parameters",
      "title": "Parameters",
      "role": "parameters",
      "text": "| Name | Type | Default value | Description |\n|------|------|---------------|-------------|\n| commands | array of strings | null | The commands that this reader is registered on |\n| eventTypes | array of strings | null | The [event types](https://redis.io/docs/latest/operate/oss_and_stack/stack-with-enterprise/deprecated-features/gears-v1/register-events#event-types) to register on (usually the command name) |\n| keyTypes | array of strings | null | The key types to register on |\n| noScan | boolean | false | Whether or not to scan the key space or just read the pattern as is |\n| pattern/prefix | string | \"\\*\" (match all keys) | The reader will get all keys that match this pattern |\n| readValues | boolean | true | Whether or not to read the keys' values |"
    },
    {
      "id": "output-records",
      "title": "Output records",
      "role": "returns",
      "text": "Creates a `KeysReaderRecord` for each matching key in the database.\n\n| Name | Type | Description |\n|------|------|-------------|\n| key | string | The name of the key |\n| type | long | The core Redis type: 'string', 'hash', 'list', 'set', 'zset', or 'stream' |\n| event | string | The event that triggered the execution (null if using the run function) |\n| stringVal | string | The key's value for string data types |\n| hashVal | Map<String,String> | The key's value for hash data types |\n| listVal | List<String> | The key's value for list data types |\n| setVal | Set<String> | The key's value for set data types |"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "Here's a basic example of a `KeysReader` that creates records for all keys in the database:\n\n[code example]\n\nIn 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.\n\n[code example]"
    }
  ],
  "examples": [
    {
      "id": "constructors-ex0",
      "language": "java",
      "code": "public KeysReader()\n\npublic KeysReader(String pattern)\n\npublic KeysReader(String prefix, boolean readValues)\n\npublic KeysReader(String pattern, boolean noScan, boolean readValues)\n\npublic KeysReader(String prefix, \n                  boolean readValues, \n                  String[] eventTypes, \n                  String[] keyTypes)\n\npublic KeysReader(String pattern, \n                  boolean noScan, \n                  boolean readValues, \n                  String[] eventTypes, \n                  String[] keyTypes)",
      "section_id": "constructors"
    },
    {
      "id": "examples-ex0",
      "language": "java",
      "code": "KeysReader reader = new KeysReader();",
      "section_id": "examples"
    },
    {
      "id": "examples-ex1",
      "language": "java",
      "code": "String[] eventTypes = {\"HSET\", \"DEL\"};\nString[] keyTypes = {\"HASH\"};\nKeysReader reader = new KeysReader(\"person:*\", false, true, eventTypes, keyTypes);",
      "section_id": "examples"
    }
  ]
}
