Download the Redis operation code encapsulated by native PHP. the Redis operation class is provided by the trace Yi blog.
Redis operations
Next we will briefly introduce how to use it.
1. instantiate the Redis operation object
Object Redis ($ host, $ port, [$ quiet_fail [, $ timeout]) # $ host Connection host # $ port connection port # $ quiet_fail (optional, whether to prompt when an exception occurs. the prompt is enabled by default # $ timeout for reading the information stream
Let's take an example.
$obj = new Redis('192.168.144.133',6379);
2. command () function
Redis command () # The number of command function parameters is unlimited # This function is used to set the command to be executed
Let's take a look at the following example. In this example, we can set the value of myblod to "Ji Yi Blog ".
$ Obj-> command ('set', 'myblog', 'recall blog ')
The function of the command () function can be considered as a preprocessing command, but the command to be executed is ready, waiting for other operations to be executed.
3. exec () function
Int exec () # run the command prepared by the command function.
Example
$ Obj-> command ('set', 'myblog', 'recall blog')-> exec ();
4. result () function
Mixed result () # This function is called after the corresponding command is executed # The command is correctly executed to obtain the corresponding result # The Boolean value is returned if the command is executed incorrectly
Example
$ Obj-> command ('set', 'myblog', 'recall blog')-> exec (); $ result = $ obj-> result (); var_dump ($ result );
5. get_errinfo () function
String get_errinfo () # Error message returned by the function # This function is called only when the command execution result is incorrect, that is, when result () returns false.
The following is an example:
$ Obj-> command ('set', 'myblog', 'recall blog')-> exec (); $ result = $ obj-> result (); if (! $ Result) {echo $ obj-> get_errinfo ();}