Requirements: Some data needs to be exported from the Redis cache via wildcards to troubleshoot issues. NET/C# uses the StackExchange.Redis client to manipulate the Redis cache and export it as a txt file to the local disk. The principle is to filter out all keys through the SCAN command, and then query the value of each key.
The KEYS command in Redis returns all matching keys at once, when there are a lot of keys in Redis, it is a hidden danger for memory consumption and redis server, and for Redis 2.8 and above versions, it provides us with a better command to traverse the keys SCAN.
SCAN returns only a small number of elements per execution, so it can be used in production environments without the problems that can block the server like the KEYS or SMEMBERS commands.
The SCAN command is a cursor-based iterator. This means that each time a command is called, it needs to use the cursor returned by the previous call as the cursor argument for the next call, so as to continue the previous iteration process
When the cursor parameter (i.e., cursor) of the SCAN command is set to 0, the server will start a new iteration, and when the server returns a cursor with a value of 0 to the user, the iteration is over.
Review:
First, we insert 100,000 bars into RedisUser:GUID 格式Data as shown in the figure below:
.NET/C# uses StackExchange.Redis to fuzzly query the "User:*" data and output it to your local disk as a txt file, the source code is as follows:
The renderings are as follows:
(End)
|