1. Go to this page and download the library: Download clue/redis-react library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$pattern = 'user.*';
$redis->psubscribe($pattern);
$redis->on('pmessage', function (string $pattern, string $channel, string $payload) {
// pubsub message received matching given $pattern
var_dump($channel, json_decode($payload));
});
$redis->subscribe('user');
Loop::addTimer(60.0, function () use ($redis) {
$redis->unsubscribe('user');
});
$redis->on('subscribe', function (string $channel, int $total) {
// subscribed to given $channel
});
$redis->on('psubscribe', function (string $pattern, int $total) {
// subscribed to matching given $pattern
});
$redis->on('unsubscribe', function (string $channel, int $total) {
// unsubscribed from given $channel
});
$redis->on('punsubscribe', function (string $pattern, int $total) {
// unsubscribed from matching given $pattern
});
$redis = new Clue\React\Redis\RedisClient('localhost:6379');
$redis->incr('hello');
// both are equivalent due to defaults being applied
$redis = new Clue\React\Redis\RedisClient('localhost');
$redis = new Clue\React\Redis\RedisClient('redis://localhost:6379');
// all forms are equivalent
$redis = new Clue\React\Redis\RedisClient('redis://:h%40llo@localhost');
$redis = new Clue\React\Redis\RedisClient('redis://ignored:h%40llo@localhost');
$redis = new Clue\React\Redis\RedisClient('redis://localhost?password=h%40llo');
// both forms are equivalent
$redis = new Clue\React\Redis\RedisClient('redis://localhost/2');
$redis = new Clue\React\Redis\RedisClient('redis://localhost?db=2');
$redis = new Clue\React\Redis\RedisClient('rediss://redis.example.com:6340');
$redis = new Clue\React\Redis\RedisClient('redis+unix:///tmp/redis.sock');
// the URI MAY contain `password` and `db` query parameters as seen above
$redis = new Clue\React\Redis\RedisClient('redis+unix:///tmp/redis.sock?password=secret&db=2');
// the URI MAY contain authentication details as userinfo as seen above
// should be used with care, also note that database can not be passed as path
$redis = new Clue\React\Redis\RedisClient('redis+unix://:secret@/tmp/redis.sock');
$redis = new Clue\React\Redis\RedisClient('localhost?timeout=0.5');
$redis = new Clue\React\Redis\RedisClient('localhost?idle=10.0');