[Redis-CentOS7]Redis事务操作(六)
事务操作
- 隔离操作: 事务中所有的命令都会序列化,按顺序执行,不会被其他命令打扰
原子操作: 事务中所有的命令要么全部执行,要么全部不执行
添加事务并执行
127.0.0.1:6379> MULTI # 开启事务 OK 127.0.0.1:6379> INCR user_id # user_id+1 QUEUED 127.0.0.1:6379> INCR user_id QUEUED 127.0.0.1:6379> INCR user_id QUEUED 127.0.0.1:6379> PING # 发送信息 QUEUED 127.0.0.1:6379> EXEC 1) (integer) 1 2) (integer) 2 3) (integer) 3 4) PONG
DISCARD退出事务
127.0.0.1:6379> MULTI OK 127.0.0.1:6379> set username 'peigy' QUEUED 127.0.0.1:6379> set password 'password' QUEUED 127.0.0.1:6379> PING "set ok" QUEUED 127.0.0.1:6379> DISCARD OK
监听防止事务修改
127.0.0.1:6379> set lock lock_times OK 127.0.0.1:6379> watch lock lock_times OK 127.0.0.1:6379> keys * 1) "user_id" 2) "lock" 127.0.0.1:6379> MULTI OK 127.0.0.1:6379> set lock lock_times1 QUEUED 127.0.0.1:6379> EXEC (nil)
解除监听
127.0.0.1:6379> UNWATCH OK
相关推荐
spurity 2020-11-10
LeeLuffy 2020-10-16
DriveCar 2020-09-07
xkorey 2020-09-14
zjuwangleicn 2020-09-04
dongtiandeyu 2020-08-18
Langeldep 2020-08-16
gamestart0 2020-08-15
loviezhang 2020-08-08
gaozhennan 2020-08-03
mcvsyy 2020-08-02
wenjieyatou 2020-07-30
happinessaflower 2020-07-29
花落花开春去秋来 2020-07-29
solarspot 2020-07-28
powrexly 2020-07-20
牧场SZShepherd 2020-07-20
qingjiuquan 2020-07-18