7. Basic Redis commands-task queue and redis queue
1. Advantages: loose coupling is easy to expand, and consumers can expand multiple servers.
2. LPUSH RPOP
3. The BRPOP command is similar to RPOP. The only difference is that when there are no elements in the list, the BRPOP command will always block the link and know that new elements are added.
4. If the value of BRPOP key timeout is 0, the waiting time is not limited (in seconds). If no element exists, it will be blocked. For example, BRPOP list 0
5. BRPOP key 1 is blocked for 1 second and data is retrieved. The returned value is an array. The first element is the key name, and the second element is the value. If no data exists, nil 127.0.0.1: 6379> BRPOP list 0 is returned.
1) "list"
2) "13"
(11.46 s)
127.0.0.1: 6379> BRPOP list 2
(Nil)
6. priority queue BLPOP queue: 1 queue2: 2 queue3: 3 0 if all values exist, the queue2 queue value is preferentially retrieved.
7. SUBSCRIBE channel channelNo. clients in the subscription status can only use the following four commands: SUBSCRIBE/UNSUBSCRIBE/PSUBSCRIBE/PUNSUBSCRIBE Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "channel"
3) (integer) 1 can subscribe to multiple message channels at the same time
Wagner. 0.0.1: 6379> SUBSCRIBE channel1 channel2 channel3
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "channel1"
3) (integer) 1
1) "subscribe"
2) "channel2"
3) (integer) 2
1) "subscribe"
2) "channel3"
3) (integer) 3
8. PUBLISH the PUBLISH channel channelNo message. The returned value indicates the number of clients that receive the message. You can also cancel multiple message channels 127.0.0.1: 6379> PUBLISH channel hello
(Integer) 1
9. PSUBSCRIBE channel1 .? * Subscribe to messages of a specified rule. Supports glob-style wildcard formats. If Client A subscribes to psubscribe 1.1 and psubscribe 1 .? *. Then, client B publishes A message to channel1.1, and client A receives two messages.
10. PUNSUBSCRIBE * cannot Unsubscribe the channel. * rule, but must use PUNSUBSCRIBE channel. * unsubscribe
11. The pipeline client and Redis are connected using the TCP protocol. When sending commands to Redis and returning execution results, they all need to be transmitted over the network. One-to-one is called a round-trip delay. If you want to execute multiple commands without interdependent return values, you can use the pipeline technology. Multiple commands are sent to Redis at one time, that is, these commands are sent together through pipeline commands. Pipelines can reduce the number of communications between clients and Redis to reduce the round-trip latency. Similar to batch processing.