From 32837e06e92bd31c0866ee680aff78aa38c7145d Mon Sep 17 00:00:00 2001 From: michael-grunder Date: Mon, 18 Nov 2013 11:41:19 -0800 Subject: Allow for NULL to be passed in our optional arguments and just ignore it if it is (but still set the key). Addresses #407 --- redis.c | 4 +++- tests/TestRedis.php | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/redis.c b/redis.c index ec400b6a..c2a3d87c 100644 --- a/redis.c +++ b/redis.c @@ -836,7 +836,9 @@ PHP_METHOD(Redis, set) { /* Our optional argument can either be a long (to support legacy SETEX */ /* redirection), or an array with Redis >= 2.6.12 set options */ - if(z_opts && Z_TYPE_P(z_opts) != IS_LONG && Z_TYPE_P(z_opts) != IS_ARRAY) { + if(z_opts && Z_TYPE_P(z_opts) != IS_LONG && Z_TYPE_P(z_opts) != IS_ARRAY + && Z_TYPE_P(z_opts) != IS_NULL) + { RETURN_FALSE; } diff --git a/tests/TestRedis.php b/tests/TestRedis.php index 65bc63ca..60f015f5 100644 --- a/tests/TestRedis.php +++ b/tests/TestRedis.php @@ -264,6 +264,12 @@ class Redis_Test extends TestSuite $this->assertTrue($this->redis->set('foo','barbaz', Array('not-valid','nx','invalid','ex'=>200))); $this->assertEquals($this->redis->ttl('foo'), 200); $this->assertEquals($this->redis->get('foo'), 'barbaz'); + + /* Pass NULL as the optional arguments which should be ignored */ + $this->redis->del('foo'); + $this->redis->set('foo','bar', NULL); + $this->assertEquals($this->redis->get('foo'), 'bar'); + $this->assertTrue($this->redis->ttl('foo')<0); } public function testGetSet() { -- cgit v1.2.3