Back to Redis

Register Events

content/operate/oss_and_stack/stack-with-enterprise/gears-v1/register-events.md

latest1.4 KB
Original Source

You can register RedisGears functions to run when certain events occur in a Redis database.

Register on events

To register RedisGears functions to run on an event, your code needs to:

  1. Pass KeysReader to a GearsBuilder object.

  2. Call the GearsBuilder.register() function.

  3. Pass the eventTypes parameter to either:

    • The register function for Python.

    • The KeysReader object for Java.

For more information and examples of event registration, see:

  • Java references:

    • [KeysReader]({{< relref "/operate/oss_and_stack/stack-with-enterprise/gears-v1/jvm/classes/readers/keysreader" >}})

    • [GearsBuilder.register()]({{< relref "/operate/oss_and_stack/stack-with-enterprise/gears-v1/jvm/classes/gearsbuilder/register" >}})

Event types

For the list of event types you can register on, see the [Redis keyspace notification documentation]({{< relref "/develop/pubsub/keyspace-notifications" >}}#events-generated-by-different-commands).

Active-Active event types

In addition to standard Redis [events]({{< relref "/develop/pubsub/keyspace-notifications" >}}#events-generated-by-different-commands), [Redis Software Active-Active databases]({{< relref "/operate/rs/databases/active-active" >}}) also support the registration of RedisGears functions for the following event types:

  • change: This event occurs when a key changes on another replica of the Active-Active database.