Skip to content

Commit

Permalink
Added PERSIST.
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasff committed Sep 30, 2010
1 parent b90aed3 commit 3073a3b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.markdown
Expand Up @@ -1365,6 +1365,21 @@ Long, the time left to live in seconds.
$redis->ttl('key');
</pre>

## persist
##### *Description*
Remove the expiration timer from a key.

##### *Parameters*
*Key*: key

##### *Return value*
*BOOL*: `TRUE` if a timeout was removed, `FALSE` if the key didn’t exist or didn’t have an expiration timer.

##### *Example*
<pre>
$redis->persist('key');
</pre>

## mset (redis >= 1.1)
##### *Description*
Sets multiple key-value pairs in one atomic command
Expand Down
1 change: 1 addition & 0 deletions php_redis.h
Expand Up @@ -84,6 +84,7 @@ PHP_METHOD(Redis, flushAll);
PHP_METHOD(Redis, dbSize);
PHP_METHOD(Redis, auth);
PHP_METHOD(Redis, ttl);
PHP_METHOD(Redis, persist);
PHP_METHOD(Redis, info);
PHP_METHOD(Redis, select);
PHP_METHOD(Redis, move);
Expand Down
30 changes: 30 additions & 0 deletions redis.c
Expand Up @@ -106,6 +106,7 @@ static zend_function_entry redis_functions[] = {
PHP_ME(Redis, dbSize, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Redis, auth, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Redis, ttl, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Redis, persist, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Redis, info, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Redis, select, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Redis, move, NULL, ZEND_ACC_PUBLIC)
Expand Down Expand Up @@ -2339,6 +2340,35 @@ PHP_METHOD(Redis, auth) {
}
/* }}} */

/* {{{ proto long Redis::persist(string key)
*/
PHP_METHOD(Redis, persist) {

zval *object;
RedisSock *redis_sock;

char *cmd, *key;
int cmd_len, key_len;

if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",
&object, redis_ce, &key, &key_len) == FAILURE) {
RETURN_FALSE;
}

if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
RETURN_FALSE;
}

cmd_len = redis_cmd_format_static(&cmd, "PERSIST", "s", key, key_len);

REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
IF_ATOMIC() {
redis_long_response(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL);
}
REDIS_PROCESS_RESPONSE(redis_long_response);
}
/* }}} */

/* {{{ proto long Redis::ttl(string key)
*/
PHP_METHOD(Redis, ttl) {
Expand Down
11 changes: 11 additions & 0 deletions tests/TestRedis.php
Expand Up @@ -1354,6 +1354,17 @@ public function testttl() {
}
}

public function testPersist() {
$this->redis->set('x', 'y');
$this->redis->setTimeout('x', 100);
$this->assertTrue(TRUE === $this->redis->persist('x')); // true if there is a timeout
$this->assertTrue(-1 === $this->redis->ttl('x')); // -1: timeout has been removed.
$this->assertTrue(FALSE === $this->redis->persist('x')); // false if there is no timeout

$this->redis->delete('x');
$this->assertTrue(FALSE === $this->redis->persist('x')); // false if the key doesn’t exist.
}

public function testinfo() {
$info = $this->redis->info();

Expand Down

0 comments on commit 3073a3b

Please sign in to comment.