You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+84Lines changed: 84 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,5 +28,89 @@ Our goal is to be a drop-in replacement for existing users, while providing powe
28
28
composer require devrabie/php-telegram-bot-plus
29
29
```
30
30
31
+
## 🚀 Using the Redis Helper
32
+
33
+
This library provides a simple helper to integrate a [Predis](https://github.com/predis/predis) client, allowing you to easily use Redis for your custom data persistence needs (e.g., storing user states, settings, caching). The library itself remains stateless.
34
+
35
+
### 1. Enable Redis
36
+
37
+
In your main bot file (e.g., `hook.php` or your script that handles updates):
38
+
39
+
```php
40
+
<?php
41
+
42
+
require_once __DIR__ . '/vendor/autoload.php';
43
+
44
+
$bot_api_key = 'YOUR_BOT_API_KEY';
45
+
$bot_username = 'YOUR_BOT_USERNAME';
46
+
47
+
$telegram = new Longman\TelegramBot\Telegram($bot_api_key, $bot_username);
48
+
49
+
// Initialize the Redis client and make it available to all commands
50
+
// Default connection: tcp://127.0.0.1:6379
51
+
$telegram->enableRedis();
52
+
53
+
// Or with custom connection parameters:
54
+
// $telegram->enableRedis([
55
+
// 'scheme' => 'tcp',
56
+
// 'host' => 'your-redis-host',
57
+
// 'port' => 6379,
58
+
// // 'password' => 'your-redis-password'
59
+
// ]);
60
+
61
+
// Handle updates
62
+
$telegram->handle();
63
+
```
64
+
65
+
### 2. Use Redis in Your Commands
66
+
67
+
You can access the shared Redis client instance from any command class using `getRedis()`:
0 commit comments