Use SOCKET to operate redis

Source: Internet
Author: User

 

Code:

$cmd = "*3\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$3\r\nbar\r\n"; // set foo bar$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);socket_connect($socket, ‘127.0.0.1‘, 6379);$flag = socket_write($socket,$cmd,strlen($cmd));eee($flag);

 

Reids protocol uses text protocol

Specific reference http://www.redisdoc.com/en/latest/topic/protocol.html

In addition to the native TCP protocol, redis also designedInline commandsTo operate redis like in redis-cli

 

Redis: Text Protocol

Memcached: text protocol + binary Protocol

HTTP: Text Protocol

Gearman: Binary Protocol

MySQL: Binary Protocol

 

Binary Protocol: smaller data volume, higher efficiency, but not easy to expand, poor readability

Text Protocol: multiple data transmission, good readability, and easy scalability

 

Predis is an extension that uses the native socket method to operate redis.

 

Simple understanding of the Protocol

 

Use SOCKET to operate redis

Related Article

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.