Skip to content

Add session locking support to RedisCluster#2836

Open
rveznaver wants to merge 1 commit into
phpredis:developfrom
rveznaver:cluster_session_lock
Open

Add session locking support to RedisCluster#2836
rveznaver wants to merge 1 commit into
phpredis:developfrom
rveznaver:cluster_session_lock

Conversation

@rveznaver
Copy link
Copy Markdown

Inspired by #2738, I started wondering if it would be possible to add support for session locking into RedisCluster.

I started thinking about distributed locks... mostly if I could avoid them at all if possible. So my idea was to couple the session with its lock and make the write and reads atomic (or a transaction in relational DB terms), and for that I would need to put them both on the same node. Luckily, Redis supports this with hash tags. (Funnily enough, after I started working and digging about it I later found out that someone already had the same idea.)

Now, the last time I have written anything in C was a very long time ago, but I do believe I remember enough to read it. I have utilised both Claude Opus 4.7 extra high thinking and GPT 5.5 extra high thinking to help me in this endeavour, and then proceeded to manually review every single function it added. You may notice that most of the locking functions read as if they are a mirror of the standalone session handling code. This is on purpose as I copied them over before adapting them to work on the cluster, and even went so far as to define the REDIS_CLUSTER_SPPRINTF macro in library.h to mirror the REDIS_SPPRINTF one. So if you are used to reading the session handling code, this should be functionally identical.

The main deviations from the standalone session flow are:

  • added functions to generate the lock key using hash tags (session key hash tag validation was copied over from Redis source code, lock key generation was made by me)
  • added a LUA script to both acquire the lock and read the session (I hope I got that one right)
  • if session locking is enabled, we always go to the writer (but we should support cluster topology change)

I have left out the separate docker tests the LLMs have built as I do not see any in this repo and did not really have time to clean up and review those as closely as I have the code.

I am also very sorry for this behemoth of a pull request, I really tried to keep it as minimal and as close to current code as possible for a possible review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant