💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、豆包、星火、月之暗面及文生图、文生视频 广告
# 事物 ``` <pre class="calibre29">``` 事务 multi<span class="token3">,</span> exec<span class="token3">,</span> discard <span class="token1">-</span> 进入和退出交易模式 $ret <span class="token1">=</span> $redis<span class="token1">-</span><span class="token1">></span><span class="token4">multi</span><span class="token3">(</span>Redis<span class="token3">:</span><span class="token3">:</span>MULTI<span class="token3">)</span> <span class="token1">-</span><span class="token1">></span><span class="token4">set</span><span class="token3">(</span><span class="token2">'key1'</span><span class="token3">,</span> <span class="token2">'val1'</span><span class="token3">)</span> <span class="token1">-</span><span class="token1">></span><span class="token4">get</span><span class="token3">(</span><span class="token2">'key1'</span><span class="token3">)</span> <span class="token1">-</span><span class="token1">></span><span class="token4">set</span><span class="token3">(</span><span class="token2">'key2'</span><span class="token3">,</span> <span class="token2">'val2'</span><span class="token3">)</span> <span class="token1">-</span><span class="token1">></span><span class="token4">get</span><span class="token3">(</span><span class="token2">'key2'</span><span class="token3">)</span> <span class="token1">-</span><span class="token1">></span><span class="token4">exec</span><span class="token3">(</span><span class="token3">)</span><span class="token3">;</span><span class="token">//array (true,'val1',true, 'val2')</span> watch<span class="token3">[</span><span class="token2">'key1'</span><span class="token3">,</span><span class="token2">'key2'</span><span class="token3">,</span><span class="token2">'keyn'</span><span class="token3">]</span> 监视其他客户端是否修改制定的key 如果在WATCH和EXEC之间修改key,则MULTI<span class="token1">/</span>EXEC事务将失败(返回FALSE) $redis<span class="token1">-</span><span class="token1">></span><span class="token4">watch</span><span class="token3">(</span><span class="token2">'x'</span><span class="token3">)</span><span class="token3">;</span> $ret <span class="token1">=</span> $redis<span class="token1">-</span><span class="token1">></span><span class="token4">multi</span><span class="token3">(</span><span class="token3">)</span> <span class="token1">-</span><span class="token1">></span><span class="token4">incr</span><span class="token3">(</span><span class="token2">'x'</span><span class="token3">)</span> <span class="token1">-</span><span class="token1">></span><span class="token4">exec</span><span class="token3">(</span><span class="token3">)</span><span class="token3">;</span> unwatch<span class="token3">[</span><span class="token2">'key1'</span><span class="token3">,</span><span class="token2">'key2'</span><span class="token3">,</span><span class="token2">'keyn'</span><span class="token3">]</span> 取消 WATCH 命令对所有 key 的监视 如果在执行WATCH命令之后, EXEC命令或DISCARD命令先被执行了的话,那么就不需要再添加这个代码执行UNWATCH了 ``` ```