Environment: WINDOWS10, Redis installed
1. Command line version
Open cmd, switch to the Redis installation directory, the directory should have Redis-cli.exe, Redis-server.exe, redis.conf and other files.
Turn on the local Redis service: Perform Redis-server.exe redis.conf and start the Redis service.
Client Connection Redis Service: Perform redis-cli.exe-h 127.0.0.1, connect to Redis service.
Subscriber subscription Message type of interest: Subscribe news.it
Publisher Post message: Publish news.it "I like It"
2. PHP version
Subscription: subscribe.php
Ini_set (' Default_socket_timeout ',-1); does not time out
$redis = new Redis ();
$redis->connect (' 127.0.0.1 ', 6379);
if (Empty ($argv [1])) echo "Please input your channel";
$channel = $argv [1]; Channel
$redis->subscribe (Array ($channel), ' callback ');
function callback ($instance, $channelName, $message) {
Echo $channelName, "==>", $message, Php_eol;
}
Release: publish.php
$redis = new Redis ();
$redis->connect (' 127.0.0.1 ', 6379);
/*argv[0] is the name of the file to execute, Argv[1] is the first parameter immediately following the execution of a file */
$channel = $argv [1]; Channel
$msg = $ARGV [2]; Msg
Var_dump ($channel. $msg);
$redis->publish ($channel, $msg);
Run:
The above describes the Redis publishing and subscription-a preliminary discussion, including aspects of the content, I hope to be interested in the PHP tutorial friends helpful.