8000 Implement several hash expiration commands · phpredis/phpredis@7350768 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7350768

Browse files
Implement several hash expiration commands
Commands implemented: `H[P]EXPIRE` `H[P]TTL` `H[P]EXPIREAT` `H[P]EXPIRETIME` `HPERSIST`
1 parent 593ba01 commit 7350768

12 files changed

+622
-6
lines changed

library.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2027,7 +2027,7 @@ redis_hello_response(INTERNAL_FUNCTION_PARAMETERS,
20272027
array_init(&z_ret);
20282028

20292029
if (redis_read_multibulk_recursive(redis_sock, numElems, 0, &z_ret) != SUCCESS ||
2030-
array_zip_values_recursive(&z_ret) != SUCCESS)
2030+
array_zip_values_recursive(&z_ret) != SUCCESS)
20312031
{
20322032
zval_dtor(&z_ret);
20332033
goto fail;

redis.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,6 +1878,51 @@ PHP_METHOD(Redis, hMset)
18781878
}
18791879
/* }}} */
18801880

1881+
PHP_METHOD(Redis, hexpire) {
1882+
REDIS_PROCESS_KW_CMD("HEXPIRE", redis_hexpire_cmd,
1883+
redis_read_variant_reply);
1884+
}
1885+
1886+
PHP_METHOD(Redis, hpexpire) {
1887+
REDIS_PROCESS_KW_CMD("HPEXPIRE", redis_hexpire_cmd,
1888+
redis_read_variant_reply);
1889+
}
1890+
1891+
PHP_METHOD(Redis, hexpireat) {
1892+
REDIS_PROCESS_KW_CMD("HEXPIREAT", redis_hexpire_cmd,
1893+
redis_read_variant_reply);
1894+
}
1895+
1896+
PHP_METHOD(Redis, hpexpireat) {
1897+
REDIS_PROCESS_KW_CMD("HPEXPIREAT", redis_hexpire_cmd,
1898+
redis_read_variant_reply);
1899+
}
1900+
1901+
PHP_METHOD(Redis, httl) {
1902+
REDIS_PROCESS_KW_CMD("HTTL", redis_httl_cmd,
1903+
redis_read_variant_reply);
1904+
}
1905+
1906+
PHP_METHOD(Redis, hpttl) {
1907+
REDIS_PROCESS_KW_CMD("HPTTL", redis_httl_cmd,
1908+
redis_read_variant_reply);
1909+
}
1910+
1911+
PHP_METHOD(Redis, hexpiretime) {
1912+
REDIS_PROCESS_KW_CMD("HEXPIRETIME", redis_httl_cmd,
1913+
redis_read_variant_reply);
1914+
}
1915+
1916+
PHP_METHOD(Redis, hpexpiretime) {
1917+
REDIS_PROCESS_KW_CMD("HPEXPIRETIME", redis_httl_cmd,
1918+
redis_read_variant_reply);
1919+
}
1920+
1921+
PHP_METHOD(Redis, hpersist) {
1922+
REDIS_PROCESS_KW_CMD("HPERSIST", redis_httl_cmd,
1923+
redis_read_variant_reply);
1924+
}
1925+
18811926
/* {{{ proto bool Redis::hRandField(string key, [array $options]) */
18821927
PHP_METHOD(Redis, hRandField)
18831928
{

redis.stub.php

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,6 +1913,121 @@ public function hStrLen(string $key, string $field): Redis|int|false;
19131913
*/
19141914
public function hVals(string $key): Redis|array|false;
19151915

1916+
/**
1917+
* Set the expiration on one or more fields in a hash.
1918+
*
1919+
* @param string $key The hash to update.
1920+
* @param int $ttl The time to live in seconds.
1921+
* @param array $fields The fields to set the expiration on.
1922+
* @param string|null $option An optional mode (NX, XX, ETC)
1923+
* @return Redis|array|false
1924+
*
1925+
* @see https://redis.io/commands/hexpire
1926+
*/
1927+
public function hexpire(string $key, int $ttl, array $fields,
1928+
?string $mode = NULL): Redis|array|false;
1929+
1930+
/**
1931+
* Set the expiration on one or more fields in a hash in milliseconds.
1932+
*
1933+
* @param string $key The hash to update.
1934+
* @param int $ttl The time to live in milliseconds.
1935+
* @param array $fields The fields to set the expiration on.
1936+
* @param string|null $option An optional mode (NX, XX, ETC)
1937+
* @return Redis|array|false
1938+
*
1939+
* @see https://redis.io/commands/hexpire
1940+
*/
1941+
public function hpexpire(string $key, int $ttl, array $fields,
1942+
?string $mode = NULL): Redis|array|false;
1943+
1944+
/**
1945+
* Set the expiration time on one or more fields of a hash.
1946+
*
1947+
* @param string $key The hash to update.
1948+
* @param int $time The time to live in seconds.
1949+
* @param array $fields The fields to set the expiration on.
1950+
* @param string|null $option An optional mode (NX, XX, ETC)
1951+
* @return Redis|array|false
1952+
*
1953+
* @see https://redis.io/commands/hexpire
1954+
*/
1955+
public function hexpireat(string $key, int $time, array $fields,
1956+
?string $mode = NULL): Redis|array|false;
1957+
1958+
/**
1959+
* Set the expiration time on one or more fields of a hash in milliseconds.
1960+
*
1961+
* @param string $key The hash to update.
1962+
* @param int $mstime The time to live in milliseconds.
1963+
* @param array $fields The fields to set the expiration on.
1964+
* @param string|null $option An optional mode (NX, XX, ETC)
1965+
* @return Redis|array|false
1966+
*
1967+
* @see https://redis.io/commands/hexpire
1968+
*/
1969+
public function hpexpireat(string $key, int $mstime, array $fields,
1970+
?string $mode = NULL): Redis|array|false;
1971+
1972+
/**
1973+
* Get the TTL of one or more fields in a hash
1974+
*
1975+
* @param string $key The hash to query.
1976+
* @param array $fields The fields to query.
1977+
*
1978+
* @return Redis|array|false
1979+
*
1980+
* @see https://redis.io/commands/httl
1981+
*/
1982+
public function httl(string $key, array $fields): Redis|array|false;
1983+
1984+
/**
1985+
* Get the millisecond TTL of one or more fields in a hash
1986+
*
1987+
* @param string $key The hash to query.
1988+
* @param array $fields The fields to query.
1989+
*
1990+
* @return Redis|array|false
1991+
*
1992+
* @see https://redis.io/commands/hpttl
1993+
*/
1994+
public function hpttl(string $key, array $fields): Redis|array|false;
1995+
1996+
/**
1997+
* Get the expiration time of one or more fields in a hash
1998+
*
1999+
* @param string $key The hash to query.
2000+
* @param array $fields The fields to query.
2001+
*
2002+
* @return Redis|array|false
2003+
*
2004+
* @see https://redis.io/commands/hexpiretime
2005+
*/
2006+
public function hexpiretime(string $key, array $fields): Redis|array|false;
2007+
2008+
/**
2009+
* Get the expiration time in milliseconds of one or more fields in a hash
2010+
*
2011+
* @param string $key The hash to query.
2012+
* @param array $fields The fields to query.
2013+
*
2014+
* @return Redis|array|false
2015+
*
2016+
* @see https://redis.io/commands/hpexpiretime
2017+
*/
2018+
public function hpexpiretime(string $key, array $fields): Redis|array|false;
2019+
2020+
/**
2021+
* Persist one or more hash fields
2022+
*
2023+
* @param string $key The hash to query.
2024+
* @param array $fields The fields to query.
2025+
*
2026+
* @return Redis|array|false
2027+
*
2028+
* @see https://redis.io/commands/hpersist
2029+
*/
2030+
public function hpersist(string $key, array $fields): Redis|array|false;
19162031

19172032
/**
19182033
* Iterate over the fields and values of a hash in an incremental fashion.

redis_arginfo.h

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 3a08bc16dd5a73e721e0df8f7843acdbbb585df5 */
2+
* Stub hash: c6205649cd23ff2b9fcc63a034b601ee566ef236 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___construct, 0, 0, 0)
55
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 1, "null")
@@ -464,6 +464,39 @@ ZEND_END_ARG_INFO()
464464

465465
#define arginfo_class_Redis_hVals arginfo_class_Redis_getWithMeta
466466

467+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_hexpire, 0, 3, Redis, MAY_BE_ARRAY|MAY_BE_FALSE)
468+
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
469+
ZEND_ARG_TYPE_INFO(0, ttl, IS_LONG, 0)
470+
ZEND_ARG_TYPE_INFO(0, fields, IS_ARRAY, 0)
471+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_STRING, 1, "NULL")
472+
ZEND_END_ARG_INFO()
473+
474+
#define arginfo_class_Redis_hpexpire arginfo_class_Redis_hexpire
475+
476+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_hexpireat, 0, 3, Redis, MAY_BE_ARRAY|MAY_BE_FALSE)
477+
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
478+
ZEND_ARG_TYPE_INFO(0, time, IS_LONG, 0)
479+
ZEND_ARG_TYPE_INFO(0, fields, IS_ARRAY, 0)
480+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_STRING, 1, "NULL")
481+
ZEND_END_ARG_INFO()
482+
483+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_hpexpireat, 0, 3, Redis, MAY_BE_ARRAY|MAY_BE_FALSE)
484+
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
485+
ZEND_ARG_TYPE_INFO(0, mstime, IS_LONG, 0)
486+
ZEND_ARG_TYPE_INFO(0, fields, IS_ARRAY, 0)
487+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_STRING, 1, "NULL")
488+
ZEND_END_ARG_INFO()
489+
490+
#define arginfo_class_Redis_httl arginfo_class_Redis_hMget
491+
492+
#define arginfo_class_Redis_hpttl arginfo_class_Redis_hMget
493+
494+
#define arginfo_class_Redis_hexpiretime arginfo_class_Redis_hMget
495+
496+
#define arginfo_class_Redis_hpexpiretime arginfo_class_Redis_hMget
497+
498+
#define arginfo_class_Redis_hpersist arginfo_class_Redis_hMget
499+
467500
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_hscan, 0, 2, Redis, MAY_BE_ARRAY|MAY_BE_BOOL)
468501
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
469502
ZEND_ARG_TYPE_MASK(1, iterator, MAY_BE_NULL|MAY_BE_LONG|MAY_BE_STRING, NULL)
@@ -1292,6 +1325,15 @@ ZEND_METHOD(Redis, hSet);
12921325
ZEND_METHOD(Redis, hSetNx);
12931326
ZEND_METHOD(Redis, hStrLen);
12941327
ZEND_METHOD(Redis, hVals);
1328+
ZEND_METHOD(Redis, hexpire);
1329+
ZEND_METHOD(Redis, hpexpire);
1330+
ZEND_METHOD(Redis, hexpireat);
1331+
ZEND_METHOD(Redis, hpexpireat);
1332+
ZEND_METHOD(Redis, httl);
1333+
ZEND_METHOD(Redis, hpttl);
1334+
ZEND_METHOD(Redis, hexpiretime);
1335+
ZEND_METHOD(Redis, hpexpiretime);
1336+
ZEND_METHOD(Redis, hpersist);
12951337
ZEND_METHOD(Redis, hscan);
12961338
ZEND_METHOD(Redis, expiremember);
12971339
ZEND_METHOD(Redis, expirememberat);
@@ -1553,6 +1595,15 @@ static const zend_function_entry class_Redis_methods[] = {
15531595
ZEND_ME(Redis, hSetNx, arginfo_class_Redis_hSetNx, ZEND_ACC_PUBLIC)
15541596
ZEND_ME(Redis, hStrLen, arginfo_class_Redis_hStrLen, ZEND_ACC_PUBLIC)
15551597
ZEND_ME(Redis, hVals, arginfo_class_Redis_hVals, ZEND_ACC_PUBLIC)
1598+
ZEND_ME(Redis, hexpire, arginfo_class_Redis_hexpire, ZEND_ACC_PUBLIC)
1599+
ZEND_ME(Redis, hpexpire, arginfo_class_Redis_hpexpire, ZEND_ACC_PUBLIC)
1600+
ZEND_ME(Redis, hexpireat, arginfo_class_Redis_hexpireat, ZEND_ACC_PUBLIC)
1601+
ZEND_ME(Redis, hpexpireat, arginfo_class_Redis_hpexpireat, ZEND_ACC_PUBLIC)
1602+
ZEND_ME(Redis, httl, arginfo_class_Redis_httl, ZEND_ACC_PUBLIC)
1603+
ZEND_ME(Redis, hpttl, arginfo_class_Redis_hpttl, ZEND_ACC_PUBLIC)
1604+
ZEND_ME(Redis, hexpiretime, arginfo_class_Redis_hexpiretime, ZEND_ACC_PUBLIC)
1605+
ZEND_ME(Redis, hpexpiretime, arginfo_class_Redis_hpexpiretime, ZEND_ACC_PUBLIC)
1606+
ZEND_ME(Redis, hpersist, arginfo_class_Redis_hpersist, ZEND_ACC_PUBLIC)
15561607
ZEND_ME(Redis, hscan, arginfo_class_Redis_hscan, ZEND_ACC_PUBLIC)
15571608
ZEND_ME(Redis, expiremember, arginfo_class_Redis_expiremember, ZEND_ACC_PUBLIC)
15581609
ZEND_ME(Redis, expirememberat, arginfo_class_Redis_expirememberat, ZEND_ACC_PUBLIC)

redis_cluster.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,49 @@ PHP_METHOD(RedisCluster, hmset) {
12031203
}
12041204
/* }}} */
12051205

1206+
PHP_METHOD(RedisCluster, hexpire) {
1207+
CLUSTER_PROCESS_KW_CMD("HEXPIRE",
1208+
redis_hexpire_cmd, cluster_variant_resp, 0);
1209+
}
1210+
1211+
PHP_METHOD(RedisCluster, hpexpire) {
1212+
CLUSTER_PROCESS_KW_CMD("HPEXPIRE",
1213+
redis_hexpire_cmd, cluster_variant_resp, 0);
1214+
}
1215+
1216+
PHP_METHOD(RedisCluster, hexpireat) {
1217+
CLUSTER_PROCESS_KW_CMD("HEXPIREAT",
1218+
redis_hexpire_cmd, cluster_variant_resp, 0);
1219+
}
1220+
1221+
PHP_METHOD(RedisCluster, hpexpireat) {
1222+
CLUSTER_PROCESS_KW_CMD("HPEXPIREAT",
1223+
redis_hexpire_cmd, cluster_variant_resp, 0);
1224+
}
1225+
1226+
PHP_METHOD(RedisCluster, httl) {
1227+
CLUSTER_PROCESS_KW_CMD("HTTL", redis_httl_cmd, cluster_variant_resp, 1);
1228+
}
1229+
1230+
PHP_METHOD(RedisCluster, hpttl) {
1231+
CLUSTER_PROCESS_KW_CMD("HPTTL", redis_httl_cmd, cluster_variant_resp, 1);
1232+
}
1233+
1234+
1235+
PHP_METHOD(RedisCluster, hexpiretime) {
1236+
CLUSTER_PROCESS_KW_CMD("HEXPIRETIME", redis_httl_cmd,
1237+
cluster_variant_resp, 1);
1238+
}
1239+
1240+
PHP_METHOD(RedisCluster, hpexpiretime) {
1241+
CLUSTER_PROCESS_KW_CMD("HPEXPIRETIME", redis_httl_cmd,
1242+
cluster_variant_resp, 1);
1243+
}
1244+
1245+
PHP_METHOD(RedisCluster, hpersist) {
1246+
CLUSTER_PROCESS_KW_CMD("HPERSIST", redis_httl_cmd, cluster_variant_resp, 0);
1247+
}
1248+
12061249
/* {{{ proto bool RedisCluster::hrandfield(string key, [array $options]) */
12071250
PHP_METHOD(RedisCluster, hrandfield) {
12081251
CLUSTER_PROCESS_CMD(hrandfield, cluster_hrandfield_resp, 1);

redis_cluster.stub.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,55 @@ public function hsetnx(string $key, string $member, mixed $value): RedisCluster|
535535
*/
536536
public function hstrlen(string $key, string $field): RedisCluster|int|false;
537537

538+
/**
539+
* @see Redis::hexpire
540+
*/
541+
public function hexpire(string $key, int $ttl, array $fields,
542+
?string $mode = NULL): RedisCluster|array|false;
543+
544+
/**
545+
* @see Redis::hpexpire
546+
*/
547+
public function hpexpire(string $key, int $ttl, array $fields,
548+
?string $mode = NULL): RedisCluster|array|false;
549+
550+
/**
551+
* @see Redis::hexpireat
552+
*/
553+
public function hexpireat(string $key, int $time, array $fields,
554+
?string $mode = NULL): RedisCluster|array|false;
555+
556+
/**
557+
* @see Redis::hpexpireat
558+
*/
559+
public function hpexpireat(string $key, int $mstime, array $fields,
560+
?string $mode = NULL): RedisCluster|array|false;
561+
562+
/**
563+
* @see Redis::httl
564+
*/
565+
public function httl(string $key, array $fields): RedisCluster|array|false;
566+
567+
/**
568+
* @see Redis::hpttl
569+
*/
570+
public function hpttl(string $key, array $fields): RedisCluster|array|false;
571+
572+
/**
573+
* @see Redis::hexpiretime
574+
*/
575+
public function hexpiretime(string $key, array $fields): RedisCluster|array|false;
576+
577+
/**
578+
* @see Redis::hpexpiretime
579+
*/
580+
public function hpexpiretime(string $key, array $fields): RedisCluster|array|false;
581+
582+
/**
583+
* @see Redis::hpexpiretime
584+
*/
585+
public function hpersist(string $key, array $fields): RedisCluster|array|false;
586+
538587
/**
539588
* @see Redis::hvals
540589
*/

0 commit comments

Comments
 (0)
0