Redis事务乐观锁和watch及unwatch机制测试-----Redis

发布时间:2024年01月20日
127.0.0.1:6379> set k1 v1
OK
127.0.0.1:6379> get k1
"v1"
127.0.0.1:6379> hset user:001 id 11 uname li4
(integer) 2
127.0.0.1:6379> set k1 v1
OK
127.0.0.1:6379> expire k1 30
(integer) 1
127.0.0.1:6379> ttl k1
(integer) 26
127.0.0.1:6379> set k1 v1
OK
127.0.0.1:6379> set k2 v2
OK
127.0.0.1:6379> del count
(integer) 0
127.0.0.1:6379> incr count
(integer) 1
127.0.0.1:6379> multi
OK
127.0.0.1:6379(TX)> set k1 v1
QUEUED
127.0.0.1:6379(TX)> set k2 v2
QUEUED
127.0.0.1:6379(TX)> set k3 v3
QUEUED
127.0.0.1:6379(TX)> incr count
QUEUED
127.0.0.1:6379(TX)> exec
1) OK
2) OK
3) OK
4) (integer) 2
127.0.0.1:6379> get k3
"v3"
127.0.0.1:6379> get count
"2"
127.0.0.1:6379> keys *
1) "user:001"
2) "k1"
3) "count"
4) "k3"
5) "k2"
127.0.0.1:6379> multi
OK
127.0.0.1:6379(TX)> set k1 v11
QUEUED
127.0.0.1:6379(TX)> set k2 v22
QUEUED
127.0.0.1:6379(TX)> incr count
QUEUED
127.0.0.1:6379(TX)> discard
OK
127.0.0.1:6379> get count
"2"
127.0.0.1:6379> get k2
"v2"
127.0.0.1:6379> set email zzyybs@126.com
OK
127.0.0.1:6379> multi
OK
127.0.0.1:6379(TX)> set k1 v111
QUEUED
127.0.0.1:6379(TX)> set k2 v222
QUEUED
127.0.0.1:6379(TX)> set k3
(error) ERR wrong number of arguments for 'set' command
127.0.0.1:6379(TX)> exec
(error) EXECABORT Transaction discarded because of previous errors.
127.0.0.1:6379> get k1
"v1"
127.0.0.1:6379> get k2
"v2"
127.0.0.1:6379> get email
"zzyybs@126.com"
127.0.0.1:6379> multi
OK
127.0.0.1:6379(TX)> set k1 v1111
QUEUED
127.0.0.1:6379(TX)> set k2 v2222
QUEUED
127.0.0.1:6379(TX)> incr count
QUEUED
127.0.0.1:6379(TX)> incr email
QUEUED
127.0.0.1:6379(TX)> set k3 v3333
QUEUED
127.0.0.1:6379(TX)> exec
1) OK
2) OK
3) (integer) 3
4) (error) ERR value is not an integer or out of range
5) OK
127.0.0.1:6379> get k1
"v1111"
127.0.0.1:6379> get k2
"v2222"
127.0.0.1:6379> get k3
"v3333"
127.0.0.1:6379> get count
"3"
127.0.0.1:6379> set k1 abc
OK
127.0.0.1:6379> set balance 100
OK
127.0.0.1:6379> get k1
"abc"
127.0.0.1:6379> get balance
"100"
127.0.0.1:6379> watch balance
OK
127.0.0.1:6379> multi
OK
127.0.0.1:6379(TX)> set k1 abc2
QUEUED
127.0.0.1:6379(TX)> set balance 110
QUEUED
127.0.0.1:6379(TX)> exec
1) OK
2) OK
127.0.0.1:6379> get k1
"abc2"
127.0.0.1:6379> get balance
"110"
127.0.0.1:6379> watch balance
OK
127.0.0.1:6379> multi
OK
127.0.0.1:6379(TX)> set balance 200
QUEUED
127.0.0.1:6379(TX)> set k2 xxx
QUEUED
127.0.0.1:6379(TX)> exec
(nil)
127.0.0.1:6379> get k2
"v2222"
127.0.0.1:6379> get balance
"300"
127.0.0.1:6379> watch balance
OK
127.0.0.1:6379> get balance
"300"
127.0.0.1:6379> unwatch
OK
127.0.0.1:6379> multi
OK
127.0.0.1:6379(TX)> set balance 300
QUEUED
127.0.0.1:6379(TX)> get balance
QUEUED
127.0.0.1:6379(TX)> exec
1) OK
2) "300"

127.0.0.1:6379> set k1 v1
OK
127.0.0.1:6379> get k1
"v1"
127.0.0.1:6379> hset user:001 id 11 uname li4
(integer) 2
127.0.0.1:6379> set k1 v1
OK
127.0.0.1:6379> expire k1 30
(integer) 1
127.0.0.1:6379> ttl k1
(integer) 26
127.0.0.1:6379> set k1 v1
OK
127.0.0.1:6379> set k2 v2
OK
127.0.0.1:6379> del count
(integer) 0
127.0.0.1:6379> incr count
(integer) 1
127.0.0.1:6379> multi
OK
127.0.0.1:6379(TX)> set k1 v1
QUEUED
127.0.0.1:6379(TX)> set k2 v2
QUEUED
127.0.0.1:6379(TX)> set k3 v3
QUEUED
127.0.0.1:6379(TX)> incr count
QUEUED
127.0.0.1:6379(TX)> exec
1) OK
2) OK
3) OK
4) (integer) 2
127.0.0.1:6379> get k3
"v3"
127.0.0.1:6379> get count
"2"
127.0.0.1:6379> keys *
1) "user:001"
2) "k1"
3) "count"
4) "k3"
5) "k2"
127.0.0.1:6379> multi
OK
127.0.0.1:6379(TX)> set k1 v11
QUEUED
127.0.0.1:6379(TX)> set k2 v22
QUEUED
127.0.0.1:6379(TX)> incr count
QUEUED
127.0.0.1:6379(TX)> discard
OK
127.0.0.1:6379> get count
"2"
127.0.0.1:6379> get k2
"v2"
127.0.0.1:6379> set email zzyybs@126.com
OK
127.0.0.1:6379> multi
OK
127.0.0.1:6379(TX)> set k1 v111
QUEUED
127.0.0.1:6379(TX)> set k2 v222
QUEUED
127.0.0.1:6379(TX)> set k3
(error) ERR wrong number of arguments for 'set' command
127.0.0.1:6379(TX)> exec
(error) EXECABORT Transaction discarded because of previous errors.
127.0.0.1:6379> get k1
"v1"
127.0.0.1:6379> get k2
"v2"
127.0.0.1:6379> get email
"zzyybs@126.com"
127.0.0.1:6379> multi
OK
127.0.0.1:6379(TX)> set k1 v1111
QUEUED
127.0.0.1:6379(TX)> set k2 v2222
QUEUED
127.0.0.1:6379(TX)> incr count
QUEUED
127.0.0.1:6379(TX)> incr email
QUEUED
127.0.0.1:6379(TX)> set k3 v3333
QUEUED
127.0.0.1:6379(TX)> exec
1) OK
2) OK
3) (integer) 3
4) (error) ERR value is not an integer or out of range
5) OK
127.0.0.1:6379> get k1
"v1111"
127.0.0.1:6379> get k2
"v2222"
127.0.0.1:6379> get k3
"v3333"
127.0.0.1:6379> get count
"3"
127.0.0.1:6379> set k1 abc
OK
127.0.0.1:6379> set balance 100
OK
127.0.0.1:6379> get k1
"abc"
127.0.0.1:6379> get balance
"100"
127.0.0.1:6379> watch balance
OK
127.0.0.1:6379> multi
OK
127.0.0.1:6379(TX)> set k1 abc2
QUEUED
127.0.0.1:6379(TX)> set balance 110
QUEUED
127.0.0.1:6379(TX)> exec
1) OK
2) OK
127.0.0.1:6379> get k1
"abc2"
127.0.0.1:6379> get balance
"110"
127.0.0.1:6379> watch balance
OK
127.0.0.1:6379> multi
OK
127.0.0.1:6379(TX)> set balance 200
QUEUED
127.0.0.1:6379(TX)> set k2 xxx
QUEUED
127.0.0.1:6379(TX)> exec
(nil)
127.0.0.1:6379> get k2
"v2222"
127.0.0.1:6379> get balance
"300"
127.0.0.1:6379> watch balance
OK
127.0.0.1:6379> get balance
"300"
127.0.0.1:6379> unwatch
OK
127.0.0.1:6379> multi
OK
127.0.0.1:6379(TX)> set balance 300
QUEUED
127.0.0.1:6379(TX)> get balance
QUEUED
127.0.0.1:6379(TX)> exec
1) OK
2) "300"

127.0.0.1:6379> set balance 300
OK
127.0.0.1:6379> get balance
"300"
127.0.0.1:6379> set balance 200
OK
127.0.0.1:6379> get balance
"200"
127.0.0.1:6379> get balance
"300"

?127.0.0.1:6379> set balance 300
OK
127.0.0.1:6379> get balance
"300"
127.0.0.1:6379> set balance 200
OK
127.0.0.1:6379> get balance
"200"
127.0.0.1:6379> get balance
"300"

文章来源:https://blog.csdn.net/2201_75960169/article/details/135678344
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。