Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
redis如何确保所有请求数据只能由一个';阅读';函数调用?_Redis - Fatal编程技术网

redis如何确保所有请求数据只能由一个';阅读';函数调用?

redis如何确保所有请求数据只能由一个';阅读';函数调用?,redis,Redis,我最近读了redis的源代码,现在正在研究网络代码 Redis使用非块模式和epoll(或类似的东西)进行网络数据读/写。当读取数据事件到达时,将调用“readQueryFromClient”函数,在该函数中,请求数据将被读取到缓冲区中 在“readQueryFromClient”函数中,如果确实有数据到达,则通过一个“read”函数将数据读入缓冲区,然后处理请求 nread = read(fd, c->querybuf+qblen, readlen); // **one read fu

我最近读了redis的源代码,现在正在研究网络代码

Redis使用非块模式和epoll(或类似的东西)进行网络数据读/写。当读取数据事件到达时,将调用“readQueryFromClient”函数,在该函数中,请求数据将被读取到缓冲区中

在“readQueryFromClient”函数中,如果确实有数据到达,则通过一个“read”函数将数据读入缓冲区,然后处理请求

 nread = read(fd, c->querybuf+qblen, readlen); // **one read function**
//... some other codes to check read function retuen value
processInputBuffer(c);// **request will be handled in this function**
我的问题是:redis如何确保所有请求数据只需一次“读取”函数调用就可以读取到缓冲区中,也许所有数据都会通过更多的“读取”函数调用获得

processInputBuffer(c);//请求将在此功能中处理

那部分不是真的。Redis协议被设计为包含传递的每个数据块的长度。因此,服务器总是知道需要读取多少数据才能发出完整的请求。在
processInputBuffer
内部,如果
processInlineBuffer
processMultibulkBuffer
都不返回
REDIS_OK
(即在缓冲区中找不到请求终止符/参数不足),则控制权将从函数中消失。在本例中,
processInputBuffer
所做的就是填充客户机缓冲区的一块并更新解析状态。然后,在事件循环的下一次迭代中,在调用
aeProcessEvents
时,如果套接字缓冲区中仍有未读数据,将再次触发
readQueryFromClient
回调以解析剩余数据