1. Pipeline
The Redis pipeline (Pipelining) sends multiple commands at once
Save round trip time
Reduce communication costs
** Important note ** : When piping a command, the server will be forced to reply to a queue, consuming a lot of memory.
2. Publish and subscribe Pub/Sub
2.1 Application Scenarios
- Publish and subscribe system logs
- Sentinels find each other
- Publish and subscribe decouple the business
2.2 Common Commands
** PUBLISH channel message**
Sends the message to the specified channel, channel
Time complexity: O(N+M)
N is the number of subscribers to channel
M is the number of clients using Subscribed patterns.
** SUBSCRIBE channel [channel …] 支那
Subscribe to information for a specified channel
Time complexity: O(N)
N is the number of channels subscribed to.
** UNSUBSCRIBE [channel [channel …]]**
Instructs the client to unsubscribe from a given channel or all channels if no channel is specified
Time complexity: O(N)
N is the number of channels subscribed to.
** PSUBSCRIBE pattern [pattern …] 支那
Subscribe to a given pattern pattern is a match to a channel
Time complexity: O(N)
N is the number of subscribed modes.
** PUNSUBSCRIBE [pattern [pattern …]] **
Instructs the client to unsubscribe from the specified schema or exit all schemas if no schema is provided
Time complexity: O(N+M)
N is the number of schemas subscribed by the client
M is the number of modes subscribed by all clients in the system.
** PUBSUB subcommand [argument [argument …]] **
PUBSUB is an introspective command that looks at the status of a subscription and publishing system. It consists of several subcommands in different formats
- PUBSUB CHANNELS [pattern]
Lists the current active Channels. Active means the channel has one or more subscribers
Responds only to SUBSCRIBE UNSUBSCRIBE commands
- PUBSUB NUMSUB [channel-1 … channel-N]
Lists the number of subscribers for the specified channel
Responds only to SUBSCRIBE UNSUBSCRIBE commandsCopy the code
- PUBSUB NUMPAT
Returns the number of subscription patterns
Responds only to the PSUBSCRIBE PUNSUBSCRIBE command
3. The transaction
A set of commands is processed in the same transaction.
Redis is single-process, if there are more than one client sent instructions are queued to execute.
Redis transactions do not support rollback and, unlike database transactions, remain simple and fast
When a transaction is executed, the client whose EXEC command arrives first will be executed first, as shown in the following figure:
3.1 Common Commands
** MULTI **
Open the transaction
** EXEC **
Perform transactions
With WATCH, EXEC is executed only if the monitored key is not modified and the setup mechanism is allowed to be checked
** DISCARD **
Abort transaction execution
DISCARD releases all WATCH keys when a WATCH is present
** WATCH key [key …] 支那
Flags that all specified keys are monitored for conditional execution in a transaction (optimistic locking)
** UNWATCH **
Unmonitor all keys with the WATCH command
If you perform EXEC or DISCARD, you do not need to manually execute UNWATCH
Four Modules – RedisBloom
RedisBloom extension program, provides 4 kinds of data structures, Bloom Filter, a cuckoo filter, a count-min Sketch, a top-K.
Bloom and Cuckoo filter are used to determine whether an element is an element of a set, how it works
A count-min Sketch is used as a frequency table for events in the data stream, and the hash function maps events to frequencies
A top-k is used to maintain the k most frequently occurring sequences
4.1 Bloom Filter
Use bloom filters to reduce disk IO or network requests
** Note ** when using Bloom Filter
- It’s penetrating. It doesn’t exist
- Client, add key and value tags in Redis
- The database adds elements
- Finish adding the element to bloom
Bloom shortcomings
- The query performance is relatively weak because it uses hash functions to jump from point to point on the bitmap, making it difficult to exploit the CPU cache
- Deletion not supported
4.2 cuckoo Filter
Cuckoo filters are not implemented using bitmaps, but one-dimensional arrays. What it stores is a fingerprint of the data
Refer to websites and pages
redis.cn/
redis.io/
Blog.csdn.net/cs958903980…