127.0.0.1:6379> set name aaa
OK
127.0.0.1:6379> get name
"aaa"
127.0.0.1:6379> multi
OK
127.0.0.1:6379> set name bbb
QUEUED
127.0.0.1:6379> get name
QUEUED
127.0.0.1:6379> exec
1) OK
2) "bbb"
127.0.0.1:6379> get name
"bbb"
2.数据类型有错的事务
127.0.0.1:6379> get name
"bbb"
127.0.0.1:6379> multi
OK
127.0.0.1:6379> set name ccc
QUEUED
127.0.0.1:6379> get name
QUEUED
127.0.0.1:6379> lpush name 1 2
QUEUED
127.0.0.1:6379> exec
1) OK
2) "ccc"
3) (error) WRONGTYPE Operation against a key holding the wrong kind of value
127.0.0.1:6379> get name
"ccc"
3.命令有错的事务
127.0.0.1:6379> get name
"ccc"
127.0.0.1:6379> multi
OK
127.0.0.1:6379> set name ddd
QUEUED
127.0.0.1:6379> get name
QUEUED
127.0.0.1:6379> tttt name
(error) ERR unknown command `tttt`, with args beginning with: `name`,
127.0.0.1:6379> exec
(error) EXECABORT Transaction discarded because of previous errors.
127.0.0.1:6379> get name
"ccc"
4.锁
客户端A
①
127.0.0.1:6379> get count
"100"
127.0.0.1:6379> watch count
OK
127.0.0.1:6379> multi
OK
127.0.0.1:6379> set name aaa
QUEUED
127.0.0.1:6379> get name
QUEUED
③
127.0.0.1:6379> exec
(nil)
127.0.0.1:6379> get count
"1000"
127.0.0.1:6379> get name
"ddd"
客户端B
②
127.0.0.1:6379> set count 1000
OK
5.解锁
客户端A
①
127.0.0.1:6379> setnx lock-age 18
(integer) 1
127.0.0.1:6379> setnx lock-age 20
(integer) 0
③
127.0.0.1:6379> del lock-age
(integer) 1
客户端B
②
127.0.0.1:6379> setnx lock-age 20
(integer) 0
127.0.0.1:6379> get lock-age
"18"
④
127.0.0.1:6379> get lock-age
(nil)
127.0.0.1:6379> set lock-age 21
OK
1.正常的事务127.0.0.1:6379> set name aaaOK127.0.0.1:6379> get name"aaa"127.0.0.1:6379> multiOK127.0.0.1:6379> set name bbbQUEUED127.0.0.1:6379> get nameQUEUED127.0.0.1:6379> exec1) OK2) "bbb"127.0.0.1:6379> get name"bbb"2.数