Redis communication protocol Optimization

Source: Internet
Author: User

1. Simplified commands

Analysis: commands in redis Communication Protocol use the original set, get, hset, hget, and other strings, it can be replaced by a single byte, such as 0x01, 0x02, 0x03, and 0x04.

Benefits: reduces network transmission traffic and sizes of dump and aof files.

Disadvantage: not easy to read (this seems to be a problem ...).

 

2. Simplified command Separators

Analysis: The command Separator in the redis communication protocol, which is "\ r \ n". It can be replaced by "\ r" or "\ n" in the same HTTP protocol.

Benefits: reduces network transmission traffic and sizes of dump and aof files.

Disadvantage: it seems that there is no such thing.

 

3. Optimize Command case sensitivity (this is related to 1. If 1 is done, it will not exist)

Analysis: The redis communication protocol document does not indicate that commands in the Protocol are written in uppercase or in lowercase. However, if you read the source code carefully, it is best to use lower case letters.

Benefits: Reduce the number of lowercase to accelerate command search.

Disadvantage: none.

Refer:

// The following code is from redis. c/* A Case Insensitive version used for the command lookup table. */INT dictsdskeycasecompare (void * privdata, const void * key1, const void * key2) {dict_notused (privdata); Return strcasecmp (key1, key2) = 0 ;} /* command table. SDS string-> command struct pointer. */dicttype commandtabledicttype = {dictsdscasehash,/* hash function */null,/* Key DUP */null,/* val DUP */dictsdskey Casecompare,/* Key compare */dictsdsdestructor,/* Key destructor */null/* val destructor */}; void initserverconfig (){//... /* command table -- We intiialize it here as it is part of the * initial configuration, since command names may be changed via * redis. conf using the rename-command directive. */server. commands = dictcreate (& commandtabledicttype, null); populatecommandtable (); server. d Elcommand = lookupcommandbycstring ("Del"); server. multicommand = lookupcommandbycstring ("multi ");//...} // The following code is from the LIB/string in Linux kernel 3.4.4. c file # ifndef _ have_arch_strcasecmpint strcasecmp (const char * S1, const char * S2) {int C1, C2; do {C1 = tolower (* S1 ++ ); c2 = tolower (* S2 ++);} while (C1 = c2 & C1! = 0); Return C1-C2;} export_symbol (strcasecmp); # endif

When the key functions are compared with strcasecmp, the corresponding characters in S1 and S2 are converted to lower-case characters before comparison.

Reference link:

Http://redis.io/topics/protocol

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.