# 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/blob/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: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
