/** * Removes a value from the hash stored at key. * If the hash table doesn't exist, or the key doesn't exist, FALSE is returned. * * @param string $key * @param string|array $hashKey * * @return bool whether the operation was successful * @link http://redis.io/commands/hdel * @example * <pre> * $redis->hMSet('h', * array( * 'f1' => 'v1', * 'f4' => 'v4', * )); * var_dump( $redis->hDel('h', 'f1') ); // bool(true) * s * var_dump( $redis->hGetAll('h') ); * //// Output: * // array(1) { * // ["f4"]=> string(2) "v4" * // } * </pre> */ public function hDel($key, $hashKey) { try { return $this->client->hDel($key, $hashKey); } catch (Exception $e) { return $this->handleException($e, __FUNCTION__, func_get_args()); } }
/** * Test deleting fields form a hash */ public function testHdel() { $this->redis->del('testHdel'); $numRemoved = $this->redis->hset('testHdel', 'field1', 'Hello'); $this->assertInternalType('int', $numRemoved); $this->assertEquals(1, $numRemoved); $this->assertEquals(1, $this->redis->hdel('testHdel', 'field1')); $this->assertEquals(0, $this->redis->hdel('testHdel', 'field1')); $this->assertEquals(1, $this->redis->hset('testHdel', 'field1', 'Hello')); $this->assertEquals(1, $this->redis->hset('testHdel', 'field2', 'Hello')); $this->assertEquals(2, $this->redis->hdel('testHdel', array('field1', 'field2'))); // make sure varargs are not supported $this->redis->hset('testHdel1', 'field1', 'abc'); $this->redis->hset('testHdel1', 'field2', 'def'); $this->assertEquals(1, $this->redis->hDel('testHdel1', 'field1', 'field2')); $this->assertEquals('def', $this->redis->hGet('testHdel1', 'field2')); $this->assertEquals(1, $this->redis->del('testHdel1')); }
/** * Removes a value from the hash stored at key. * If the hash table doesn't exist, or the key doesn't exist, FALSE is returned. * * @param string $key * @param string|array $hashKey * * @return bool whether the operation was successful * @link http://redis.io/commands/hdel * @example * <pre> * $redis->hMSet('h', * array( * 'f1' => 'v1', * 'f4' => 'v4', * )); * var_dump( $redis->hDel('h', 'f1') ); // bool(true) * s * var_dump( $redis->hGetAll('h') ); * //// Output: * // array(1) { * // ["f4"]=> string(2) "v4" * // } * </pre> */ public function hDel($key, $hashKey) { $this->appendToLog('HDEL ' . $key . ' ' . $this->keysToString($hashKey)); return $this->client->hDel($key, $hashKey); }