- Note: As of this writing the main purpose is to give yourself a memo , if you have studied Redis and hope to find some forgotten knowledge from this article, then you can read this article. Because not a lot to explain in the article, so this article is not suitable for beginners to use white.
1. Transaction
1.1 Introduction to transactions
What is:
- A plurality of commands can be executed, is essentially a collection of commands. All commands will be a transaction serialization
按顺序地串行化执行而不会被其他命令插入,不允许加塞
.
Why can:
a queue, a one-time, sequential, exclusively execute a series of commands.
How to play:
- Common Commands
- Case1: normal execution
- Case2: abandon the transaction
- Case3: all guilt
if a command error occurs upon addition of the transaction, the transaction invalid block all instructions. - Case4: injustice head creditors
if a command can be added to a transaction, but logically false, the transaction is executed in block statement This statement error, but does not affect other statements. - Case5: watch monitor
1.2.Redis transaction command
Example of use:
> MULTI
> set k1 v1
> set k2 v2
> get k2
> set k3 v3
> EXEC
输出结果:
OK
OK
"v2"
OK
1.3.watch monitoring
- A monitor (or more) key, if this (or these) key changes to other orders are executed before the transaction, then the transaction will be interrupted.
monitor
watch key
Cancel Monitoring
unwatch
- Once executed exec operation, before adding the monitor lock will be canceled.
summary:
- By monitoring multiple Keys WATCH command before executing a transaction, if there is any value in Key has changed, transaction EXEC command execution will be abandoned, while the return Nullmulti-bulk reply to inform the caller of the transaction fails after WATCH.
1.4. 3-phase transactions, 3 properties
Stage 3
3 Features
2. Publish and Subscribe
2.1. What is
- A messaging mode of communication between processes: a sender (Pub) sends a message, the subscriber (Sub) receives the message.
- Publish / subscribe message Figure: