Redis Publishing and subscription-preliminary exploration

Source: Internet
Author: User
: 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.