redis source code analysis

Read about redis source code analysis, The latest news, videos, and discussion topics about redis source code analysis from alibabacloud.com

Redis source code analysis (8) --- t_hash hash Conversion

After the last zipmap analysis, the content about the redis source code struct has actually ended, because there are several operation classes related to the struct below, they are merged into the struct package. These files include t_hash.c, z_list, z_set.c, t_string.c, and t_zset.c. The functions of these files are s

Redis Source Code Analysis (23)---CRC cyclic redundancy algorithm and Rand random number algorithm

integer as a random number and then plans the 32-bit pseudo-random number to [0,1], initializes the drand48 () with the function srand48, initializes the high 32 bits of the 48-bit integer only, and its low 16-bit is set to a random value. This is a pseudo-random generator with better statistical characteristics. These 2 functions are the original C language implementation: #ifndef DRAND48_H #define DRAND48_H #include Because the rand () function of the system is still used here

Redis source code analysis 20-release/subscription

= listNext(li)) != NULL) { pubsubPattern *pat = ln->value; if (stringmatchlen((char*)pat->pattern->ptr, sdslen(pat->pattern->ptr), (char*)channel->ptr, sdslen(channel->ptr),0)) { addReply(pat->client,shared.mbulk4); addReply(pat->client,shared.pmessagebulk); addReplyBulk(pat->client,pat->pattern); addReplyBulk(pat->client,

Redis Source code Analysis--Doubly linked list

directly use value to compare. If you use value directly to compare, it is a strong contrast, that is, the data required for comparison and the data in the linked list are in the same place in memory.ListNode *listsearchkey (list *list, void *key) { listiter iter; ListNode *node; Listrewind (list, iter); while (node = Listnext (iter)) = NULL) { if (list->match) { if (List->match (Node->value, key)) { C6/>return node; } } else { if (key

Redis Source Code Analysis (27)---Rio I/o packages

Rio */static size_t Riofilewrite (Rio *r, const void *buf, size_t len) { size_t retval; retval = fwrite (BUF,LEN,1,R->IO.FILE.FP); R->io.file.buffered + = len; if (R->io.file.autosync r->io.file.buffered >= r->io.file.autosync) { // Interpretation of the need to synchronize fflush (R->IO.FILE.FP); Aof_fsync (Fileno (R->IO.FILE.FP)); r->io.file.buffered = 0; } return retval;} Copyright notice: This article Bo Master original articles, blogs, w

Redis source code analysis (27th) --- encapsulation of the Rio system I/O

(Rio * r, double D );Here is a method implementation: /* Write multi bulk count in the format: "* The riowrite method is called. You can define the buffer Io or file IO according to your own implementation. There is a detail in the file write method. When you read the content into Rio. file. when the buffer exceeds the given minimum Synchronization Byte, you must refresh the buffer content to the file. /* Returns 1 or 0 for success/failure. * // * write the Buf to the file in Rio */static s

Redis source code analysis (5) --- sparkline micrograph

->max - seq->min; int steps = charset_len*rows; int row = 0; char *chars = zmalloc(len); int loop = 1; int opt_fill = flags SPARKLINE_FILL; int opt_log = flags SPARKLINE_LOG_SCALE; if (opt_log) { relmax = log(relmax+1); } else if (relmax == 0) { relmax = 1; } while(loop) { loop = 0; memset(chars,' ',len); for (j = 0; j Due to my limited ability, I am not quite familiar with the specific details. After reading about the details,

Redis source code analysis 24-VM (medium)

) { if (key->storage == REDIS_VM_MEMORY || key->storage == REDIS_VM_SWAPPING) { /* If we were swapping the object out, stop it, this key * was requested. */ if (key->storage == REDIS_VM_SWAPPING) vmCancelThreadedIOJob(key); /* Update the access time of the key for the aging algorithm. */ key->vm.atime = server.unixtime; } else { int notify

Redis source code analysis (17) --- multi transaction operations

operation will fail */void touchwatchedkey (redisdb * dB, robj * Key) {list * clients; listiter Li; listnode * ln; If (dictsize (db-> watched_keys) = 0) return; clients = dictfetchvalue (db-> watched_keys, key); If (! Clients) return;/* mark all the clients watching this key as redis_dirty_cas * // * check if we are already watching for this key */listrewind (clients, Li ); while (Ln = listnext ( Li) {redisclient * c = listnodevalue (LN); // traverses the client owned by the key, mark flag as

Redis source code analysis 16-blocking command

REDIS_BLOCKED flag for the client, so that the client is blocked. static void blockForKeys(redisClient *c, robj **keys, int numkeys, time_t timeout) { dictEntry *de; list *l; int j; --- if (c->fd The waiting client will be blocked until the push operation exists. At this time, unblockClientWaitingData will be called to remove the blocking of the client. /* Unblock a client that's waiting in a blocking operation such as BLPOP * // reduce the reference to the blocked object static

Redis source code analysis 25-VM (below)

]; int retval, processed = 0, toprocess = -1, trytoswap = 1; REDIS_NOTUSED(el); REDIS_NOTUSED(mask); REDIS_NOTUSED(privdata); if (privdata != NULL) trytoswap = 0; /* check the comments above... */ /* For every byte we read in the read side of the pipe, there is one * I/O job completed to process. */ while((retval = read(fd,buf,1)) == 1) { iojob *j; listNode *ln; robj *key; struct dictEntry *de; redisLog(REDIS_DEBUG,"Processing I/O compl

Redis Source Code Analysis (22)---Networking Network protocol transmission

The last time I only analyzed the parts of the Redis network part of the code, today I took networking's code implementation part also learned, networking's code more emphasis is the operation of client clients. The method operation inside the Addreply () series is the main part. This series of light-and-light methods

Scrapy-redis source code analysis

written. The encoding implementation here is different from the situation analyzed in the article (link :). Since the configuration needs to be read here, from_crawler () is used () function. (V) schedler. py this extension is an alternative to the scheduler self-contained in scrapy (pointed out in the scheduler variable of settings), which is used to implement distributed scheduling of crawlers. The data structure it uses comes from the data structure implemented in the queue. Scrapy-

Redis source code analysis-Memory Data Structure intset

, find the starting position of the movement, and then memmove (), bingo !!! Data query interface implementation: static uint8_t intsetSearch(intset *is, int64_t value, uint32_t *pos) { int min = 0, max = intrev32ifbe(is->length)-1, mid = -1; int64_t cur = -1; /* The value can never be found when the set is empty */ if (intrev32ifbe(is->length) == 0) { if (pos) *pos = 0; return 0; } else { /* Check for the case where we know we cannot find the value,

Redis Source Code Analysis (21)---Encapsulation of anet network communication

; int RV; memset (hints,0,sizeof (hints)); if (Flags anet_ip_only) hints.ai_flags = Ai_numerichost; hints.ai_family = Af_unspec; Hints.ai_socktype = Sock_stream; /* Specify socktype to avoid dups *///parse hostname if (rv = getaddrinfo (host, NULL, hints, info))! = 0) { Anetseterror (Err, "%s", Gai_strerror (RV)); return anet_err; }//Resolve ipV4 address by type or IPV6 address if (info->ai_family = = af_inet) {struct sockaddr_in *sa = (struct sockaddr_in *) info->

Redis Source Code Analysis (28)---object to create and release Redisobject objects

of an encoded object (returned as a new object). * If The object is already raw-encoded just increment the ref count. *//* gets the decoded robj */robj *getdecodedobject (robj *o) { robj *dec; if (o->encoding = = Redis_encoding_raw) { //Assume there is no encoding method. The reference count is added directly. and return to Incrrefcount (o); return o; } if (O->type = = redis_string o->encoding = = redis_encoding_int) { char buf[32];//is assumed to be a STRIN

Redis source code analysis (6) --- ziplist compression list

后调用插入数据的insert方法 return __ziplistInsert(zl,p,s,slen);} Finally, the insert method is called. I have read some ziplist analyses analyzed by others before writing them. I feel that some of them are very rough. I think it is clear that I have read the source code carefully. Each person has a different focus. Finally, the header file and key macro definitions are given: /* zip列表的末尾值 */#define ZIP_END 255/* z

Redis Source Code Analysis (18)---DB.C in-memory database operations

removed, so in the earliest function, to the memory database when the value of the time to determine whether to expire/* To determine if this key expires, 2 conditions, 1 whether there is a expire key does not expire 2. In expire inside, judge when time is not more than the current time, no more than also not expired */int expireifneeded (Redisdb *db , RobJ *key) {mstime_t when = Getexpire (Db,key); mstime_t now; if (when Each expire key has a TTL concept, which is "Time to Live" lifetime

Python---redis cache page Analysis of the play in front of the render source code

):"""Flushes the current output of buffer to the network.the ' callback ' argument,ifGiven, can be used forFlow control:it would be run if all flushed data have been written to the socket. Note that only one flush callback can is outstanding at a time; ifAnother flush occurs before the previous flush'S Callbackhas been run, the previous callback would be discarded. .. Versionchanged::4.0Now returns a '. Future 'ifNo callback isgiven. """Chunk = b"". Join (Self._write_buffer) self._write_b

Redis Source Code Analysis SDS, dynamic array

ends with a. This is not the same as Nginx's ngx_string.As a substitute for strlen, SDS also offers SdslenThe time complexity of the original strlen is O (n), while the time complexity of the Sdslen is O (1)The memory expansion of SDS, when memory consumption is less than 1M, it will be expanded to twice times the original. In this way, the time complexity of expanding the scale is also O (1). is also highly efficient.When the memory footprint is more than 1M, it will only grow 1M at a time, no

Total Pages: 15 1 2 3 4 5 6 .... 15 Go to: Go

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.