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