Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b698901

Browse files
bitactivemichael-grunder
authored andcommitted
Support for early_refresh in Redis sessions to match cluster behavior
Previously, the redis.session.early_refresh feature was implemented for Redis Cluster, utilizing GETEX for the initial session read to minimize the number of commands sent to the Redis server. However, this enhancement was not applied to non-cluster sessions. This update addresses this discrepancy, ensuring consistent behavior between Redis and Redis Cluster.
1 parent eb7f31e commit b698901

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

redis_session.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,11 @@ PS_UPDATE_TIMESTAMP_FUNC(redis)
645645

646646
if (!skeylen) return FAILURE;
647647

648+
/* No need to update the session timestamp if we've already done so */
649+
if (INI_INT("redis.session.early_refresh")) {
650+
return SUCCESS;
651+
}
652+
648653
redis_pool *pool = PS_GET_MOD_DATA();
649654
redis_pool_member *rpm = redis_pool_get_sock(pool, skey);
650655
RedisSock *redis_sock = rpm ? rpm->redis_sock : NULL;
@@ -698,7 +703,14 @@ PS_READ_FUNC(redis)
698703
/* send GET command */
699704
if (pool->lock_status.session_key) zend_string_release(pool->lock_status.session_key);
700705
pool->lock_status.session_key = redis_session_key(redis_sock, skey, skeylen);
701-
cmd_len = REDIS_SPPRINTF(&cmd, "GET", "S", pool->lock_status.session_key);
706+
707+
/* Update the session ttl if early refresh is enabled */
708+
if (INI_INT("redis.session.early_refresh")) {
709+
cmd_len = REDIS_SPPRINTF(&cmd, "GETEX", "Ssd", pool->lock_status.session_key,
710+
"EX", 2, session_gc_maxlifetime());
711+
} else {
712+
cmd_len = REDIS_SPPRINTF(&cmd, "GET", "S", pool->lock_status.session_key);
713+
}
702714

703715
if (lock_acquire(redis_sock, &pool->lock_status) != SUCCESS) {
704716
php_error_docref(NULL, E_WARNING, "Failed to acquire session lock");

0 commit comments

Comments
 (0)