亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Redis 通訊協(xié)議的疑問(wèn)
怪我咯
怪我咯 2017-04-21 10:57:48
0
3
695

關(guān)于通訊協(xié)議,見(jiàn)https://redis.readthedocs.org/en/latest/topic/protocol.html

1)命令 set mykey myvalue 對(duì)應(yīng) 要發(fā)送到Redis的字符串(要轉(zhuǎn)化為二進(jìn)制數(shù)據(jù))是

"*3\r\n$3\r\nset\r\n$5\r\nmykey\r\n$7\r\nmyvalue\r\n"

2)命令 get mykey 對(duì)應(yīng)字符串是 "*2\r\n$3\r\nget\r\n$5\r\nmykey\r\n"

3)最后得到Redis發(fā)回的響應(yīng)是 "+OK\r\n$7\r\nmyvalue\r\n"

我的問(wèn)題是,Redis這樣的響應(yīng)格式,是否意味者 客戶(hù)端發(fā)完命令(需要得到返回

值的命令如get)后,必須要等待回應(yīng)到達(dá)之后才能發(fā)送下一個(gè)命令? 這樣對(duì)客戶(hù)端來(lái)說(shuō) 效率是否低了點(diǎn)?

怪我咯
怪我咯

走同樣的路,發(fā)現(xiàn)不同的人生

reply all(3)
左手右手慢動(dòng)作

This is the normal TCP streaming method.

阿神

Your "low efficiency for the client" is just your fantasy, right? Is there any data to support this? Without any data to support it, can it be judged correctly based on subjective feelings?

There is also the relationship between efficiency and business. Generally speaking, you will only start to consider efficiency issues when efficiency does not support business. Isn’t it a bit premature for you to consider this efficiency before you have done anything?

One final addition. . This is the definition in the tcp protocol. If there is anything unclear, http://en.wikipedia.org/wiki/Transmission_Control_Protocol go here to learn about the tcp specification. .

迷茫

Maybe this question becomes: Can redis only send one command in one request? will be better

Conclusion: No matter which redis request protocol is used, sending multiple commands in one request is supported


redis request protocol

Non-standard redis request protocol format (also known as Inline):

Command name Parameter 1 Parameter 2 ... Parameter N

set name diaocow

Standard redis request protocol format:

*<Number of parameters>CR LF
$<Number of bytes of parameter 1>CR LF <Data of parameter 1>CR LF
...
$<Number of bytes of parameter N>CR LF
<Data of parameter N>CR LF

*3rn$3rnsetrn$4rnnamern$7rndiaocowrn

So when we need to set the value of the key name to diaocow, we can use the above two protocol formats to complete it (interested readers can use the telnet or nc command to test it themselves)

How does the Redis request protocol support batch execution? (This is what everyone often calls pipeline mode)

For example, I need to execute the following two commands in batches:

  1. set name diaocow

  2. set country china

Then the data in a request will look like this (assuming we use the standard protocol): *3rn$3rnsetrn$4rnnamern$7rndiaocowrn*3rn$3rnsetrn$7rncountryrn$5rnchinarn

Then inside redis, it will be parsed like this, pseudo code:

def processInputBuffer(client): 
    while (len(client.querybuf) > 0): 
        # 獲取命令名,參數(shù)個(gè)數(shù),參數(shù)數(shù)組以及當(dāng)前讀取到querybuf位置 
        cmd, argc, argv, pos = parseCommandInfo(client.querybuf) 
        # 執(zhí)行命令 
        processCommand(cmd, argc, argv) 
        # 切換到下一個(gè)命令 
        client.querybuf = client.querybuf[pos:-1] 

parseCommandInfo will be parsed according to different protocols: if the first byte is '*', the standard protocol will be used

Remarks: All redis clients implement the function of sending commands in batches, which is nothing more than sending multiple commands to redis according to the format we just mentioned. Interested readers can refer to the client in the language they are familiar with

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template