First, Introduction
Ssdb's PHP API provides a convenient interface for PHP development. git address https://github.com/ideawu/ssdb.git, SSDB Official document address http://ssdb.io/zh_cn/
Second, the SSDB class structure diagram
PHP interface source files in/api/php/ssdb.php
Third, SSDB network protocol
Message
' \ n ' Block :'\ n'\ n'Size := literal_integerdata := Size_bytes_of_data
Request
Request: = cmd blocks*cmd := Block
Request commands include:get, set, del, ...
Response
Response: = Status block*status := Block
Response status codes include:ok, not_found, error, fail, client_error
Example
Connect to the SSDB server with a telnet or NC command, and enter the following code (ending with the last line of Blank lines):
3 Get 3 Key
You will see a response similar to this:
2 OK 3 Val
In send processing in the API, the CMD and Argus are sent to the server in the format of the network protocol. The relevant code is as follows
Private functionSend$data){ $ps=Array(); foreach($data as $p){ $ps[] =strlen($p); $ps[] =$p; } $s=Join("\ n",$ps) . "\ n"; if($this-Debug) { Echo' > '.Str_replace(Array("\ r", "\ n"),Array(' \ r ', ' \ n '),$s) . "\ n"; } Try{ while(true){ $ret= @fwrite($this->sock,$s); if($ret==false){ $this-Close (); Throw NewSsdbexception (' Connection lost '); } $s=substr($s,$ret); if(strlen($s) = = 0){ Break; } @Fflush($this-sock); } }Catch(Exception $e){ $this-Close (); Throw NewSsdbexception ($e-getMessage ()); } return $ret; }
A brief analysis of Ssdb PHP API