Redis source Read value to character longlong2str

Source: Internet
Author: User

Redis will turn a long long into a string and store it in the bottom layer. The main function is in the SDS module. The following two functions convert long long to char and unsiged long long to char. The general idea is that 1 values are converted from one to the end of the tail to a character, 2 to the length, and to the Terminator. 3 reverse the string. 4 If it is a long long type to consider a negative number of cases.
intSDSLL2STR (Char*s,Long Longvalue) {    Char*p, aux; unsignedLong Longv;    size_t l; /*Generate The string representation, this method produces * an reversed string.*/v= (Value <0) ? -Value:value; P=s;  Do {        *p++ ='0'+ (v%Ten); V/=Ten; }  while(v); if(Value <0) *p++ ='-'; /*Compute length and add null term.*/L= Ps; *p =' /'; /*Reverse the string.*/P--;  while(S <p) {aux= *s; *s = *p; *p =aux; S++; P--; }    returnl;}/*identical sdsll2str (), but for unsigned long long type.*/intSDSULL2STR (Char*s, unsignedLong Longv) {Char*p, aux;    size_t l; /*Generate The string representation, this method produces * an reversed string.*/P=s;  Do {        *p++ ='0'+ (v%Ten); V/=Ten; }  while(v); /*Compute length and add null term.*/L= Ps; *p =' /'; /*Reverse the string.*/P--;  while(S <p) {aux= *s; *s = *p; *p =aux; S++; P--; }    returnl;}

Redis source Read value to character longlong2str

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.