PHP Redis Bulk Operations

Source: Internet
Author: User

Reference website

Phpredis Extension: Https://github.com/phpredis/phpredis#pconnect-popen

Command reference: Http://doc.redisfans.com Redis

Summary of Redis operation exceptions

1. The obtained key exists, using the wrong method, such as: string with hashes method, return false.

2. Get the nonexistent key false.

3. Set the nonexistent key, write the value, return 1, and return 0 if there is a replacement. With a function of type hsetnx, there is a value that returns false without setting a value, or true setting.

Redis Batch Testing

Batch
$redis = new \redis ();
$redis->pconnect (' 127.0.0.1 ');
$redis->auth (' 111111 ');
$ts = Microtime (true);
Var_dump ($ts);
$redis->multi ();
for ($i =0; $i < $i + +) {
$redis->set (' Key1 ', ' val1 ');
$redis->get (' Key1 ');
$redis->del (' Key1 ');
}
$redis->exec ();
$DF = Microtime (True)-$ts;
Var_dump ($DF);
Var_dump ($ret);
Die
Single
$redis = new \think\cache\driver\redis ();
$ts = Microtime (true);
Var_dump ($ts);
for ($i =0; $i < $i + +) {
$redis->set (' Key1 ', ' val1 ');
$redis->get (' Key1 ');
$redis->del (' Key1 ');
}
$DF = Microtime (True)-$ts;
Var_dump ($DF);
Die

Results Batch: Float (1.11732006073) Single: float (1.2670619487762) can be seen in the Phpredis expansion using the batch and the individual and not too much time on the

Difference and http://my.oschina.net/u/2273085/blog/419920, this netizen conclusion difference is very big, perhaps is php own problem, unknown.

Redis Operations General return condition

Redis gets key type error return False
$keyString = ' 13999999999 ';
$keyHash = ' thumbnailserverlist ';
$redisCache = new \think\cache\driver\redis ();
$return = $redisCache->hgetall ($keyString, $value);
Var_dump ($return);
$return = $redisCache->hgetall ($keyHash, $value);
Var_dump ($return);
$return = $redisCache->get ($keyString, $value);
Var_dump ($return);
$return = $redisCache->get ($keyHash, $value);
Var_dump ($return);
Die

Result:bool (FALSE) bool (false) string "9c8d83f5890611e45538a744eb1b036b156790b7533" bool (FALSE) Get type error returns false, Does not exist and is false.

PHP Redis Bulk Operations

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.