> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-+-++/modules/bx-redis/built-in-functions/redissubscribe.md).

# RedisSubscribe

Subscribes to a Redis channel for messages.

## Method Signature

```
RedisSubscribe(cacheName=[any], channel=[any], callback=[any])
```

### Arguments

| Argument    | Type  | Required | Description                                                 | Default |
| ----------- | ----- | -------- | ----------------------------------------------------------- | ------- |
| `cacheName` | `any` | `true`   | The name of the redis cache to use.                         |         |
| `channel`   | `any` | `true`   | The channel name to subscribe to.                           |         |
| `callback`  | `any` | `true`   | The callback function to invoke when messages are received. |         |

## Examples

Subscribe to a Redis channel:

```js
// Subscribe to a channel with a callback handler
RedisSubscribe(
    cache = "myRedisCache",
    channel = "notifications",
    callback = function( message ) {
        println( "Received message: " & message );
    }
);
```

Handle multiple message types:

```js
// Subscribe to events channel and parse JSON messages
RedisSubscribe(
    cache = "myRedisCache",
    channel = "events",
    callback = function( message ) {
        var event = deserializeJSON( message );

        switch( event.type ) {
            case "user.created":
                println( "New user created: " & event.userId );
                break;
            case "user.updated":
                println( "User updated: " & event.userId );
                break;
            default:
                println( "Unknown event type: " & event.type );
        }
    }
);
```

Subscribe to multiple channels:

```js
// Subscribe to multiple channels with pattern matching
RedisSubscribe(
    cache = "myRedisCache",
    channel = "events:*",
    callback = function( message ) {
        println( "Event received: " & message );
    }
);
```

## Related

* [RedisPublish()](/boxlang-+-++/modules/bx-redis/built-in-functions/redispublish.md) - Publish messages to Redis channels
* [RedisGetProvider()](/boxlang-+-++/modules/bx-redis/built-in-functions/redisgetprovider.md) - Get the Redis cache provider
* [Pub/Sub Patterns Guide](https://github.com/ortus-boxlang/boxlang-docs/tree/v1.x/boxlang-framework/boxlang-plus/modules/bx-redis/pub-sub-patterns.md) - Advanced publish/subscribe patterns
* [API Usage Guide](/boxlang-+-++/modules/bx-redis/api-usage.md) - Redis API documentation


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://boxlang.ortusbooks.com/boxlang-+-++/modules/bx-redis/built-in-functions/redissubscribe.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
