The use of Redis things

Source: Internet
Author: User

Several things for Redis command:

WATCHMonitor one (or more) key, if this (or these) key is changed by other commands before the transaction executes, then the transaction will be interrupted;
unwatchcancels the watch command's monitoring of all keys;
MULTImarks the beginning of a transaction block, meaning that multiple commands within a transaction block are placed in a queue in order of precedence and executed by the EXEC command atomically (atomic);
DISCARDcancels the transaction, discarding all commands within the transaction block;
EXECexecute commands within all the transaction blocks;

How to implement Phpredis:

The invocation of a transaction has two modes Redis::multi and Redis::P ipeline, the default is Redis::multi mode, Redis::P ipeline pipeline mode is faster, but there is no guarantee that atomicity can cause data loss.

code example:

<?php$redis = new Redis (), $redis->connect (' 127.0.0.1 ', 6379); $startTime = Microtimefloat (); $pipe = $redis    multi (Redis::P ipeline); for ($i = 0; $i < 100000; $i + +) {$pipe->set ("Key:: $i", Time ()); $pipe->get ("Key:: $i");} $pipe->exec ();//$redis->flushdb (); $endTime = Microtimefloat (); $runTime = $endTime-$startTime; Echo $runTime    Seconds "; function microtimefloat () {list ($usec, $sec) = Explode (" ", Microtime ()); return (float) $usec + (float) $sec); >


The use of Redis things

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.