Skip to content

Commit 3073a3b

Browse files
committed
Added PERSIST.
1 parent b90aed3 commit 3073a3b

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

README.markdown

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,6 +1365,21 @@ Long, the time left to live in seconds.
13651365
$redis->ttl('key');
13661366
</pre>
13671367

1368+
## persist
1369+
##### *Description*
1370+
Remove the expiration timer from a key.
1371+
1372+
##### *Parameters*
1373+
*Key*: key
1374+
1375+
##### *Return value*
1376+
*BOOL*: `TRUE` if a timeout was removed, `FALSE` if the key didn’t exist or didn’t have an expiration timer.
1377+
1378+
##### *Example*
1379+
<pre>
1380+
$redis->persist('key');
1381+
</pre>
1382+
13681383
## mset (redis >= 1.1)
13691384
##### *Description*
13701385
Sets multiple key-value pairs in one atomic command

php_redis.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ PHP_METHOD(Redis, flushAll);
8484
PHP_METHOD(Redis, dbSize);
8585
PHP_METHOD(Redis, auth);
8686
PHP_METHOD(Redis, ttl);
87+
PHP_METHOD(Redis, persist);
8788
PHP_METHOD(Redis, info);
8889
PHP_METHOD(Redis, select);
8990
PHP_METHOD(Redis, move);

redis.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ static zend_function_entry redis_functions[] = {
106106
PHP_ME(Redis, dbSize, NULL, ZEND_ACC_PUBLIC)
107107
PHP_ME(Redis, auth, NULL, ZEND_ACC_PUBLIC)
108108
PHP_ME(Redis, ttl, NULL, ZEND_ACC_PUBLIC)
109+
PHP_ME(Redis, persist, NULL, ZEND_ACC_PUBLIC)
109110
PHP_ME(Redis, info, NULL, ZEND_ACC_PUBLIC)
110111
PHP_ME(Redis, select, NULL, ZEND_ACC_PUBLIC)
111112
PHP_ME(Redis, move, NULL, ZEND_ACC_PUBLIC)
@@ -2339,6 +2340,35 @@ PHP_METHOD(Redis, auth) {
23392340
}
23402341
/* }}} */
23412342

2343+
/* {{{ proto long Redis::persist(string key)
2344+
*/
2345+
PHP_METHOD(Redis, persist) {
2346+
2347+
zval *object;
2348+
RedisSock *redis_sock;
2349+
2350+
char *cmd, *key;
2351+
int cmd_len, key_len;
2352+
2353+
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",
2354+
&object, redis_ce, &key, &key_len) == FAILURE) {
2355+
RETURN_FALSE;
2356+
}
2357+
2358+
if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
2359+
RETURN_FALSE;
2360+
}
2361+
2362+
cmd_len = redis_cmd_format_static(&cmd, "PERSIST", "s", key, key_len);
2363+
2364+
REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
2365+
IF_ATOMIC() {
2366+
redis_long_response(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL);
2367+
}
2368+
REDIS_PROCESS_RESPONSE(redis_long_response);
2369+
}
2370+
/* }}} */
2371+
23422372
/* {{{ proto long Redis::ttl(string key)
23432373
*/
23442374
PHP_METHOD(Redis, ttl) {

tests/TestRedis.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,6 +1354,17 @@ public function testttl() {
13541354
}
13551355
}
13561356

1357+
public function testPersist() {
1358+
$this->redis->set('x', 'y');
1359+
$this->redis->setTimeout('x', 100);
1360+
$this->assertTrue(TRUE === $this->redis->persist('x')); // true if there is a timeout
1361+
$this->assertTrue(-1 === $this->redis->ttl('x')); // -1: timeout has been removed.
1362+
$this->assertTrue(FALSE === $this->redis->persist('x')); // false if there is no timeout
1363+
1364+
$this->redis->delete('x');
1365+
$this->assertTrue(FALSE === $this->redis->persist('x')); // false if the key doesn’t exist.
1366+
}
1367+
13571368
public function testinfo() {
13581369
$info = $this->redis->info();
13591370

0 commit comments

Comments
 (0)