Get the App
SLTechnology News&Howtos  ›  Database  › 

How to use exec of redis in php

Shulou Source: shulou.com Published: 2022-05-31 11:09:11 09月22日 Update

This article mainly explains "how to use the exec of redis in php". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use the exec of redis in php.

In Redis, exec is used to execute commands within all transaction blocks, and the return values of all commands within the transaction block are arranged in the order in which the commands were executed. When the operation is interrupted, the null value "nil" is returned, and the syntax is "redis > Exec".

This article operating environment: Windows10 system, PHP7.1 version, Dell G3 computer.

What is the use of exec of redis in php

The Redis Exec command is used to execute commands within all transaction blocks.

The basic syntax for redis Exec commands is as follows:

Redis 127.0.0.1 6379 > Exec

Return value

The return values of all commands within the transaction block are arranged in the order in which the commands were executed. Returns a null value of nil when the operation is interrupted.

Examples are as follows:

# transaction executed successfully redis 127.0.0.1 INCR user_idQUEUEDredis 6379 > INCR user_idQUEUEDredis 127.0.0.1 INCR user_idQUEUEDredis 6379 > INCR user_idQUEUEDredis 127.0.0.1 INCR user_idQUEUEDredis 6379 > INCR user_idQUEUEDredis 127.0.0.1 INCR user_idQUEUEDredis 127.0.1 PONG# Monitoring key 12) (integer) 23) (integer) 34) PONG# Monitoring key And the transaction successfully executes redis 127.0.0.1 MULTIOKredis 6379 > MULTIOKredis 127.0.0.1 MULTIOKredis 6379 > SET lock "huangz" QUEUEDredis 127.0.0.1 MULTIOKredis 6379 > INCR lock_timesQUEUEDredis 127.0.0.1 MULTIOKredis 6379 > EXEC1) OK2) (integer) monitor key And the transaction was interrupted redis 127.0.0.1 redis 6379 > MULTIOKredis 127.0.0.1 MULTIOKredis 6379 > SET lock "joe" # just then, another client modified the value of lock_times QUEUEDredis 127.0.0.1joe 6379 > INCR lock_timesQUEUEDredis 127.0.0.1 joe 6379 > EXEC # because lock_times was modified, joe transaction execution failed (nil) to this point I believe you have a deeper understanding of "how to use the exec of redis in php", so you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Transaction command success sequence content grammar order learning monitoring practical deeper interest practicality practical customer client simple operation method more friends Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Microsoft vpn macOS MariaDB