A Redis usage bug record (EXEC)

Source: Internet
Author: User

In one project, the blogger used the Redis class in the tool class because the Redis did not encapsulate the pipeline pipeline and EXEC commands, so pen a __call.

The code is as follows (where $this->_connect () returns a Redis instance).

After the things feel Chinese can not be expressed, the code is similar to

$redis->pipeline ();

$redis->lpop ($key);

$redis->lpop ($key);

$redis->exec ();

After you have written a simple example test, you should normally return the top two stack elements in the $key queue, that is, array (' item1 ', ' item2 '), but the result of the final return is null.

Super doubt, is it call_user_fun_array () The function of this application is the return value of wood, and so on, that this is not the pit dead daddy. And this is just a person guess, PHP treasure Book in the hand is not empty, found that there is no such

Description, but there is a simple example of this: The following example, plus a personal test, is a return value, which means that this conjecture is unsuccessful.

OK, can only continue to debug, long after the wood has found problems, ask the company a colleague, he came to find you said that since it is $this->_connect () is a Redis object,

There is not a $this->_redis handle, direct replacement, and then in the magical thing happened, there is a return value.

Well, the question can be guessed twos, this certainly shows that $this->_connect () and $this->_redis there must be something different, such as the above code, we directly dump two variables.

It was then discovered that, as crossing should understand, this is fundamentally different two resources.

Feeling aware of the problem, returned to see the _connect () function, found that there is no Redis singleton, each time is a new Redis object.

So still do not know the problem is crossing can continue to follow elder brother go down.

This problem, we technical people do not say anything, on the code, in a batch of REDIS Operations Command, the use of three different Redis objects, the third is direct exec, even pipeline are wood, that is definitely null.

This you believe, anyway, I am a letter, I am also drunk, of course, I also pit myself. The problem comes to the truth. There was a strange way of playing in the pit.

A Redis usage bug record (EXEC)

Related Article

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.