: This article mainly introduces the release and subscription of redis. For more information about PHP tutorials, see. Environment: Windows 10, with redis installed
1. Command Line Edition
Open the Directory, switch to redis-cli.exe, the directory should have redis-cli.exe, redis-server.exe, redis. conf and other files.
Enable the local redis service: execute redis-server.exe redis. conf to start the redis service.
Connect the client to the redis service: execute redis-cli.exe-h 127.0.0.1 and connect to the redis service.
Subscriber: subscribe news. it
Published by the publisher: publish news. it "I like it"
2. php version
Subscription: subscribe. php
Ini_set ('default _ socket_timeout ',-1); // no timeout
$ Redis = new Redis ();
$ Redis-> connect ('2017. 0.0.1 ', 127 );
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 ('2017. 0.0.1 ', 127 );
/* Argv [0] is the name of the execution file, and argv [1] is the first parameter followed by the execution file */
$ Channel = $ argv [1]; // channel
$ Msg = $ argv [2]; // msg
// Var_dump ($ channel. $ msg );
$ Redis-> publish ($ channel, $ msg );
Run:
The above introduces the redis release and subscription-preliminary research, including the content, hope to be helpful to friends who are interested in PHP tutorials.