Redis command process

Source: Internet
Author: User


Key data structures and methods 1) struct redisCommand
struct redisCommand {    char *name;    redisCommandProc *proc;    int arity;    char *sflags; /* Flags as string representation, one char per flag. */    int flags;    /* The actual flags, obtained from the 'sflags' field. */    /* Use a function to determine keys arguments in a command line. */    redisGetKeysProc *getkeys_proc;    /* What keys should be loaded in background when calling this command? */    int firstkey; /* The first argument that's a key (0 = no keys) */    int lastkey;  /* The last argument that's a key */    int keystep;  /* The step between first and last key */    long long microseconds, calls;};
Compare a record to see the meaning of the field, and learn how to design a good command protocol. {"Set", setCommand,-3, "wm", 0, noPreloadGetKeys, 1, 1, 0 },
 * w: write command (may modify the key space). * r: read command  (will never modify the key space). * m: may increase memory usage once called. Don't allow if out of memory. * a: admin command, like SAVE or SHUTDOWN. * p: Pub/Sub related command. * f: force replication of this command, regardless of server.dirty. * s: command not allowed in scripts. * R: random command. Command is not deterministic, that is, the same command *    with the same arguments, with the same key space, may have different *    results. For instance SPOP and RANDOMKEY are two random commands. * S: Sort command output array if called from script, so that the output *    is deterministic. * l: Allow command while loading the database. * t: Allow command while a slave has stale data but is not allowed to *    server this data. Normally no command is accepted in this condition *    but just a few. * M: Do not automatically propagate the command on MONITOR.
RedisGetKeysProc and subsequent parameters are the list of processing parameters, and the keys and values are parsed from the command line. Suppose we want to return the server's easy-to-understand time and return the time format based on the input parameter.
void utimeCommand(redisClient *c) {char * fmt = c->argv[1]->ptr;char fmtResult[64];memset(fmtResult,0,64);struct timeval tv;gettimeofday(&tv,NULL);struct tm*tm;tm = localtime(&tv.tv_sec);if(tm!=NULL){strftime(fmtResult, sizeof fmtResult, fmt, tm);           }else{sprintf(fmtResult,"%s","error when retriving time");}addReplyBulkCString(c,fmtResult);}



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.