Download the Redis operation code encapsulated by native PHP

Source: Internet
Author: User
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 ();}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.