Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit dc6e530

Browse filesBrowse files
Use zend_hrtime instead of time(NULL) since it's monotonic
`time(NULL)` isn't monotonic and can run backwards so switch to `zend_hrtime` which uses `clock_gettime(CLOCK_MONOTONIC)` on Linux and `QueryPerformanceCounter`on Windows.
1 parent fead6c7 commit dc6e530
Copy full SHA for dc6e530

File tree

1 file changed

+6
-2
lines changed
Filter options

1 file changed

+6
-2
lines changed

‎cluster_library.c

Copy file name to clipboardExpand all lines: cluster_library.c
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,14 +891,18 @@ cluster_free(redisCluster *c, int free_ctx)
891891
if (free_ctx) efree(c);
892892
}
893893

894+
static inline uint64_t redis_time(void) {
895+
return zend_hrtime() / ZEND_NANO_IN_SEC;
896+
}
897+
894898
static zend_long cluster_cache_expiry(void) {
895899
zend_long expiry;
896900

897901
expiry = INI_INT("redis.clusters.slot_cache_expiry");
898902
if (expiry <= 0)
899903
return 0;
900904

901-
return time(NULL) + expiry;
905+
return redis_time() + expiry;
902906
}
903907

904908
#ifdef HAVE_REDIS_ATOMICS_MMAP
@@ -3172,7 +3176,7 @@ PHP_REDIS_API redisCachedCluster *cluster_cache_load(zend_string *hash) {
31723176

31733177
cc = le->ptr;
31743178
/* Short circuit if it should be expired */
3175-
if (cc->expiry != 0 && cc->expiry <= time(NULL))
3179+
if (cc->expiry != 0 && cc->expiry <= redis_time())
31763180
return NULL;
31773181

31783182
#ifdef HAVE_REDIS_ATOMICS_MMAP

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.