preface
In the learning process, it is found that the Zset of redis can also be used to realize the lightweight delayed message queuing function. Although the reliability needs to be improved, it can be realized for some functions that require less data reliability. This paper mainly uses zadd, zrangebycore and zdel in Zset of redis to realize a small demo.
Prepare to install redis, redis go in advance
Because the Mac OS is used
Installing Redis is really simple on a Mac OS. Follow these steps and you are good to go:Download the package from Internet. This website uses cookies and other tracking technology to analyse traffic, personalise ads and learn how we can improve the experience for our visitors and customers. The most advanced Redis client for Mac. Red looks great in Dark Mode in Mac OS Mojave. Swiftly Efficient - Red is written in native Swift, exclusively for the Mac.
Because it is lazy, the objectid in bson is directly used to generate the unique ID of the task
The unique ID is not required, but if there is a practical application to carry, it is easy to find the corresponding task.
Redis Client Mac Os X
producer
10W tasks are generated through a for loop, each with a different time
The addjob function is in another package, which takes the randomly generated time in the previous function as the timestamp to be processed
consumer
The consumer processing process is divided into two steps:
- Gets tasks less than or equal to the current timestamp
- By deleting the current task to determine who has obtained the current task
This is because when obtaining tasks less than or equal to the current timestamp, multiple go routines may read the current task at the same time, and only one task can process the current task. Therefore, we need to use a scheme to determine who will handle the task (of course, if only one consumer can read it, it will be handled directly): at this time, it can be obtained through the deletion operation of redis, because only the successful operation will return non-zero when deleting the specified value, so we can think of the go that successfully deleted the current queue Routine got the current assignment.
Here is the code:
Redis part of the code, get the task and delete the task
That's pretty much the code. Finally, after running, I can deal with 1W tasks every 3-4 seconds
Redis Client Mac Os High Sierra
The above is the whole content of this article, I hope to help you in your study, and I hope you can support developeppaer more.
Redis uses a standard practice for its versioning: major.minor.patchlevel. An even minor marks a stable release, like 1.2, 2.0, 2.2, 2.4, 2.6, 2.8. Odd minors are used for unstable releases, for example 2.9.x releases are the unstable versions of what will be Redis 3.0 once stable.
Unstable
This is where all the development happens. Only for hard-core hackers. Use only if you need to test the latest features or performance improvements. This is going to be the next Redis release in a few months.Pre-release (6.2)
Redis 6.2 includes many new commands and improvements, but no big features. It mainly makes Redis more complete and addresses issues that have been requested by many users frequently or for a long time.Stable (6.0)
Redis 6.0 introduces SSL, the new RESP3 protocol, ACLs, client side caching, diskless replicas, I/O threads, faster RDB loading, new modules APIs and many more improvements.Docker Hub
It is possible to get Docker images of Redis from the Docker Hub. Multiple versions are available, usually updated in a short time after a new release is available.In the Cloud
Get a free-for-life Redis instance with Redis Cloud Essentials from Redis Labs, the home of Redis.
*Other versions
Old (5.0)
Redis 5.0 is the first version of Redis to introduce the new stream data type with consumer groups, sorted sets blocking pop operations, LFU/LRU info in RDB, Cluster manager inside redis-cli, active defragmentation V2, HyperLogLogs improvements and many other improvements. Redis 5 was release as GA in October 2018.See the release notes or download 5.0.10.
*Other
Historical downloads are still available on https://download.redis.io/.Scripts and other automatic downloads can easily access the tarball of the latest Redis stable version at https://download.redis.io/redis-stable.tar.gz, and its respective SHA256 sum at https://download.redis.io/redis-stable.tar.gz.SHA256SUM. The source code of the latest stable release is always browsable here, use the file src/version.h in order to extract the version in an automatic way.
*How to verify files for integrity
The Github repository redis-hashes contains a README file with SHA1 digests of released tarball archives. Note: the generic redis-stable.tar.gz tarball does not match any hash because it is modified to untar to the redis-stable directory.
*Installation
*From source code
Download, extract and compile Redis with:
The binaries that are now compiled are available in the src
directory. Run Redis with:
You can interact with Redis using the built-in client:
*From the official Ubuntu PPA
The above is the whole content of this article, I hope to help you in your study, and I hope you can support developeppaer more.
Redis uses a standard practice for its versioning: major.minor.patchlevel. An even minor marks a stable release, like 1.2, 2.0, 2.2, 2.4, 2.6, 2.8. Odd minors are used for unstable releases, for example 2.9.x releases are the unstable versions of what will be Redis 3.0 once stable.
Unstable
This is where all the development happens. Only for hard-core hackers. Use only if you need to test the latest features or performance improvements. This is going to be the next Redis release in a few months.Pre-release (6.2)
Redis 6.2 includes many new commands and improvements, but no big features. It mainly makes Redis more complete and addresses issues that have been requested by many users frequently or for a long time.Stable (6.0)
Redis 6.0 introduces SSL, the new RESP3 protocol, ACLs, client side caching, diskless replicas, I/O threads, faster RDB loading, new modules APIs and many more improvements.Docker Hub
It is possible to get Docker images of Redis from the Docker Hub. Multiple versions are available, usually updated in a short time after a new release is available.In the Cloud
Get a free-for-life Redis instance with Redis Cloud Essentials from Redis Labs, the home of Redis.
*Other versions
Old (5.0)
Redis 5.0 is the first version of Redis to introduce the new stream data type with consumer groups, sorted sets blocking pop operations, LFU/LRU info in RDB, Cluster manager inside redis-cli, active defragmentation V2, HyperLogLogs improvements and many other improvements. Redis 5 was release as GA in October 2018.See the release notes or download 5.0.10.
*Other
Historical downloads are still available on https://download.redis.io/.Scripts and other automatic downloads can easily access the tarball of the latest Redis stable version at https://download.redis.io/redis-stable.tar.gz, and its respective SHA256 sum at https://download.redis.io/redis-stable.tar.gz.SHA256SUM. The source code of the latest stable release is always browsable here, use the file src/version.h in order to extract the version in an automatic way.
*How to verify files for integrity
The Github repository redis-hashes contains a README file with SHA1 digests of released tarball archives. Note: the generic redis-stable.tar.gz tarball does not match any hash because it is modified to untar to the redis-stable directory.
*Installation
*From source code
Download, extract and compile Redis with:
The binaries that are now compiled are available in the src
directory. Run Redis with:
You can interact with Redis using the built-in client:
*From the official Ubuntu PPA
You can install the latest stable version of Redis from the redislabs/redis
package repository. Add the repository to the apt
index, update it and install:
*From Snapcraft
You can install the latest stable version of Redis from the Snapcraft marketplace:
Mac Os Download
Are you new to Redis? Try our online, interactive tutorial.