Redis Client Design

Source: Internet
Author: User
Tags redis cluster install redis

Redis Client Design

The Redis client is designed as follows:

/* With multiplexing we need to take per-clinet state.
* Clients are taken in a liked list .*/
Typedef struct redisClient {
Int fd;
RedisDb * db;
Int dictid;
Sds querybuf;
Robj ** argv, ** mbargv;
Int argc, mbargc;
Int bulklen;/* bulk read len.-1 if not in bulk read mode */
Int multibulk;/* multi bulk command format active */
List * reply;
Int sentlen;
Time_t lastinteraction;/* time of the last interaction, used for timeout */
Int flags;/* REDIS_CLOSE | REDIS_SLAVE | REDIS_MONITOR */
Int slaveseldb;/* slave selected db, if this client is a slave */
Int authenticated;/* when requirepass is non-NULL */
Int replstate;/* replication state if this is a slave */
Int repldbfd;/* replication DB file descriptor */
Long repldboff;/* replication DB file offset */
Off_t repldbsize;/* replication DB file size */
} RedisClient;

After accpet, create a client.

The Code is as follows:

Static client createClient (void ){
Client c = zmalloc (sizeof (struct _ client ));
Char err [ANET_ERR_LEN];

C-> fd = anetTcpNonBlockConnect (err, config. hostip, config. hostport );
If (c-> fd = ANET_ERR ){
Zfree (c );
Fprintf (stderr, "Connect: % s \ n", err );
Return NULL;
}
AnetTcpNoDelay (NULL, c-> fd );
C-> obuf = sdsempty ();
C-> ibuf = sdsempty ();
C-> mbulk =-1;
C-> readlen = 0;
C-> written = 0;
C-> totreceived = 0;
C-> state = CLIENT_CONNECTING;
AeCreateFileEvent (config. el, c-> fd, AE _WRITABLE, writeHandler, c );
Config. liveclients ++;
ListAddNodeTail (config. clients, c );
Return c;
}

I think the following code is a bit written.

ListAddNodeTail (config. clients, c );

Since this function is named createclient, it should do the create operation, and put listaddnodetail in the outer function for implementation.

Since the add function is implemented in the createclient function, it seems a bit malformed to return a c pointer to the outer function to determine if the number of links exceeds the limit.

What do you think?

Install and test Redis in Ubuntu 14.04

Redis cluster details

Install Redis in Ubuntu 12.10 (graphic explanation) + Jedis to connect to Redis

Redis series-installation, deployment, and maintenance

Install Redis in CentOS 6.3

Learning notes on Redis installation and deployment

Redis. conf

Redis details: click here
Redis: click here

This article permanently updates the link address:

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.