The RedLock algorithm for distributed locks based on Redis and its implementation in RedLock-Hyperf

Introduction Recently, the project required encapsulating a Redis distributed lock under the Hyperf framework, so I encapsulated the RedLock-Hyperf SDK based on the RedLock algorithm. Currently, in addition to supporting simple object calls, it also supports implementation through AOP annotations within the Hyperf framework. Implementing a distributed lock with Redis is probably not a difficult task for you. Most people use the setnx + expire + del commands to implement a simple distributed lock, but is such a mutex really secure? In this article, we will explore together the common implementations of Redis distributed locks and how the officially recommended RedLcok algorithm by Redis ensures the security of the lock. As a side note, although there are distributed locks implemented with Zookeeper and etcd besides Redis, these latter two options bring certain operational costs for a simple action of distributed...

March 18, 2021 · 4 min · 1586 words · ZhangYong

Why does Hyperf disable short names for Swoole coroutines

In the server requirements section of the official Hyperf documentation, it is mentioned: Swoole PHP extension >= 4.5, with Short Name disabled Furthermore, in the documentation’s FAQ section, one can find a tag titledSwoole Short Name Not Disabled. I would like to inquire why it is imperative for Hyperf to disable Swoole’s coroutine short names. First, let’s examine what Swoole’s coroutine short names are All class names prefixed with Swoole\Coroutine are aliased to Co. Additionally, there are the following mappings: the go() function for creating coroutines, the chan() function for channel operations, and the defer() function for deferred execution. From the above explanation, we understand that Hyperf primarily wishes to prevent the use of these specific functions, but why is their use discouraged? Considering that the go() function is often used in code to resolve blocking issues, does this mean...

January 12, 2021 · 2 min · 525 words · ZhangYong

Hyperf/Crontab Component Source Code Analysis

Pre-Read:Hyperf/Crontab Documents Pre-Read:Hyperf/Process Custom Process Documents Pre-Read:Hyperf Event System Introduction Previously, while working on a project, I used the Hyperf/Crontab component for second-level data cleansing. Recently, as I’ve been working on splitting scheduled tasks, I decided to go through the component source code to deepen my understanding and, at the same time, contemplate how to build a task scheduling feature based on Hyperf/Crontab. At its core, Crontab is a custom process that starts with the Server, so we will introduce it in...

June 2, 2020 · 3 min · 1199 words · ZhangYong