Redis source code analysis () --- redis-cli.c client command line interface implementation (1)

Source: Internet
Author: User
Tags redis cli

I analyzed the redis source code for nearly a month, and reached the core, closest to the beginning of the system. I named it the main directory, there are two important files, redis-CLI and redis files, one representing the client's execution file and the other representing the server's files, these two are also the most core modules of the entire system, so I will summarize them to the main program module. The main program module is also the last module for me to learn about redis, here we can see the traces of all functional modules that I have seen before. Because the main module has a large amount of code, I chose to study in batches. So today I mainly pull out the API methods in it, anatomy of the things in redis-cli.

At first, I thought redis-cli. is the abbreviation of redis-client, but in fact it means:


/ * Redis CLI (command line interface)
  * Command line interface
Therefore, it directly responds to the commands for operating the black window in redis. This file defines the redis context, configuration information structure, and a bunch of APIs:



/ * redis context * /
static redisContext * context;
/ * Redis configuration structure * /
static struct config
I am not in a rush to look at the methods of the subsequent APIs, because there are too many methods. First, we will learn to classify them. Below is a diagram I made;



There are a lot of modules. The above are all English expressions. In the subsequent analysis, I will study modules one by one. For example, the first utility functions is a general method, what are the following methods. All the APIs in redis-cli are released as follows:


/ * Utility functions * /
static long long ustime (void)
static long long mstime (void)
static void cliRefreshPrompt (void)
static sds cliVersion (void)
static void cliInitHelp (void)
static void cliOutputCommandHelp (struct commandHelp * help, int group)
static void cliOutputGenericHelp (void)
static void cliOutputHelp (int argc, char ** argv)
static void completionCallback (const char * buf, linenoiseCompletions * lc)
static int cliAuth ()
static int cliSelect ()
static int cliConnect (int force)
static void cliPrintContextError (void)
static sds cliFormatReplyTTY (redisReply * r, char * prefix)
static sds cliFormatReplyRaw (redisReply * r)
static sds cliFormatReplyCSV (redisReply * r)
static int cliReadReply (int output_raw_strings)
static int cliSendCommand (int argc, char ** argv, int repeat)
static redisReply * reconnectingInfo (void)
Ranch
/ * User interface user interface * /
static int parseOptions (int argc, char ** argv)
static sds readArgFromStdin (void)
static void usage (void)
static char ** convertToSds (int count, char ** args)
static void repl (void)
static int noninteractive (int argc, char ** argv)
Ranch
/ * Eval mode Eval mode * /
static int evalMode (int argc, char ** argv)
Ranch
/ * Latency and latency history modes * /
static void latencyMode (void)

/ * Slave mode * /
unsigned long long sendSync (int fd)
static void slaveMode (void)

/ * RDB transfer mode * /
static void getRDB (void)

/ * Bulk import (pipe) mode * /
static void pipeMode (void)
Ranch
/ * Find big keys * /
static redisReply * sendScan (unsigned long long * it)
static int getDbSize (void)
static int toIntType (char * key, char * type)
static void getKeyTypes (redisReply * keys, int * types)
static void getKeySizes (redisReply * keys, int * types, unsigned long long * sizes)
static void findBigKeys (void)
Ranch
/ * Stats mode * /
static char * getInfoField (char * info, char * field)
static long getLongInfoField (char * info, char * field)
void bytesToHuman (char * s, long long n)
static void statMode (void)
Ranch
/ * Scan mode * /
static void scanMode (void)

/ * Intrisic latency mode * /
unsigned long compute_something_fast (void)
static void intrinsicLatencyModeStop (int s)
static void intrinsicLatencyMode (void)

/ * Program main () * /
int main (int argc, char ** argv) 


Redis source code analysis () --- redis-cli.c client command line interface implementation (1)

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.