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