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: