Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for hash field expiration commands #1456

Open
wants to merge 14 commits into
base: v2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .codespellrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ skip=./.git
check-hidden=
check-filenames=
builtin=clear,rare,informal,usage,code,names
ignore-words-list=master,masters,slave,slaves,whitelist,cas,exat,smove,SUGGET,sugget,ro
ignore-words-list=master,masters,slave,slaves,whitelist,cas,exat,smove,SUGGET,sugget,ro,DOF,dof
1 change: 1 addition & 0 deletions .github/workflows/stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
- '8.3'
redis:
- latest
- 7.4.0-rc1

continue-on-error: ${{ matrix.php == '8.3' }}

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
- 5
- 6
- 7
- 7.4-rc1

services:
redis:
Expand Down
2 changes: 1 addition & 1 deletion examples/transaction_using_cas.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function zpop($client, $key)
'cas' => true, // Initialize with support for CAS operations
'watch' => $key, // Key that needs to be WATCHed to detect changes
'retry' => 3, // Number of retries on aborted transactions, after
// which the client bails out with an exception.
// which the client bails out with an exception.
];

$client->transaction($options, function ($tx) use ($key, &$element) {
Expand Down
9 changes: 9 additions & 0 deletions src/ClientContextInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@
* @method $this strlen($key)
* @method $this hdel($key, array $fields)
* @method $this hexists($key, $field)
* @method $this hexpire(string $key, int $seconds, array $fields, string $flag = null)
* @method $this hexpireat(string $key, int $unixTimeSeconds, array $fields, string $flag = null)
* @method $this hexpiretime(string $key, array $fields)
* @method $this hpersist(string $key, array $fields)
* @method $this hpexpire(string $key, int $milliseconds, array $fields, string $flag = null)
* @method $this hpexpireat(string $key, int $unixTimeMilliseconds, array $fields, string $flag = null)
* @method $this hpexpiretime(string $key, array $fields)
* @method $this hget($key, $field)
* @method $this hgetall($key)
* @method $this hincrby($key, $field, $increment)
Expand All @@ -166,6 +173,8 @@
* @method $this hscan($key, $cursor, ?array $options = null)
* @method $this hset($key, $field, $value)
* @method $this hsetnx($key, $field, $value)
* @method $this httl(string $key, array $fields)
* @method $this hpttl(string $key, array $fields)
* @method $this hvals($key)
* @method $this hstrlen($key, $field)
* @method $this jsonarrappend(string $key, string $path = '$', ...$value)
Expand Down
9 changes: 9 additions & 0 deletions src/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@
* @method int strlen(string $key)
* @method int hdel(string $key, array $fields)
* @method int hexists(string $key, string $field)
* @method array|null hexpire(string $key, int $seconds, array $fields, string $flag = null)
* @method array|null hexpireat(string $key, int $unixTimeSeconds, array $fields, string $flag = null)
* @method array|null hexpiretime(string $key, array $fields)
* @method array|null hpersist(string $key, array $fields)
* @method array|null hpexpire(string $key, int $milliseconds, array $fields, string $flag = null)
* @method array|null hpexpireat(string $key, int $unixTimeMilliseconds, array $fields, string $flag = null)
* @method array|null hpexpiretime(string $key, array $fields)
* @method string|null hget(string $key, string $field)
* @method array hgetall(string $key)
* @method int hincrby(string $key, string $field, int $increment)
Expand All @@ -175,6 +182,8 @@
* @method array hscan(string $key, $cursor, ?array $options = null)
* @method int hset(string $key, string $field, string $value)
* @method int hsetnx(string $key, string $field, string $value)
* @method array|null httl(string $key, array $fields)
* @method array|null hpttl(string $key, array $fields)
* @method array hvals(string $key)
* @method int hstrlen(string $key, string $field)
* @method array jsonarrappend(string $key, string $path = '$', ...$value)
Expand Down
14 changes: 7 additions & 7 deletions src/Collection/Iterator/CursorBasedIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,13 @@ public function next()
$this->fetch();
}

if ($this->elements) {
$this->extractNext();
} elseif ($this->cursor) {
goto tryFetch;
} else {
$this->valid = false;
}
if ($this->elements) {
$this->extractNext();
} elseif ($this->cursor) {
goto tryFetch;
} else {
$this->valid = false;
}
}

/**
Expand Down
51 changes: 51 additions & 0 deletions src/Command/Redis/HEXPIRE.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Predis\Command\Redis;

use Predis\Command\Command as RedisCommand;
use UnexpectedValueException;

class HEXPIRE extends RedisCommand
{
/**
* @var array
*/
protected $flagsEnum = [
'NX', 'XX', 'GT', 'LT',
];

public function getId()
{
return 'HEXPIRE';
}

public function setArguments(array $arguments)
{
$processedArguments = [$arguments[0], $arguments[1]];

if (array_key_exists(3, $arguments) && null !== $arguments[3]) {
if (in_array(strtoupper($arguments[3]), $this->flagsEnum, true)) {
$processedArguments[] = strtoupper($arguments[3]);
} else {
throw new UnexpectedValueException('Unsupported flag value');
}
}

if (array_key_exists(2, $arguments) && null !== $arguments[2]) {
array_push($processedArguments, 'FIELDS', count($arguments[2]));
$processedArguments = array_merge($processedArguments, $arguments[2]);
}

parent::setArguments($processedArguments);
}
}
21 changes: 21 additions & 0 deletions src/Command/Redis/HEXPIREAT.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Predis\Command\Redis;

class HEXPIREAT extends HEXPIRE
{
public function getId()
{
return 'HEXPIREAT';
}
}
31 changes: 31 additions & 0 deletions src/Command/Redis/HEXPIRETIME.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Predis\Command\Redis;

use Predis\Command\Command as RedisCommand;

class HEXPIRETIME extends RedisCommand
vladvildanov marked this conversation as resolved.
Show resolved Hide resolved
{
public function getId()
{
return 'HEXPIRETIME';
}

public function setArguments(array $arguments)
{
$processedArguments = [$arguments[0], 'FIELDS', count($arguments[1])];
$processedArguments = array_merge($processedArguments, $arguments[1]);

parent::setArguments($processedArguments);
}
}
31 changes: 31 additions & 0 deletions src/Command/Redis/HPERSIST.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Predis\Command\Redis;

use Predis\Command\Command as RedisCommand;

class HPERSIST extends RedisCommand
{
public function getId()
{
return 'HPERSIST';
}

public function setArguments(array $arguments)
{
$processedArguments = [$arguments[0], 'FIELDS', count($arguments[1])];
$processedArguments = array_merge($processedArguments, $arguments[1]);

parent::setArguments($processedArguments);
}
}
21 changes: 21 additions & 0 deletions src/Command/Redis/HPEXPIRE.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Predis\Command\Redis;

class HPEXPIRE extends HEXPIRE
{
public function getId()
{
return 'HPEXPIRE';
}
}
21 changes: 21 additions & 0 deletions src/Command/Redis/HPEXPIREAT.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Predis\Command\Redis;

class HPEXPIREAT extends HEXPIRE
{
public function getId()
{
return 'HPEXPIREAT';
}
}
21 changes: 21 additions & 0 deletions src/Command/Redis/HPEXPIRETIME.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Predis\Command\Redis;

class HPEXPIRETIME extends HEXPIRETIME
{
public function getId()
{
return 'HPEXPIRETIME';
}
}
21 changes: 21 additions & 0 deletions src/Command/Redis/HPTTL.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Predis\Command\Redis;

class HPTTL extends HTTL
{
public function getId()
{
return 'HPTTL';
}
}
31 changes: 31 additions & 0 deletions src/Command/Redis/HTTL.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Predis\Command\Redis;

use Predis\Command\Command as RedisCommand;

class HTTL extends RedisCommand
{
public function getId()
{
return 'HTTL';
}

public function setArguments(array $arguments)
{
$processedArguments = [$arguments[0], 'FIELDS', count($arguments[1])];
$processedArguments = array_merge($processedArguments, $arguments[1]);

parent::setArguments($processedArguments);
}
}
6 changes: 3 additions & 3 deletions src/Connection/RelayConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class RelayConnection extends StreamConnection
/**
* The Relay instance.
*
* @var \Relay\Relay
* @var Relay
*/
protected $client;

Expand Down Expand Up @@ -151,7 +151,7 @@ protected function assertParameters(ParametersInterface $parameters)
/**
* Creates a new instance of the client.
*
* @return \Relay\Relay
* @return Relay
*/
private function createClient()
{
Expand Down Expand Up @@ -189,7 +189,7 @@ private function createClient()
/**
* Returns the underlying client.
*
* @return \Relay\Relay
* @return Relay
*/
public function getClient()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Pipeline/RelayPipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class RelayPipeline extends Pipeline
*/
protected function executePipeline(ConnectionInterface $connection, SplQueue $commands)
{
/** @var \Predis\Connection\RelayConnection $connection */
/** @var RelayConnection $connection */
$client = $connection->getClient();

$throw = $this->client->getOptions()->exceptions;
Expand Down