標籤:os io ar sp on new ad c as
1.事務 1.1 MULTI和EXEC命令
發送MULTI命令,聲明事務;EXEC執行事務
Redis不支援交易回復
redis 127.0.0.1:6379> SET key 1OKredis 127.0.0.1:6379> SET key 2OKredis 127.0.0.1:6379> SADD key 3(error) ERR Operation against a key holding the wrong kind of valueredis 127.0.0.1:6379> SADD key 3 4(error) ERR Operation against a key holding the wrong kind of valueredis 127.0.0.1:6379> SADD keynew 3(integer) 1redis 127.0.0.1:6379> MUTIL(error) ERR unknown command ‘MUTIL‘redis 127.0.0.1:6379> MULTIOKredis 127.0.0.1:6379> SET key 3QUEUEDredis 127.0.0.1:6379> SET keynew 4QUEUEDredis 127.0.0.1:6379> EXEC1) OK2) OKredis 127.0.0.1:6379> GET key"3"redis 127.0.0.1:6379> GET keynew"4"redis 127.0.0.1:6379>
1.2 Watch命令
監控某個索引值,如果被修改,阻止後面的事務執行。僅僅防禦性質的。
redis 127.0.0.1:6379> SET key 1OKredis 127.0.0.1:6379> WATCH keyOKredis 127.0.0.1:6379> MULTIOKredis 127.0.0.1:6379> SET key 2QUEUEDredis 127.0.0.1:6379> EXEC1) OKredis 127.0.0.1:6379> GET key"2"redis 127.0.0.1:6379>
redis 127.0.0.1:6379> SET keywatch 1OKredis 127.0.0.1:6379> SET keywatch 2OKredis 127.0.0.1:6379> WATCH keywatchOKredis 127.0.0.1:6379> SET keywatch 3OKredis 127.0.0.1:6379> MULTIOKredis 127.0.0.1:6379> SET keywatch 8QUEUEDredis 127.0.0.1:6379> EXEC(nil)redis 127.0.0.1:6379> GET keywatch"3"redis 127.0.0.1:6379>
Redis進階 ----事務