├── README.md ├── config.xml ├── config_fr.xml ├── hsrediscache.php ├── logo.gif ├── logo.png ├── override ├── classes │ └── cache │ │ └── CacheRedis.php └── controllers │ └── admin │ └── AdminPerformanceController.php ├── predis ├── Autoloader.php ├── Client.php ├── ClientContextInterface.php ├── ClientException.php ├── ClientInterface.php ├── Cluster │ ├── ClusterStrategy.php │ ├── Distributor │ │ ├── DistributorInterface.php │ │ ├── EmptyRingException.php │ │ ├── HashRing.php │ │ └── KetamaRing.php │ ├── Hash │ │ ├── CRC16.php │ │ └── HashGeneratorInterface.php │ ├── PredisStrategy.php │ ├── RedisStrategy.php │ └── StrategyInterface.php ├── Collection │ └── Iterator │ │ ├── CursorBasedIterator.php │ │ ├── HashKey.php │ │ ├── Keyspace.php │ │ ├── ListKey.php │ │ ├── SetKey.php │ │ └── SortedSetKey.php ├── Command │ ├── Command.php │ ├── CommandInterface.php │ ├── ConnectionAuth.php │ ├── ConnectionEcho.php │ ├── ConnectionPing.php │ ├── ConnectionQuit.php │ ├── ConnectionSelect.php │ ├── HashDelete.php │ ├── HashExists.php │ ├── HashGet.php │ ├── HashGetAll.php │ ├── HashGetMultiple.php │ ├── HashIncrementBy.php │ ├── HashIncrementByFloat.php │ ├── HashKeys.php │ ├── HashLength.php │ ├── HashScan.php │ ├── HashSet.php │ ├── HashSetMultiple.php │ ├── HashSetPreserve.php │ ├── HashValues.php │ ├── HyperLogLogAdd.php │ ├── HyperLogLogCount.php │ ├── HyperLogLogMerge.php │ ├── KeyDelete.php │ ├── KeyDump.php │ ├── KeyExists.php │ ├── KeyExpire.php │ ├── KeyExpireAt.php │ ├── KeyKeys.php │ ├── KeyMove.php │ ├── KeyPersist.php │ ├── KeyPreciseExpire.php │ ├── KeyPreciseExpireAt.php │ ├── KeyPreciseTimeToLive.php │ ├── KeyRandom.php │ ├── KeyRename.php │ ├── KeyRenamePreserve.php │ ├── KeyRestore.php │ ├── KeyScan.php │ ├── KeySort.php │ ├── KeyTimeToLive.php │ ├── KeyType.php │ ├── ListIndex.php │ ├── ListInsert.php │ ├── ListLength.php │ ├── ListPopFirst.php │ ├── ListPopFirstBlocking.php │ ├── ListPopLast.php │ ├── ListPopLastBlocking.php │ ├── ListPopLastPushHead.php │ ├── ListPopLastPushHeadBlocking.php │ ├── ListPushHead.php │ ├── ListPushHeadX.php │ ├── ListPushTail.php │ ├── ListPushTailX.php │ ├── ListRange.php │ ├── ListRemove.php │ ├── ListSet.php │ ├── ListTrim.php │ ├── PrefixableCommandInterface.php │ ├── Processor │ │ ├── KeyPrefixProcessor.php │ │ ├── ProcessorChain.php │ │ └── ProcessorInterface.php │ ├── PubSubPublish.php │ ├── PubSubPubsub.php │ ├── PubSubSubscribe.php │ ├── PubSubSubscribeByPattern.php │ ├── PubSubUnsubscribe.php │ ├── PubSubUnsubscribeByPattern.php │ ├── RawCommand.php │ ├── ScriptCommand.php │ ├── ServerBackgroundRewriteAOF.php │ ├── ServerBackgroundSave.php │ ├── ServerClient.php │ ├── ServerCommand.php │ ├── ServerConfig.php │ ├── ServerDatabaseSize.php │ ├── ServerEval.php │ ├── ServerEvalSHA.php │ ├── ServerFlushAll.php │ ├── ServerFlushDatabase.php │ ├── ServerInfo.php │ ├── ServerInfoV26x.php │ ├── ServerLastSave.php │ ├── ServerMonitor.php │ ├── ServerObject.php │ ├── ServerSave.php │ ├── ServerScript.php │ ├── ServerSentinel.php │ ├── ServerShutdown.php │ ├── ServerSlaveOf.php │ ├── ServerSlowlog.php │ ├── ServerTime.php │ ├── SetAdd.php │ ├── SetCardinality.php │ ├── SetDifference.php │ ├── SetDifferenceStore.php │ ├── SetIntersection.php │ ├── SetIntersectionStore.php │ ├── SetIsMember.php │ ├── SetMembers.php │ ├── SetMove.php │ ├── SetPop.php │ ├── SetRandomMember.php │ ├── SetRemove.php │ ├── SetScan.php │ ├── SetUnion.php │ ├── SetUnionStore.php │ ├── StringAppend.php │ ├── StringBitCount.php │ ├── StringBitOp.php │ ├── StringDecrement.php │ ├── StringDecrementBy.php │ ├── StringGet.php │ ├── StringGetBit.php │ ├── StringGetMultiple.php │ ├── StringGetRange.php │ ├── StringGetSet.php │ ├── StringIncrement.php │ ├── StringIncrementBy.php │ ├── StringIncrementByFloat.php │ ├── StringPreciseSetExpire.php │ ├── StringSet.php │ ├── StringSetBit.php │ ├── StringSetExpire.php │ ├── StringSetMultiple.php │ ├── StringSetMultiplePreserve.php │ ├── StringSetPreserve.php │ ├── StringSetRange.php │ ├── StringStrlen.php │ ├── StringSubstr.php │ ├── TransactionDiscard.php │ ├── TransactionExec.php │ ├── TransactionMulti.php │ ├── TransactionUnwatch.php │ ├── TransactionWatch.php │ ├── ZSetAdd.php │ ├── ZSetCardinality.php │ ├── ZSetCount.php │ ├── ZSetIncrementBy.php │ ├── ZSetIntersectionStore.php │ ├── ZSetLexCount.php │ ├── ZSetRange.php │ ├── ZSetRangeByLex.php │ ├── ZSetRangeByScore.php │ ├── ZSetRank.php │ ├── ZSetRemove.php │ ├── ZSetRemoveRangeByLex.php │ ├── ZSetRemoveRangeByRank.php │ ├── ZSetRemoveRangeByScore.php │ ├── ZSetReverseRange.php │ ├── ZSetReverseRangeByScore.php │ ├── ZSetReverseRank.php │ ├── ZSetScan.php │ ├── ZSetScore.php │ └── ZSetUnionStore.php ├── CommunicationException.php ├── Configuration │ ├── ClusterOption.php │ ├── ConnectionFactoryOption.php │ ├── ExceptionsOption.php │ ├── OptionInterface.php │ ├── Options.php │ ├── OptionsInterface.php │ ├── PrefixOption.php │ ├── ProfileOption.php │ └── ReplicationOption.php ├── Connection │ ├── AbstractConnection.php │ ├── Aggregate │ │ ├── ClusterInterface.php │ │ ├── MasterSlaveReplication.php │ │ ├── PredisCluster.php │ │ ├── RedisCluster.php │ │ └── ReplicationInterface.php │ ├── AggregateConnectionInterface.php │ ├── CompositeConnectionInterface.php │ ├── CompositeStreamConnection.php │ ├── ConnectionException.php │ ├── ConnectionInterface.php │ ├── Factory.php │ ├── FactoryInterface.php │ ├── NodeConnectionInterface.php │ ├── Parameters.php │ ├── ParametersInterface.php │ ├── PhpiredisSocketConnection.php │ ├── PhpiredisStreamConnection.php │ ├── StreamConnection.php │ └── WebdisConnection.php ├── Monitor │ └── Consumer.php ├── NotSupportedException.php ├── Pipeline │ ├── Atomic.php │ ├── ConnectionErrorProof.php │ ├── FireAndForget.php │ └── Pipeline.php ├── PredisException.php ├── Profile │ ├── Factory.php │ ├── ProfileInterface.php │ ├── RedisProfile.php │ ├── RedisUnstable.php │ ├── RedisVersion200.php │ ├── RedisVersion220.php │ ├── RedisVersion240.php │ ├── RedisVersion260.php │ ├── RedisVersion280.php │ └── RedisVersion300.php ├── Protocol │ ├── ProtocolException.php │ ├── ProtocolProcessorInterface.php │ ├── RequestSerializerInterface.php │ ├── ResponseReaderInterface.php │ └── Text │ │ ├── CompositeProtocolProcessor.php │ │ ├── Handler │ │ ├── BulkResponse.php │ │ ├── ErrorResponse.php │ │ ├── IntegerResponse.php │ │ ├── MultiBulkResponse.php │ │ ├── ResponseHandlerInterface.php │ │ ├── StatusResponse.php │ │ └── StreamableMultiBulkResponse.php │ │ ├── ProtocolProcessor.php │ │ ├── RequestSerializer.php │ │ └── ResponseReader.php ├── PubSub │ ├── AbstractConsumer.php │ ├── Consumer.php │ └── DispatcherLoop.php ├── Replication │ └── ReplicationStrategy.php ├── Response │ ├── Error.php │ ├── ErrorInterface.php │ ├── Iterator │ │ ├── MultiBulk.php │ │ ├── MultiBulkIterator.php │ │ └── MultiBulkTuple.php │ ├── ResponseInterface.php │ ├── ServerException.php │ └── Status.php ├── Session │ └── Handler.php └── Transaction │ ├── AbortedMultiExecException.php │ ├── MultiExec.php │ └── MultiExecState.php ├── settings.tpl └── translations └── fr.php /README.md: -------------------------------------------------------------------------------- 1 | # Hs Cache Redis Prestashop module 2 | 3 | ## Versions : 1.5.x -> 1.6.0.9 4 | 5 | Prestashop provides several caching method as memcached, apc, xcache ... 6 | 7 | I propose another method more efficient with Redis ( 8 | similar to memcached but more powerful) 9 | 10 | 11 | 12 | ### Requirements 13 | 14 | follow the following rules: 15 | 16 | * Install redis server ( check http://redis.io/download ) 17 | * clone the project inside your /modules/ to get finaly /modules/hsrediscache/ :) 18 | * do not forget to update your config module from prestashop backoffice 19 | 20 | NB : I'am using [Predis PHP Library](https://github.com/nrk/predis) so many thanks to [Daniele Alessandri](http://twitter.com/JoL1hAHN) 21 | 22 | ## Author 23 | 24 | 25 | **Hachem LATRACH** 26 | 27 | email: hachem@gmail.com 28 | twitter: @hachemsoft 29 | -------------------------------------------------------------------------------- /config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | hsrediscache 4 | 5 | 6 | 7 | 8 | 9 | 1 10 | 1 11 | 12 | -------------------------------------------------------------------------------- /config_fr.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | hsrediscache 4 | 5 | 6 | 7 | 8 | 9 | 10 | 1 11 | 1 12 | 13 | -------------------------------------------------------------------------------- /logo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hachemsoft/redis-cache-prestashop/7d1e8784331d264a40298f8b990844774ecda123/logo.gif -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hachemsoft/redis-cache-prestashop/7d1e8784331d264a40298f8b990844774ecda123/logo.png -------------------------------------------------------------------------------- /predis/Autoloader.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | namespace Predis; 12 | 13 | /** 14 | * Implements a lightweight PSR-0 compliant autoloader for Predis. 15 | * 16 | * @author Eric Naeseth 17 | * @author Daniele Alessandri 18 | */ 19 | class Autoloader 20 | { 21 | private $directory; 22 | private $prefix; 23 | private $prefixLength; 24 | 25 | /** 26 | * @param string $baseDirectory Base directory where the source files are located. 27 | */ 28 | public function __construct($baseDirectory = __DIR__) 29 | { 30 | $this->directory = $baseDirectory; 31 | $this->prefix = __NAMESPACE__ . '\\'; 32 | $this->prefixLength = strlen($this->prefix); 33 | } 34 | 35 | /** 36 | * Registers the autoloader class with the PHP SPL autoloader. 37 | * 38 | * @param bool $prepend Prepend the autoloader on the stack instead of appending it. 39 | */ 40 | public static function register($prepend = false) 41 | { 42 | spl_autoload_register(array(new self, 'autoload'), true, $prepend); 43 | } 44 | 45 | /** 46 | * Loads a class from a file using its fully qualified name. 47 | * 48 | * @param string $className Fully qualified name of a class. 49 | */ 50 | public function autoload($className) 51 | { 52 | if (0 === strpos($className, $this->prefix)) { 53 | $parts = explode('\\', substr($className, $this->prefixLength)); 54 | $filepath = $this->directory.DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR, $parts).'.php'; 55 | 56 | if (is_file($filepath)) { 57 | require($filepath); 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /predis/ClientException.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis; 13 | 14 | /** 15 | * Exception class that identifies client-side errors. 16 | * 17 | * @author Daniele Alessandri 18 | */ 19 | class ClientException extends PredisException 20 | { 21 | } 22 | -------------------------------------------------------------------------------- /predis/Cluster/Distributor/DistributorInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Cluster\Distributor; 13 | 14 | use Predis\Cluster\Hash\HashGeneratorInterface; 15 | 16 | /** 17 | * A distributor implements the logic to automatically distribute keys among 18 | * several nodes for client-side sharding. 19 | * 20 | * @author Daniele Alessandri 21 | */ 22 | interface DistributorInterface 23 | { 24 | /** 25 | * Adds a node to the distributor with an optional weight. 26 | * 27 | * @param mixed $node Node object. 28 | * @param int $weight Weight for the node. 29 | */ 30 | public function add($node, $weight = null); 31 | 32 | /** 33 | * Removes a node from the distributor. 34 | * 35 | * @param mixed $node Node object. 36 | */ 37 | public function remove($node); 38 | 39 | /** 40 | * Returns the corresponding slot of a node from the distributor using the 41 | * computed hash of a key. 42 | * 43 | * @param mixed $hash 44 | * 45 | * @return mixed 46 | */ 47 | public function getSlot($hash); 48 | 49 | /** 50 | * Returns a node from the distributor using its assigned slot ID. 51 | * 52 | * @param mixed $slot 53 | * 54 | * @return mixed|null 55 | */ 56 | public function getBySlot($slot); 57 | 58 | /** 59 | * Returns a node from the distributor using the computed hash of a key. 60 | * 61 | * @param mixed $hash 62 | * 63 | * @return mixed 64 | */ 65 | public function getByHash($hash); 66 | 67 | /** 68 | * Returns a node from the distributor mapping to the specified value. 69 | * 70 | * @param string $value 71 | * 72 | * @return mixed 73 | */ 74 | public function get($value); 75 | 76 | /** 77 | * Returns the underlying hash generator instance. 78 | * 79 | * @return HashGeneratorInterface 80 | */ 81 | public function getHashGenerator(); 82 | } 83 | -------------------------------------------------------------------------------- /predis/Cluster/Distributor/EmptyRingException.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Cluster\Distributor; 13 | 14 | use Exception; 15 | 16 | /** 17 | * Exception class that identifies empty rings. 18 | * 19 | * @author Daniele Alessandri 20 | */ 21 | class EmptyRingException extends Exception 22 | { 23 | } 24 | -------------------------------------------------------------------------------- /predis/Cluster/Distributor/KetamaRing.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Cluster\Distributor; 13 | 14 | /** 15 | * This class implements an hashring-based distributor that uses the same 16 | * algorithm of libketama to distribute keys in a cluster using client-side 17 | * sharding. 18 | * 19 | * @author Daniele Alessandri 20 | * @author Lorenzo Castelli 21 | */ 22 | class KetamaRing extends HashRing 23 | { 24 | const DEFAULT_REPLICAS = 160; 25 | 26 | /** 27 | * @param mixed $nodeHashCallback Callback returning a string used to calculate the hash of nodes. 28 | */ 29 | public function __construct($nodeHashCallback = null) 30 | { 31 | parent::__construct($this::DEFAULT_REPLICAS, $nodeHashCallback); 32 | } 33 | 34 | /** 35 | * {@inheritdoc} 36 | */ 37 | protected function addNodeToRing(&$ring, $node, $totalNodes, $replicas, $weightRatio) 38 | { 39 | $nodeObject = $node['object']; 40 | $nodeHash = $this->getNodeHash($nodeObject); 41 | $replicas = (int) floor($weightRatio * $totalNodes * ($replicas / 4)); 42 | 43 | for ($i = 0; $i < $replicas; $i++) { 44 | $unpackedDigest = unpack('V4', md5("$nodeHash-$i", true)); 45 | 46 | foreach ($unpackedDigest as $key) { 47 | $ring[$key] = $nodeObject; 48 | } 49 | } 50 | } 51 | 52 | /** 53 | * {@inheritdoc} 54 | */ 55 | public function hash($value) 56 | { 57 | $hash = unpack('V', md5($value, true)); 58 | 59 | return $hash[1]; 60 | } 61 | 62 | /** 63 | * {@inheritdoc} 64 | */ 65 | protected function wrapAroundStrategy($upper, $lower, $ringKeysCount) 66 | { 67 | // Binary search for the first item in ringkeys with a value greater 68 | // or equal to the key. If no such item exists, return the first item. 69 | return $lower < $ringKeysCount ? $lower : 0; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /predis/Cluster/Hash/HashGeneratorInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Cluster\Hash; 13 | 14 | /** 15 | * An hash generator implements the logic used to calculate the hash of a key to 16 | * distribute operations among Redis nodes. 17 | * 18 | * @author Daniele Alessandri 19 | */ 20 | interface HashGeneratorInterface 21 | { 22 | /** 23 | * Generates an hash from a string to be used for distribution. 24 | * 25 | * @param string $value String value. 26 | * 27 | * @return int 28 | */ 29 | public function hash($value); 30 | } 31 | -------------------------------------------------------------------------------- /predis/Cluster/PredisStrategy.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Cluster; 13 | 14 | use Predis\Cluster\Distributor\DistributorInterface; 15 | use Predis\Cluster\Distributor\HashRing; 16 | 17 | /** 18 | * Default cluster strategy used by Predis to handle client-side sharding. 19 | * 20 | * @author Daniele Alessandri 21 | */ 22 | class PredisStrategy extends ClusterStrategy 23 | { 24 | protected $distributor; 25 | 26 | /** 27 | * @param DistributorInterface $distributor Optional distributor instance. 28 | */ 29 | public function __construct(DistributorInterface $distributor = null) 30 | { 31 | parent::__construct(); 32 | 33 | $this->distributor = $distributor ?: new HashRing(); 34 | } 35 | 36 | /** 37 | * {@inheritdoc} 38 | */ 39 | public function getSlotByKey($key) 40 | { 41 | $key = $this->extractKeyTag($key); 42 | $hash = $this->distributor->hash($key); 43 | $slot = $this->distributor->getSlot($hash); 44 | 45 | return $slot; 46 | } 47 | 48 | /** 49 | * {@inheritdoc} 50 | */ 51 | protected function checkSameSlotForKeys(array $keys) 52 | { 53 | if (!$count = count($keys)) { 54 | return false; 55 | } 56 | 57 | $currentKey = $this->extractKeyTag($keys[0]); 58 | 59 | for ($i = 1; $i < $count; $i++) { 60 | $nextKey = $this->extractKeyTag($keys[$i]); 61 | 62 | if ($currentKey !== $nextKey) { 63 | return false; 64 | } 65 | 66 | $currentKey = $nextKey; 67 | } 68 | 69 | return true; 70 | } 71 | 72 | /** 73 | * {@inheritdoc} 74 | */ 75 | public function getDistributor() 76 | { 77 | return $this->distributor; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /predis/Cluster/RedisStrategy.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Cluster; 13 | 14 | use Predis\NotSupportedException; 15 | use Predis\Cluster\Hash\HashGeneratorInterface; 16 | use Predis\Cluster\Hash\CRC16; 17 | 18 | /** 19 | * Default class used by Predis to calculate hashes out of keys of 20 | * commands supported by redis-cluster. 21 | * 22 | * @author Daniele Alessandri 23 | */ 24 | class RedisStrategy extends ClusterStrategy 25 | { 26 | protected $hashGenerator; 27 | 28 | /** 29 | * @param HashGeneratorInterface $hashGenerator Hash generator instance. 30 | */ 31 | public function __construct(HashGeneratorInterface $hashGenerator = null) 32 | { 33 | parent::__construct(); 34 | 35 | $this->hashGenerator = $hashGenerator ?: new CRC16(); 36 | } 37 | 38 | /** 39 | * {@inheritdoc} 40 | */ 41 | public function getSlotByKey($key) 42 | { 43 | $key = $this->extractKeyTag($key); 44 | $slot = $this->hashGenerator->hash($key) & 0x3FFF; 45 | 46 | return $slot; 47 | } 48 | 49 | /** 50 | * {@inheritdoc} 51 | */ 52 | public function getDistributor() 53 | { 54 | throw new NotSupportedException( 55 | 'This cluster strategy does not provide an external distributor' 56 | ); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /predis/Cluster/StrategyInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Cluster; 13 | 14 | use Predis\Cluster\Distributor\DistributorInterface; 15 | use Predis\Command\CommandInterface; 16 | 17 | /** 18 | * Interface for classes defining the strategy used to calculate an hash out of 19 | * keys extracted from supported commands. 20 | * 21 | * This is mostly useful to support clustering via client-side sharding. 22 | * 23 | * @author Daniele Alessandri 24 | */ 25 | interface StrategyInterface 26 | { 27 | /** 28 | * Returns a slot for the given command used for clustering distribution or 29 | * NULL when this is not possible. 30 | * 31 | * @param CommandInterface $command Command instance. 32 | * 33 | * @return int 34 | */ 35 | public function getSlot(CommandInterface $command); 36 | 37 | /** 38 | * Returns a slot for the given key used for clustering distribution or NULL 39 | * when this is not possible. 40 | * 41 | * @param string $key Key string. 42 | * 43 | * @return int 44 | */ 45 | public function getSlotByKey($key); 46 | 47 | /** 48 | * Returns a distributor instance to be used by the cluster. 49 | * 50 | * @return DistributorInterface 51 | */ 52 | public function getDistributor(); 53 | } 54 | -------------------------------------------------------------------------------- /predis/Collection/Iterator/HashKey.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Collection\Iterator; 13 | 14 | use Predis\ClientInterface; 15 | 16 | /** 17 | * Abstracts the iteration of fields and values of an hash by leveraging the 18 | * HSCAN command (Redis >= 2.8) wrapped in a fully-rewindable PHP iterator. 19 | * 20 | * @author Daniele Alessandri 21 | * @link http://redis.io/commands/scan 22 | */ 23 | class HashKey extends CursorBasedIterator 24 | { 25 | protected $key; 26 | 27 | /** 28 | * {@inheritdoc} 29 | */ 30 | public function __construct(ClientInterface $client, $key, $match = null, $count = null) 31 | { 32 | $this->requiredCommand($client, 'HSCAN'); 33 | 34 | parent::__construct($client, $match, $count); 35 | 36 | $this->key = $key; 37 | } 38 | 39 | /** 40 | * {@inheritdoc} 41 | */ 42 | protected function executeCommand() 43 | { 44 | return $this->client->hscan($this->key, $this->cursor, $this->getScanOptions()); 45 | } 46 | 47 | /** 48 | * {@inheritdoc} 49 | */ 50 | protected function extractNext() 51 | { 52 | $this->position = key($this->elements); 53 | $this->current = array_shift($this->elements); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /predis/Collection/Iterator/Keyspace.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Collection\Iterator; 13 | 14 | use Predis\ClientInterface; 15 | 16 | /** 17 | * Abstracts the iteration of the keyspace on a Redis instance by leveraging the 18 | * SCAN command (Redis >= 2.8) wrapped in a fully-rewindable PHP iterator. 19 | * 20 | * @author Daniele Alessandri 21 | * @link http://redis.io/commands/scan 22 | */ 23 | class Keyspace extends CursorBasedIterator 24 | { 25 | /** 26 | * {@inheritdoc} 27 | */ 28 | public function __construct(ClientInterface $client, $match = null, $count = null) 29 | { 30 | $this->requiredCommand($client, 'SCAN'); 31 | 32 | parent::__construct($client, $match, $count); 33 | } 34 | 35 | /** 36 | * {@inheritdoc} 37 | */ 38 | protected function executeCommand() 39 | { 40 | return $this->client->scan($this->cursor, $this->getScanOptions()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /predis/Collection/Iterator/SetKey.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Collection\Iterator; 13 | 14 | use Predis\ClientInterface; 15 | 16 | /** 17 | * Abstracts the iteration of members stored in a set by leveraging the SSCAN 18 | * command (Redis >= 2.8) wrapped in a fully-rewindable PHP iterator. 19 | * 20 | * @author Daniele Alessandri 21 | * @link http://redis.io/commands/scan 22 | */ 23 | class SetKey extends CursorBasedIterator 24 | { 25 | protected $key; 26 | 27 | /** 28 | * {@inheritdoc} 29 | */ 30 | public function __construct(ClientInterface $client, $key, $match = null, $count = null) 31 | { 32 | $this->requiredCommand($client, 'SSCAN'); 33 | 34 | parent::__construct($client, $match, $count); 35 | 36 | $this->key = $key; 37 | } 38 | 39 | /** 40 | * {@inheritdoc} 41 | */ 42 | protected function executeCommand() 43 | { 44 | return $this->client->sscan($this->key, $this->cursor, $this->getScanOptions()); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /predis/Collection/Iterator/SortedSetKey.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Collection\Iterator; 13 | 14 | use Predis\ClientInterface; 15 | 16 | /** 17 | * Abstracts the iteration of members stored in a sorted set by leveraging the 18 | * ZSCAN command (Redis >= 2.8) wrapped in a fully-rewindable PHP iterator. 19 | * 20 | * @author Daniele Alessandri 21 | * @link http://redis.io/commands/scan 22 | */ 23 | class SortedSetKey extends CursorBasedIterator 24 | { 25 | protected $key; 26 | 27 | /** 28 | * {@inheritdoc} 29 | */ 30 | public function __construct(ClientInterface $client, $key, $match = null, $count = null) 31 | { 32 | $this->requiredCommand($client, 'ZSCAN'); 33 | 34 | parent::__construct($client, $match, $count); 35 | 36 | $this->key = $key; 37 | } 38 | 39 | /** 40 | * {@inheritdoc} 41 | */ 42 | protected function executeCommand() 43 | { 44 | return $this->client->zscan($this->key, $this->cursor, $this->getScanOptions()); 45 | } 46 | 47 | /** 48 | * {@inheritdoc} 49 | */ 50 | protected function extractNext() 51 | { 52 | $this->position = key($this->elements); 53 | $this->current = array_shift($this->elements); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /predis/Command/CommandInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * Defines an abstraction representing a Redis command. 16 | * 17 | * @author Daniele Alessandri 18 | */ 19 | interface CommandInterface 20 | { 21 | /** 22 | * Returns the ID of the Redis command. By convention, command identifiers 23 | * must always be uppercase. 24 | * 25 | * @return string 26 | */ 27 | public function getId(); 28 | 29 | /** 30 | * Assign the specified slot to the command for clustering distribution. 31 | * 32 | * @param int $slot Slot ID. 33 | */ 34 | public function setSlot($slot); 35 | 36 | /** 37 | * Returns the assigned slot of the command for clustering distribution. 38 | * 39 | * @return int|null 40 | */ 41 | public function getSlot(); 42 | 43 | /** 44 | * Sets the arguments for the command. 45 | * 46 | * @param array $arguments List of arguments. 47 | */ 48 | public function setArguments(array $arguments); 49 | 50 | /** 51 | * Sets the raw arguments for the command without processing them. 52 | * 53 | * @param array $arguments List of arguments. 54 | */ 55 | public function setRawArguments(array $arguments); 56 | 57 | /** 58 | * Gets the arguments of the command. 59 | * 60 | * @return array 61 | */ 62 | public function getArguments(); 63 | 64 | /** 65 | * Gets the argument of the command at the specified index. 66 | * 67 | * @param int $index Index of the desired argument. 68 | * 69 | * @return mixed|null 70 | */ 71 | public function getArgument($index); 72 | 73 | /** 74 | * Parses a raw response and returns a PHP object. 75 | * 76 | * @param string $data Binary string containing the whole response. 77 | * 78 | * @return mixed 79 | */ 80 | public function parseResponse($data); 81 | } 82 | -------------------------------------------------------------------------------- /predis/Command/ConnectionAuth.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/auth 16 | * @author Daniele Alessandri 17 | */ 18 | class ConnectionAuth extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'AUTH'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ConnectionEcho.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/echo 16 | * @author Daniele Alessandri 17 | */ 18 | class ConnectionEcho extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'ECHO'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ConnectionPing.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/ping 16 | * @author Daniele Alessandri 17 | */ 18 | class ConnectionPing extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'PING'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ConnectionQuit.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/quit 16 | * @author Daniele Alessandri 17 | */ 18 | class ConnectionQuit extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'QUIT'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ConnectionSelect.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/select 16 | * @author Daniele Alessandri 17 | */ 18 | class ConnectionSelect extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'SELECT'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/HashDelete.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/hdel 16 | * @author Daniele Alessandri 17 | */ 18 | class HashDelete extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'HDEL'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function filterArguments(array $arguments) 32 | { 33 | return self::normalizeVariadic($arguments); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /predis/Command/HashExists.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/hexists 16 | * @author Daniele Alessandri 17 | */ 18 | class HashExists extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'HEXISTS'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | public function parseResponse($data) 32 | { 33 | return (bool) $data; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /predis/Command/HashGet.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/hget 16 | * @author Daniele Alessandri 17 | */ 18 | class HashGet extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'HGET'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/HashGetAll.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/hgetall 16 | * @author Daniele Alessandri 17 | */ 18 | class HashGetAll extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'HGETALL'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | public function parseResponse($data) 32 | { 33 | $result = array(); 34 | 35 | for ($i = 0; $i < count($data); $i++) { 36 | $result[$data[$i]] = $data[++$i]; 37 | } 38 | 39 | return $result; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /predis/Command/HashGetMultiple.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/hmget 16 | * @author Daniele Alessandri 17 | */ 18 | class HashGetMultiple extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'HMGET'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function filterArguments(array $arguments) 32 | { 33 | return self::normalizeVariadic($arguments); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /predis/Command/HashIncrementBy.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/hincrby 16 | * @author Daniele Alessandri 17 | */ 18 | class HashIncrementBy extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'HINCRBY'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/HashIncrementByFloat.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/hincrbyfloat 16 | * @author Daniele Alessandri 17 | */ 18 | class HashIncrementByFloat extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'HINCRBYFLOAT'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/HashKeys.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/hkeys 16 | * @author Daniele Alessandri 17 | */ 18 | class HashKeys extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'HKEYS'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/HashLength.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/hlen 16 | * @author Daniele Alessandri 17 | */ 18 | class HashLength extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'HLEN'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/HashScan.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/hscan 16 | * @author Daniele Alessandri 17 | */ 18 | class HashScan extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'HSCAN'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function filterArguments(array $arguments) 32 | { 33 | if (count($arguments) === 3 && is_array($arguments[2])) { 34 | $options = $this->prepareOptions(array_pop($arguments)); 35 | $arguments = array_merge($arguments, $options); 36 | } 37 | 38 | return $arguments; 39 | } 40 | 41 | /** 42 | * Returns a list of options and modifiers compatible with Redis. 43 | * 44 | * @param array $options List of options. 45 | * 46 | * @return array 47 | */ 48 | protected function prepareOptions($options) 49 | { 50 | $options = array_change_key_case($options, CASE_UPPER); 51 | $normalized = array(); 52 | 53 | if (!empty($options['MATCH'])) { 54 | $normalized[] = 'MATCH'; 55 | $normalized[] = $options['MATCH']; 56 | } 57 | 58 | if (!empty($options['COUNT'])) { 59 | $normalized[] = 'COUNT'; 60 | $normalized[] = $options['COUNT']; 61 | } 62 | 63 | return $normalized; 64 | } 65 | 66 | /** 67 | * {@inheritdoc} 68 | */ 69 | public function parseResponse($data) 70 | { 71 | if (is_array($data)) { 72 | $fields = $data[1]; 73 | $result = array(); 74 | 75 | for ($i = 0; $i < count($fields); $i++) { 76 | $result[$fields[$i]] = $fields[++$i]; 77 | } 78 | 79 | $data[1] = $result; 80 | } 81 | 82 | return $data; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /predis/Command/HashSet.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/hset 16 | * @author Daniele Alessandri 17 | */ 18 | class HashSet extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'HSET'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | public function parseResponse($data) 32 | { 33 | return (bool) $data; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /predis/Command/HashSetMultiple.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/hmset 16 | * @author Daniele Alessandri 17 | */ 18 | class HashSetMultiple extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'HMSET'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function filterArguments(array $arguments) 32 | { 33 | if (count($arguments) === 2 && is_array($arguments[1])) { 34 | $flattenedKVs = array($arguments[0]); 35 | $args = $arguments[1]; 36 | 37 | foreach ($args as $k => $v) { 38 | $flattenedKVs[] = $k; 39 | $flattenedKVs[] = $v; 40 | } 41 | 42 | return $flattenedKVs; 43 | } 44 | 45 | return $arguments; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /predis/Command/HashSetPreserve.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/hsetnx 16 | * @author Daniele Alessandri 17 | */ 18 | class HashSetPreserve extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'HSETNX'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | public function parseResponse($data) 32 | { 33 | return (bool) $data; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /predis/Command/HashValues.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/hvals 16 | * @author Daniele Alessandri 17 | */ 18 | class HashValues extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'HVALS'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/HyperLogLogAdd.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/pfadd 16 | * @author Daniele Alessandri 17 | */ 18 | class HyperLogLogAdd extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'PFADD'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function filterArguments(array $arguments) 32 | { 33 | return self::normalizeVariadic($arguments); 34 | } 35 | 36 | /** 37 | * {@inheritdoc} 38 | */ 39 | public function parseResponse($data) 40 | { 41 | return (bool) $data; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /predis/Command/HyperLogLogCount.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/pfcount 16 | * @author Daniele Alessandri 17 | */ 18 | class HyperLogLogCount extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'PFCOUNT'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function filterArguments(array $arguments) 32 | { 33 | return self::normalizeArguments($arguments); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /predis/Command/HyperLogLogMerge.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/pfmerge 16 | * @author Daniele Alessandri 17 | */ 18 | class HyperLogLogMerge extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'PFMERGE'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function filterArguments(array $arguments) 32 | { 33 | return self::normalizeArguments($arguments); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /predis/Command/KeyDelete.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/del 16 | * @author Daniele Alessandri 17 | */ 18 | class KeyDelete extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'DEL'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function filterArguments(array $arguments) 32 | { 33 | return self::normalizeArguments($arguments); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /predis/Command/KeyDump.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/dump 16 | * @author Daniele Alessandri 17 | */ 18 | class KeyDump extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'DUMP'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/KeyExists.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/exists 16 | * @author Daniele Alessandri 17 | */ 18 | class KeyExists extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'EXISTS'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | public function parseResponse($data) 32 | { 33 | return (bool) $data; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /predis/Command/KeyExpire.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/expire 16 | * @author Daniele Alessandri 17 | */ 18 | class KeyExpire extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'EXPIRE'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | public function parseResponse($data) 32 | { 33 | return (bool) $data; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /predis/Command/KeyExpireAt.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/expireat 16 | * @author Daniele Alessandri 17 | */ 18 | class KeyExpireAt extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'EXPIREAT'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | public function parseResponse($data) 32 | { 33 | return (bool) $data; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /predis/Command/KeyKeys.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/keys 16 | * @author Daniele Alessandri 17 | */ 18 | class KeyKeys extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'KEYS'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/KeyMove.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/move 16 | * @author Daniele Alessandri 17 | */ 18 | class KeyMove extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'MOVE'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | public function parseResponse($data) 32 | { 33 | return (bool) $data; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /predis/Command/KeyPersist.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/persist 16 | * @author Daniele Alessandri 17 | */ 18 | class KeyPersist extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'PERSIST'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | public function parseResponse($data) 32 | { 33 | return (bool) $data; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /predis/Command/KeyPreciseExpire.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/pexpire 16 | * @author Daniele Alessandri 17 | */ 18 | class KeyPreciseExpire extends KeyExpire 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'PEXPIRE'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/KeyPreciseExpireAt.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/pexpireat 16 | * @author Daniele Alessandri 17 | */ 18 | class KeyPreciseExpireAt extends KeyExpireAt 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'PEXPIREAT'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/KeyPreciseTimeToLive.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/pttl 16 | * @author Daniele Alessandri 17 | */ 18 | class KeyPreciseTimeToLive extends KeyTimeToLive 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'PTTL'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/KeyRandom.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/randomkey 16 | * @author Daniele Alessandri 17 | */ 18 | class KeyRandom extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'RANDOMKEY'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | public function parseResponse($data) 32 | { 33 | return $data !== '' ? $data : null; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /predis/Command/KeyRename.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/rename 16 | * @author Daniele Alessandri 17 | */ 18 | class KeyRename extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'RENAME'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/KeyRenamePreserve.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/renamenx 16 | * @author Daniele Alessandri 17 | */ 18 | class KeyRenamePreserve extends KeyRename 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'RENAMENX'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | public function parseResponse($data) 32 | { 33 | return (bool) $data; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /predis/Command/KeyRestore.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/restore 16 | * @author Daniele Alessandri 17 | */ 18 | class KeyRestore extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'RESTORE'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/KeyScan.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/scan 16 | * @author Daniele Alessandri 17 | */ 18 | class KeyScan extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'SCAN'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function filterArguments(array $arguments) 32 | { 33 | if (count($arguments) === 2 && is_array($arguments[1])) { 34 | $options = $this->prepareOptions(array_pop($arguments)); 35 | $arguments = array_merge($arguments, $options); 36 | } 37 | 38 | return $arguments; 39 | } 40 | 41 | /** 42 | * Returns a list of options and modifiers compatible with Redis. 43 | * 44 | * @param array $options List of options. 45 | * 46 | * @return array 47 | */ 48 | protected function prepareOptions($options) 49 | { 50 | $options = array_change_key_case($options, CASE_UPPER); 51 | $normalized = array(); 52 | 53 | if (!empty($options['MATCH'])) { 54 | $normalized[] = 'MATCH'; 55 | $normalized[] = $options['MATCH']; 56 | } 57 | 58 | if (!empty($options['COUNT'])) { 59 | $normalized[] = 'COUNT'; 60 | $normalized[] = $options['COUNT']; 61 | } 62 | 63 | return $normalized; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /predis/Command/KeySort.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/sort 16 | * @author Daniele Alessandri 17 | */ 18 | class KeySort extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'SORT'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function filterArguments(array $arguments) 32 | { 33 | if (count($arguments) === 1) { 34 | return $arguments; 35 | } 36 | 37 | $query = array($arguments[0]); 38 | $sortParams = array_change_key_case($arguments[1], CASE_UPPER); 39 | 40 | if (isset($sortParams['BY'])) { 41 | $query[] = 'BY'; 42 | $query[] = $sortParams['BY']; 43 | } 44 | 45 | if (isset($sortParams['GET'])) { 46 | $getargs = $sortParams['GET']; 47 | 48 | if (is_array($getargs)) { 49 | foreach ($getargs as $getarg) { 50 | $query[] = 'GET'; 51 | $query[] = $getarg; 52 | } 53 | } else { 54 | $query[] = 'GET'; 55 | $query[] = $getargs; 56 | } 57 | } 58 | 59 | if (isset($sortParams['LIMIT']) && 60 | is_array($sortParams['LIMIT']) && 61 | count($sortParams['LIMIT']) == 2) { 62 | 63 | $query[] = 'LIMIT'; 64 | $query[] = $sortParams['LIMIT'][0]; 65 | $query[] = $sortParams['LIMIT'][1]; 66 | } 67 | 68 | if (isset($sortParams['SORT'])) { 69 | $query[] = strtoupper($sortParams['SORT']); 70 | } 71 | 72 | if (isset($sortParams['ALPHA']) && $sortParams['ALPHA'] == true) { 73 | $query[] = 'ALPHA'; 74 | } 75 | 76 | if (isset($sortParams['STORE'])) { 77 | $query[] = 'STORE'; 78 | $query[] = $sortParams['STORE']; 79 | } 80 | 81 | return $query; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /predis/Command/KeyTimeToLive.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/ttl 16 | * @author Daniele Alessandri 17 | */ 18 | class KeyTimeToLive extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'TTL'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/KeyType.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/type 16 | * @author Daniele Alessandri 17 | */ 18 | class KeyType extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'TYPE'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ListIndex.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/lindex 16 | * @author Daniele Alessandri 17 | */ 18 | class ListIndex extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'LINDEX'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ListInsert.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/linsert 16 | * @author Daniele Alessandri 17 | */ 18 | class ListInsert extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'LINSERT'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ListLength.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/llen 16 | * @author Daniele Alessandri 17 | */ 18 | class ListLength extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'LLEN'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ListPopFirst.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/lpop 16 | * @author Daniele Alessandri 17 | */ 18 | class ListPopFirst extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'LPOP'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ListPopFirstBlocking.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/blpop 16 | * @author Daniele Alessandri 17 | */ 18 | class ListPopFirstBlocking extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'BLPOP'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function filterArguments(array $arguments) 32 | { 33 | if (count($arguments) === 2 && is_array($arguments[0])) { 34 | list($arguments, $timeout) = $arguments; 35 | array_push($arguments, $timeout); 36 | } 37 | 38 | return $arguments; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /predis/Command/ListPopLast.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/rpop 16 | * @author Daniele Alessandri 17 | */ 18 | class ListPopLast extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'RPOP'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ListPopLastBlocking.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/brpop 16 | * @author Daniele Alessandri 17 | */ 18 | class ListPopLastBlocking extends ListPopFirstBlocking 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'BRPOP'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ListPopLastPushHead.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/rpoplpush 16 | * @author Daniele Alessandri 17 | */ 18 | class ListPopLastPushHead extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'RPOPLPUSH'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ListPopLastPushHeadBlocking.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/brpoplpush 16 | * @author Daniele Alessandri 17 | */ 18 | class ListPopLastPushHeadBlocking extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'BRPOPLPUSH'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ListPushHead.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/lpush 16 | * @author Daniele Alessandri 17 | */ 18 | class ListPushHead extends ListPushTail 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'LPUSH'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ListPushHeadX.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/lpushx 16 | * @author Daniele Alessandri 17 | */ 18 | class ListPushHeadX extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'LPUSHX'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ListPushTail.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/rpush 16 | * @author Daniele Alessandri 17 | */ 18 | class ListPushTail extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'RPUSH'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function filterArguments(array $arguments) 32 | { 33 | return self::normalizeVariadic($arguments); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /predis/Command/ListPushTailX.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/rpushx 16 | * @author Daniele Alessandri 17 | */ 18 | class ListPushTailX extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'RPUSHX'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ListRange.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/lrange 16 | * @author Daniele Alessandri 17 | */ 18 | class ListRange extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'LRANGE'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ListRemove.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/lrem 16 | * @author Daniele Alessandri 17 | */ 18 | class ListRemove extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'LREM'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ListSet.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/lset 16 | * @author Daniele Alessandri 17 | */ 18 | class ListSet extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'LSET'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ListTrim.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/ltrim 16 | * @author Daniele Alessandri 17 | */ 18 | class ListTrim extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'LTRIM'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/PrefixableCommandInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * Defines a command whose keys can be prefixed. 16 | * 17 | * @author Daniele Alessandri 18 | */ 19 | interface PrefixableCommandInterface extends CommandInterface 20 | { 21 | /** 22 | * Prefixes all the keys found in the arguments of the command. 23 | * 24 | * @param string $prefix String used to prefix the keys. 25 | */ 26 | public function prefixKeys($prefix); 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/Processor/ProcessorInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command\Processor; 13 | 14 | use Predis\Command\CommandInterface; 15 | 16 | /** 17 | * A command processor processes Redis commands before they are sent to Redis. 18 | * 19 | * @author Daniele Alessandri 20 | */ 21 | interface ProcessorInterface 22 | { 23 | /** 24 | * Processes the given Redis command. 25 | * 26 | * @param CommandInterface $command Command instance. 27 | */ 28 | public function process(CommandInterface $command); 29 | } 30 | -------------------------------------------------------------------------------- /predis/Command/PubSubPublish.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/publish 16 | * @author Daniele Alessandri 17 | */ 18 | class PubSubPublish extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'PUBLISH'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/PubSubPubsub.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/pubsub 16 | * @author Daniele Alessandri 17 | */ 18 | class PubSubPubsub extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'PUBSUB'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | public function parseResponse($data) 32 | { 33 | switch (strtolower($this->getArgument(0))) { 34 | case 'numsub': 35 | return self::processNumsub($data); 36 | 37 | default: 38 | return $data; 39 | } 40 | } 41 | 42 | /** 43 | * Returns the processed response to PUBSUB NUMSUB. 44 | * 45 | * @param array $channels List of channels 46 | * 47 | * @return array 48 | */ 49 | protected static function processNumsub(array $channels) 50 | { 51 | $processed = array(); 52 | $count = count($channels); 53 | 54 | for ($i = 0; $i < $count; $i++) { 55 | $processed[$channels[$i]] = $channels[++$i]; 56 | } 57 | 58 | return $processed; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /predis/Command/PubSubSubscribe.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/subscribe 16 | * @author Daniele Alessandri 17 | */ 18 | class PubSubSubscribe extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'SUBSCRIBE'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function filterArguments(array $arguments) 32 | { 33 | return self::normalizeArguments($arguments); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /predis/Command/PubSubSubscribeByPattern.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/psubscribe 16 | * @author Daniele Alessandri 17 | */ 18 | class PubSubSubscribeByPattern extends PubSubSubscribe 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'PSUBSCRIBE'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/PubSubUnsubscribe.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/unsubscribe 16 | * @author Daniele Alessandri 17 | */ 18 | class PubSubUnsubscribe extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'UNSUBSCRIBE'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function filterArguments(array $arguments) 32 | { 33 | return self::normalizeArguments($arguments); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /predis/Command/PubSubUnsubscribeByPattern.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/punsubscribe 16 | * @author Daniele Alessandri 17 | */ 18 | class PubSubUnsubscribeByPattern extends PubSubUnsubscribe 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'PUNSUBSCRIBE'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ScriptCommand.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * Base class used to implement an higher level abstraction for commands based 16 | * on Lua scripting with EVAL and EVALSHA. 17 | * 18 | * @link http://redis.io/commands/eval 19 | * @author Daniele Alessandri 20 | */ 21 | abstract class ScriptCommand extends ServerEvalSHA 22 | { 23 | /** 24 | * Gets the body of a Lua script. 25 | * 26 | * @return string 27 | */ 28 | abstract public function getScript(); 29 | 30 | /** 31 | * Specifies the number of arguments that should be considered as keys. 32 | * 33 | * The default behaviour for the base class is to return 0 to indicate that 34 | * all the elements of the arguments array should be considered as keys, but 35 | * subclasses can enforce a static number of keys. 36 | * 37 | * @return int 38 | */ 39 | protected function getKeysCount() 40 | { 41 | return 0; 42 | } 43 | 44 | /** 45 | * Returns the elements from the arguments that are identified as keys. 46 | * 47 | * @return array 48 | */ 49 | public function getKeys() 50 | { 51 | return array_slice($this->getArguments(), 2, $this->getKeysCount()); 52 | } 53 | 54 | /** 55 | * {@inheritdoc} 56 | */ 57 | protected function filterArguments(array $arguments) 58 | { 59 | if (($numkeys = $this->getKeysCount()) && $numkeys < 0) { 60 | $numkeys = count($arguments) + $numkeys; 61 | } 62 | 63 | return array_merge(array(sha1($this->getScript()), (int) $numkeys), $arguments); 64 | } 65 | 66 | /** 67 | * @return array 68 | */ 69 | public function getEvalArguments() 70 | { 71 | $arguments = $this->getArguments(); 72 | $arguments[0] = $this->getScript(); 73 | 74 | return $arguments; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /predis/Command/ServerBackgroundRewriteAOF.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/bgrewriteaof 16 | * @author Daniele Alessandri 17 | */ 18 | class ServerBackgroundRewriteAOF extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'BGREWRITEAOF'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | public function parseResponse($data) 32 | { 33 | return $data == 'Background append only file rewriting started'; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /predis/Command/ServerBackgroundSave.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/bgsave 16 | * @author Daniele Alessandri 17 | */ 18 | class ServerBackgroundSave extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'BGSAVE'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | public function parseResponse($data) 32 | { 33 | return $data === 'Background saving started' ? true : $data; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /predis/Command/ServerClient.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/client-list 16 | * @link http://redis.io/commands/client-kill 17 | * @link http://redis.io/commands/client-getname 18 | * @link http://redis.io/commands/client-setname 19 | * @author Daniele Alessandri 20 | */ 21 | class ServerClient extends Command 22 | { 23 | /** 24 | * {@inheritdoc} 25 | */ 26 | public function getId() 27 | { 28 | return 'CLIENT'; 29 | } 30 | 31 | /** 32 | * {@inheritdoc} 33 | */ 34 | public function parseResponse($data) 35 | { 36 | $args = array_change_key_case($this->getArguments(), CASE_UPPER); 37 | 38 | switch (strtoupper($args[0])) { 39 | case 'LIST': 40 | return $this->parseClientList($data); 41 | case 'KILL': 42 | case 'GETNAME': 43 | case 'SETNAME': 44 | default: 45 | return $data; 46 | } 47 | } 48 | 49 | /** 50 | * Parses the response to CLIENT LIST and returns a structured list. 51 | * 52 | * @param string $data Response buffer. 53 | * 54 | * @return array 55 | */ 56 | protected function parseClientList($data) 57 | { 58 | $clients = array(); 59 | 60 | foreach (explode("\n", $data, -1) as $clientData) { 61 | $client = array(); 62 | 63 | foreach (explode(' ', $clientData) as $kv) { 64 | @list($k, $v) = explode('=', $kv); 65 | $client[$k] = $v; 66 | } 67 | 68 | $clients[] = $client; 69 | } 70 | 71 | return $clients; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /predis/Command/ServerCommand.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/command 16 | * @author Daniele Alessandri 17 | */ 18 | class ServerCommand extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'COMMAND'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ServerConfig.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/config-set 16 | * @link http://redis.io/commands/config-get 17 | * @link http://redis.io/commands/config-resetstat 18 | * @link http://redis.io/commands/config-rewrite 19 | * @author Daniele Alessandri 20 | */ 21 | class ServerConfig extends Command 22 | { 23 | /** 24 | * {@inheritdoc} 25 | */ 26 | public function getId() 27 | { 28 | return 'CONFIG'; 29 | } 30 | 31 | /** 32 | * {@inheritdoc} 33 | */ 34 | public function parseResponse($data) 35 | { 36 | if (is_array($data)) { 37 | $result = array(); 38 | 39 | for ($i = 0; $i < count($data); $i++) { 40 | $result[$data[$i]] = $data[++$i]; 41 | } 42 | 43 | return $result; 44 | } 45 | 46 | return $data; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /predis/Command/ServerDatabaseSize.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/dbsize 16 | * @author Daniele Alessandri 17 | */ 18 | class ServerDatabaseSize extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'DBSIZE'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ServerEval.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/eval 16 | * @author Daniele Alessandri 17 | */ 18 | class ServerEval extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'EVAL'; 26 | } 27 | 28 | /** 29 | * Calculates the SHA1 hash of the body of the script. 30 | * 31 | * @return string SHA1 hash. 32 | */ 33 | public function getScriptHash() 34 | { 35 | return sha1($this->getArgument(0)); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /predis/Command/ServerEvalSHA.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/evalsha 16 | * @author Daniele Alessandri 17 | */ 18 | class ServerEvalSHA extends ServerEval 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'EVALSHA'; 26 | } 27 | 28 | /** 29 | * Returns the SHA1 hash of the body of the script. 30 | * 31 | * @return string SHA1 hash. 32 | */ 33 | public function getScriptHash() 34 | { 35 | return $this->getArgument(0); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /predis/Command/ServerFlushAll.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/flushall 16 | * @author Daniele Alessandri 17 | */ 18 | class ServerFlushAll extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'FLUSHALL'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ServerFlushDatabase.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/flushdb 16 | * @author Daniele Alessandri 17 | */ 18 | class ServerFlushDatabase extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'FLUSHDB'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ServerInfoV26x.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/info 16 | * @author Daniele Alessandri 17 | */ 18 | class ServerInfoV26x extends ServerInfo 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function parseResponse($data) 24 | { 25 | $info = array(); 26 | $current = null; 27 | $infoLines = preg_split('/\r?\n/', $data); 28 | 29 | if (isset($infoLines[0]) && $infoLines[0][0] !== '#') { 30 | return parent::parseResponse($data); 31 | } 32 | 33 | foreach ($infoLines as $row) { 34 | if ($row === '') { 35 | continue; 36 | } 37 | 38 | if (preg_match('/^# (\w+)$/', $row, $matches)) { 39 | $info[$matches[1]] = array(); 40 | $current = &$info[$matches[1]]; 41 | continue; 42 | } 43 | 44 | list($k, $v) = $this->parseRow($row); 45 | $current[$k] = $v; 46 | } 47 | 48 | return $info; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /predis/Command/ServerLastSave.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/lastsave 16 | * @author Daniele Alessandri 17 | */ 18 | class ServerLastSave extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'LASTSAVE'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ServerMonitor.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/monitor 16 | * @author Daniele Alessandri 17 | */ 18 | class ServerMonitor extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'MONITOR'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ServerObject.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/object 16 | * @author Daniele Alessandri 17 | */ 18 | class ServerObject extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'OBJECT'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ServerSave.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/save 16 | * @author Daniele Alessandri 17 | */ 18 | class ServerSave extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'SAVE'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ServerScript.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/script 16 | * @author Daniele Alessandri 17 | */ 18 | class ServerScript extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'SCRIPT'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ServerSentinel.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/topics/sentinel 16 | * @author Daniele Alessandri 17 | */ 18 | class ServerSentinel extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'SENTINEL'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | public function parseResponse($data) 32 | { 33 | switch (strtolower($this->getArgument(0))) { 34 | case 'masters': 35 | case 'slaves': 36 | return self::processMastersOrSlaves($data); 37 | 38 | default: 39 | return $data; 40 | } 41 | } 42 | 43 | /** 44 | * Returns a processed response to SENTINEL MASTERS or SENTINEL SLAVES. 45 | * 46 | * @param array $servers List of Redis servers. 47 | * 48 | * @return array 49 | */ 50 | protected static function processMastersOrSlaves(array $servers) 51 | { 52 | foreach ($servers as $idx => $node) { 53 | $processed = array(); 54 | $count = count($node); 55 | 56 | for ($i = 0; $i < $count; $i++) { 57 | $processed[$node[$i]] = $node[++$i]; 58 | } 59 | 60 | $servers[$idx] = $processed; 61 | } 62 | 63 | return $servers; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /predis/Command/ServerShutdown.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/shutdown 16 | * @author Daniele Alessandri 17 | */ 18 | class ServerShutdown extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'SHUTDOWN'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ServerSlaveOf.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/slaveof 16 | * @author Daniele Alessandri 17 | */ 18 | class ServerSlaveOf extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'SLAVEOF'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function filterArguments(array $arguments) 32 | { 33 | if (count($arguments) === 0 || $arguments[0] === 'NO ONE') { 34 | return array('NO', 'ONE'); 35 | } 36 | 37 | return $arguments; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /predis/Command/ServerSlowlog.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/slowlog 16 | * @author Daniele Alessandri 17 | */ 18 | class ServerSlowlog extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'SLOWLOG'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | public function parseResponse($data) 32 | { 33 | if (is_array($data)) { 34 | $log = array(); 35 | 36 | foreach ($data as $index => $entry) { 37 | $log[$index] = array( 38 | 'id' => $entry[0], 39 | 'timestamp' => $entry[1], 40 | 'duration' => $entry[2], 41 | 'command' => $entry[3], 42 | ); 43 | } 44 | 45 | return $log; 46 | } 47 | 48 | return $data; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /predis/Command/ServerTime.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/time 16 | * @author Daniele Alessandri 17 | */ 18 | class ServerTime extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'TIME'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/SetAdd.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/sadd 16 | * @author Daniele Alessandri 17 | */ 18 | class SetAdd extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'SADD'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function filterArguments(array $arguments) 32 | { 33 | return self::normalizeVariadic($arguments); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /predis/Command/SetCardinality.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/scard 16 | * @author Daniele Alessandri 17 | */ 18 | class SetCardinality extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'SCARD'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/SetDifference.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/sdiff 16 | * @author Daniele Alessandri 17 | */ 18 | class SetDifference extends SetIntersection 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'SDIFF'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/SetDifferenceStore.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/sdiffstore 16 | * @author Daniele Alessandri 17 | */ 18 | class SetDifferenceStore extends SetIntersectionStore 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'SDIFFSTORE'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/SetIntersection.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/sinter 16 | * @author Daniele Alessandri 17 | */ 18 | class SetIntersection extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'SINTER'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function filterArguments(array $arguments) 32 | { 33 | return self::normalizeArguments($arguments); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /predis/Command/SetIntersectionStore.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/sinterstore 16 | * @author Daniele Alessandri 17 | */ 18 | class SetIntersectionStore extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'SINTERSTORE'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function filterArguments(array $arguments) 32 | { 33 | if (count($arguments) === 2 && is_array($arguments[1])) { 34 | return array_merge(array($arguments[0]), $arguments[1]); 35 | } 36 | 37 | return $arguments; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /predis/Command/SetIsMember.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/sismember 16 | * @author Daniele Alessandri 17 | */ 18 | class SetIsMember extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'SISMEMBER'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | public function parseResponse($data) 32 | { 33 | return (bool) $data; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /predis/Command/SetMembers.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/smembers 16 | * @author Daniele Alessandri 17 | */ 18 | class SetMembers extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'SMEMBERS'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/SetMove.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/smove 16 | * @author Daniele Alessandri 17 | */ 18 | class SetMove extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'SMOVE'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | public function parseResponse($data) 32 | { 33 | return (bool) $data; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /predis/Command/SetPop.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/spop 16 | * @author Daniele Alessandri 17 | */ 18 | class SetPop extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'SPOP'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/SetRandomMember.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/srandmember 16 | * @author Daniele Alessandri 17 | */ 18 | class SetRandomMember extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'SRANDMEMBER'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/SetRemove.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/srem 16 | * @author Daniele Alessandri 17 | */ 18 | class SetRemove extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'SREM'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function filterArguments(array $arguments) 32 | { 33 | return self::normalizeVariadic($arguments); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /predis/Command/SetScan.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/sscan 16 | * @author Daniele Alessandri 17 | */ 18 | class SetScan extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'SSCAN'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function filterArguments(array $arguments) 32 | { 33 | if (count($arguments) === 3 && is_array($arguments[2])) { 34 | $options = $this->prepareOptions(array_pop($arguments)); 35 | $arguments = array_merge($arguments, $options); 36 | } 37 | 38 | return $arguments; 39 | } 40 | 41 | /** 42 | * Returns a list of options and modifiers compatible with Redis. 43 | * 44 | * @param array $options List of options. 45 | * 46 | * @return array 47 | */ 48 | protected function prepareOptions($options) 49 | { 50 | $options = array_change_key_case($options, CASE_UPPER); 51 | $normalized = array(); 52 | 53 | if (!empty($options['MATCH'])) { 54 | $normalized[] = 'MATCH'; 55 | $normalized[] = $options['MATCH']; 56 | } 57 | 58 | if (!empty($options['COUNT'])) { 59 | $normalized[] = 'COUNT'; 60 | $normalized[] = $options['COUNT']; 61 | } 62 | 63 | return $normalized; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /predis/Command/SetUnion.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/sunion 16 | * @author Daniele Alessandri 17 | */ 18 | class SetUnion extends SetIntersection 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'SUNION'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/SetUnionStore.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/sunionstore 16 | * @author Daniele Alessandri 17 | */ 18 | class SetUnionStore extends SetIntersectionStore 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'SUNIONSTORE'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/StringAppend.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/append 16 | * @author Daniele Alessandri 17 | */ 18 | class StringAppend extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'APPEND'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/StringBitCount.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/bitcount 16 | * @author Daniele Alessandri 17 | */ 18 | class StringBitCount extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'BITCOUNT'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/StringBitOp.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/bitop 16 | * @author Daniele Alessandri 17 | */ 18 | class StringBitOp extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'BITOP'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function filterArguments(array $arguments) 32 | { 33 | if (count($arguments) === 3 && is_array($arguments[2])) { 34 | list($operation, $destination, ) = $arguments; 35 | $arguments = $arguments[2]; 36 | array_unshift($arguments, $operation, $destination); 37 | } 38 | 39 | return $arguments; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /predis/Command/StringDecrement.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/decr 16 | * @author Daniele Alessandri 17 | */ 18 | class StringDecrement extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'DECR'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/StringDecrementBy.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/decrby 16 | * @author Daniele Alessandri 17 | */ 18 | class StringDecrementBy extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'DECRBY'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/StringGet.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/get 16 | * @author Daniele Alessandri 17 | */ 18 | class StringGet extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'GET'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/StringGetBit.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/getbit 16 | * @author Daniele Alessandri 17 | */ 18 | class StringGetBit extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'GETBIT'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/StringGetMultiple.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/mget 16 | * @author Daniele Alessandri 17 | */ 18 | class StringGetMultiple extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'MGET'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function filterArguments(array $arguments) 32 | { 33 | return self::normalizeArguments($arguments); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /predis/Command/StringGetRange.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/getrange 16 | * @author Daniele Alessandri 17 | */ 18 | class StringGetRange extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'GETRANGE'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/StringGetSet.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/getset 16 | * @author Daniele Alessandri 17 | */ 18 | class StringGetSet extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'GETSET'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/StringIncrement.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/incr 16 | * @author Daniele Alessandri 17 | */ 18 | class StringIncrement extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'INCR'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/StringIncrementBy.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/incrby 16 | * @author Daniele Alessandri 17 | */ 18 | class StringIncrementBy extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'INCRBY'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/StringIncrementByFloat.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/incrbyfloat 16 | * @author Daniele Alessandri 17 | */ 18 | class StringIncrementByFloat extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'INCRBYFLOAT'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/StringPreciseSetExpire.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/psetex 16 | * @author Daniele Alessandri 17 | */ 18 | class StringPreciseSetExpire extends StringSetExpire 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'PSETEX'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/StringSet.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/set 16 | * @author Daniele Alessandri 17 | */ 18 | class StringSet extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'SET'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/StringSetBit.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/setbit 16 | * @author Daniele Alessandri 17 | */ 18 | class StringSetBit extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'SETBIT'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/StringSetExpire.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/setex 16 | * @author Daniele Alessandri 17 | */ 18 | class StringSetExpire extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'SETEX'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/StringSetMultiple.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/mset 16 | * @author Daniele Alessandri 17 | */ 18 | class StringSetMultiple extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'MSET'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function filterArguments(array $arguments) 32 | { 33 | if (count($arguments) === 1 && is_array($arguments[0])) { 34 | $flattenedKVs = array(); 35 | $args = $arguments[0]; 36 | 37 | foreach ($args as $k => $v) { 38 | $flattenedKVs[] = $k; 39 | $flattenedKVs[] = $v; 40 | } 41 | 42 | return $flattenedKVs; 43 | } 44 | 45 | return $arguments; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /predis/Command/StringSetMultiplePreserve.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/msetnx 16 | * @author Daniele Alessandri 17 | */ 18 | class StringSetMultiplePreserve extends StringSetMultiple 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'MSETNX'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | public function parseResponse($data) 32 | { 33 | return (bool) $data; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /predis/Command/StringSetPreserve.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/setnx 16 | * @author Daniele Alessandri 17 | */ 18 | class StringSetPreserve extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'SETNX'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | public function parseResponse($data) 32 | { 33 | return (bool) $data; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /predis/Command/StringSetRange.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/setrange 16 | * @author Daniele Alessandri 17 | */ 18 | class StringSetRange extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'SETRANGE'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/StringStrlen.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/strlen 16 | * @author Daniele Alessandri 17 | */ 18 | class StringStrlen extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'STRLEN'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/StringSubstr.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/substr 16 | * @author Daniele Alessandri 17 | */ 18 | class StringSubstr extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'SUBSTR'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/TransactionDiscard.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/discard 16 | * @author Daniele Alessandri 17 | */ 18 | class TransactionDiscard extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'DISCARD'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/TransactionExec.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/exec 16 | * @author Daniele Alessandri 17 | */ 18 | class TransactionExec extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'EXEC'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/TransactionMulti.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/multi 16 | * @author Daniele Alessandri 17 | */ 18 | class TransactionMulti extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'MULTI'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/TransactionUnwatch.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/unwatch 16 | * @author Daniele Alessandri 17 | */ 18 | class TransactionUnwatch extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'UNWATCH'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/TransactionWatch.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/watch 16 | * @author Daniele Alessandri 17 | */ 18 | class TransactionWatch extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'WATCH'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function filterArguments(array $arguments) 32 | { 33 | if (isset($arguments[0]) && is_array($arguments[0])) { 34 | return $arguments[0]; 35 | } 36 | 37 | return $arguments; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /predis/Command/ZSetAdd.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/zadd 16 | * @author Daniele Alessandri 17 | */ 18 | class ZSetAdd extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'ZADD'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function filterArguments(array $arguments) 32 | { 33 | if (count($arguments) === 2 && is_array($arguments[1])) { 34 | $flattened = array($arguments[0]); 35 | 36 | foreach ($arguments[1] as $member => $score) { 37 | $flattened[] = $score; 38 | $flattened[] = $member; 39 | } 40 | 41 | return $flattened; 42 | } 43 | 44 | return $arguments; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /predis/Command/ZSetCardinality.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/zcard 16 | * @author Daniele Alessandri 17 | */ 18 | class ZSetCardinality extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'ZCARD'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ZSetCount.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/zcount 16 | * @author Daniele Alessandri 17 | */ 18 | class ZSetCount extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'ZCOUNT'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ZSetIncrementBy.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/zincrby 16 | * @author Daniele Alessandri 17 | */ 18 | class ZSetIncrementBy extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'ZINCRBY'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ZSetIntersectionStore.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/zinterstore 16 | * @author Daniele Alessandri 17 | */ 18 | class ZSetIntersectionStore extends ZSetUnionStore 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'ZINTERSTORE'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ZSetLexCount.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/zlexcount 16 | * @author Daniele Alessandri 17 | */ 18 | class ZSetLexCount extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'ZLEXCOUNT'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ZSetRangeByLex.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/zrangebylex 16 | * @author Daniele Alessandri 17 | */ 18 | class ZSetRangeByLex extends ZSetRange 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'ZRANGEBYLEX'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function prepareOptions($options) 32 | { 33 | $opts = array_change_key_case($options, CASE_UPPER); 34 | $finalizedOpts = array(); 35 | 36 | if (isset($opts['LIMIT']) && is_array($opts['LIMIT'])) { 37 | $limit = array_change_key_case($opts['LIMIT'], CASE_UPPER); 38 | 39 | $finalizedOpts[] = 'LIMIT'; 40 | $finalizedOpts[] = isset($limit['OFFSET']) ? $limit['OFFSET'] : $limit[0]; 41 | $finalizedOpts[] = isset($limit['COUNT']) ? $limit['COUNT'] : $limit[1]; 42 | } 43 | 44 | return $finalizedOpts; 45 | } 46 | 47 | /** 48 | * {@inheritdoc} 49 | */ 50 | protected function withScores() 51 | { 52 | return false; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /predis/Command/ZSetRangeByScore.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/zrangebyscore 16 | * @author Daniele Alessandri 17 | */ 18 | class ZSetRangeByScore extends ZSetRange 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'ZRANGEBYSCORE'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function prepareOptions($options) 32 | { 33 | $opts = array_change_key_case($options, CASE_UPPER); 34 | $finalizedOpts = array(); 35 | 36 | if (isset($opts['LIMIT']) && is_array($opts['LIMIT'])) { 37 | $limit = array_change_key_case($opts['LIMIT'], CASE_UPPER); 38 | 39 | $finalizedOpts[] = 'LIMIT'; 40 | $finalizedOpts[] = isset($limit['OFFSET']) ? $limit['OFFSET'] : $limit[0]; 41 | $finalizedOpts[] = isset($limit['COUNT']) ? $limit['COUNT'] : $limit[1]; 42 | } 43 | 44 | return array_merge($finalizedOpts, parent::prepareOptions($options)); 45 | } 46 | 47 | /** 48 | * {@inheritdoc} 49 | */ 50 | protected function withScores() 51 | { 52 | $arguments = $this->getArguments(); 53 | 54 | for ($i = 3; $i < count($arguments); $i++) { 55 | switch (strtoupper($arguments[$i])) { 56 | case 'WITHSCORES': 57 | return true; 58 | 59 | case 'LIMIT': 60 | $i += 2; 61 | break; 62 | } 63 | } 64 | 65 | return false; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /predis/Command/ZSetRank.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/zrank 16 | * @author Daniele Alessandri 17 | */ 18 | class ZSetRank extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'ZRANK'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ZSetRemove.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/zrem 16 | * @author Daniele Alessandri 17 | */ 18 | class ZSetRemove extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'ZREM'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function filterArguments(array $arguments) 32 | { 33 | return self::normalizeVariadic($arguments); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /predis/Command/ZSetRemoveRangeByLex.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/zremrangebylex 16 | * @author Daniele Alessandri 17 | */ 18 | class ZSetRemoveRangeByLex extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'ZREMRANGEBYLEX'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ZSetRemoveRangeByRank.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/zremrangebyrank 16 | * @author Daniele Alessandri 17 | */ 18 | class ZSetRemoveRangeByRank extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'ZREMRANGEBYRANK'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ZSetRemoveRangeByScore.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/zremrangebyscore 16 | * @author Daniele Alessandri 17 | */ 18 | class ZSetRemoveRangeByScore extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'ZREMRANGEBYSCORE'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ZSetReverseRange.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/zrevrange 16 | * @author Daniele Alessandri 17 | */ 18 | class ZSetReverseRange extends ZSetRange 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'ZREVRANGE'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ZSetReverseRangeByScore.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/zrevrangebyscore 16 | * @author Daniele Alessandri 17 | */ 18 | class ZSetReverseRangeByScore extends ZSetRangeByScore 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'ZREVRANGEBYSCORE'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ZSetReverseRank.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/zrevrank 16 | * @author Daniele Alessandri 17 | */ 18 | class ZSetReverseRank extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'ZREVRANK'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ZSetScan.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/zscan 16 | * @author Daniele Alessandri 17 | */ 18 | class ZSetScan extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'ZSCAN'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function filterArguments(array $arguments) 32 | { 33 | if (count($arguments) === 3 && is_array($arguments[2])) { 34 | $options = $this->prepareOptions(array_pop($arguments)); 35 | $arguments = array_merge($arguments, $options); 36 | } 37 | 38 | return $arguments; 39 | } 40 | 41 | /** 42 | * Returns a list of options and modifiers compatible with Redis. 43 | * 44 | * @param array $options List of options. 45 | * 46 | * @return array 47 | */ 48 | protected function prepareOptions($options) 49 | { 50 | $options = array_change_key_case($options, CASE_UPPER); 51 | $normalized = array(); 52 | 53 | if (!empty($options['MATCH'])) { 54 | $normalized[] = 'MATCH'; 55 | $normalized[] = $options['MATCH']; 56 | } 57 | 58 | if (!empty($options['COUNT'])) { 59 | $normalized[] = 'COUNT'; 60 | $normalized[] = $options['COUNT']; 61 | } 62 | 63 | return $normalized; 64 | } 65 | 66 | /** 67 | * {@inheritdoc} 68 | */ 69 | public function parseResponse($data) 70 | { 71 | if (is_array($data)) { 72 | $members = $data[1]; 73 | $result = array(); 74 | 75 | for ($i = 0; $i < count($members); $i++) { 76 | $result[$members[$i]] = (float) $members[++$i]; 77 | } 78 | 79 | $data[1] = $result; 80 | } 81 | 82 | return $data; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /predis/Command/ZSetScore.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/zscore 16 | * @author Daniele Alessandri 17 | */ 18 | class ZSetScore extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'ZSCORE'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /predis/Command/ZSetUnionStore.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Command; 13 | 14 | /** 15 | * @link http://redis.io/commands/zunionstore 16 | * @author Daniele Alessandri 17 | */ 18 | class ZSetUnionStore extends Command 19 | { 20 | /** 21 | * {@inheritdoc} 22 | */ 23 | public function getId() 24 | { 25 | return 'ZUNIONSTORE'; 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | protected function filterArguments(array $arguments) 32 | { 33 | $options = array(); 34 | $argc = count($arguments); 35 | 36 | if ($argc > 2 && is_array($arguments[$argc - 1])) { 37 | $options = $this->prepareOptions(array_pop($arguments)); 38 | } 39 | 40 | if (is_array($arguments[1])) { 41 | $arguments = array_merge( 42 | array($arguments[0], count($arguments[1])), 43 | $arguments[1] 44 | ); 45 | } 46 | 47 | return array_merge($arguments, $options); 48 | } 49 | 50 | /** 51 | * Returns a list of options and modifiers compatible with Redis. 52 | * 53 | * @param array $options List of options. 54 | * 55 | * @return array 56 | */ 57 | private function prepareOptions($options) 58 | { 59 | $opts = array_change_key_case($options, CASE_UPPER); 60 | $finalizedOpts = array(); 61 | 62 | if (isset($opts['WEIGHTS']) && is_array($opts['WEIGHTS'])) { 63 | $finalizedOpts[] = 'WEIGHTS'; 64 | 65 | foreach ($opts['WEIGHTS'] as $weight) { 66 | $finalizedOpts[] = $weight; 67 | } 68 | } 69 | 70 | if (isset($opts['AGGREGATE'])) { 71 | $finalizedOpts[] = 'AGGREGATE'; 72 | $finalizedOpts[] = $opts['AGGREGATE']; 73 | } 74 | 75 | return $finalizedOpts; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /predis/Configuration/ClusterOption.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Configuration; 13 | 14 | use InvalidArgumentException; 15 | use Predis\Connection\Aggregate\ClusterInterface; 16 | use Predis\Connection\Aggregate\PredisCluster; 17 | use Predis\Connection\Aggregate\RedisCluster; 18 | 19 | /** 20 | * Configures an aggregate connection used for clustering 21 | * multiple Redis nodes using various implementations with 22 | * different algorithms or strategies. 23 | * 24 | * @author Daniele Alessandri 25 | */ 26 | class ClusterOption implements OptionInterface 27 | { 28 | /** 29 | * Creates a new cluster connection from on a known descriptive name. 30 | * 31 | * @param OptionsInterface $options Instance of the client options. 32 | * @param string $id Descriptive identifier of the cluster type (`predis`, `redis-cluster`) 33 | * 34 | * @return ClusterInterface|null 35 | */ 36 | protected function createByDescription(OptionsInterface $options, $id) 37 | { 38 | switch ($id) { 39 | case 'predis': 40 | case 'predis-cluster': 41 | return new PredisCluster(); 42 | 43 | case 'redis': 44 | case 'redis-cluster': 45 | return new RedisCluster($options->connections); 46 | 47 | default: 48 | return; 49 | } 50 | } 51 | 52 | /** 53 | * {@inheritdoc} 54 | */ 55 | public function filter(OptionsInterface $options, $value) 56 | { 57 | if (is_string($value)) { 58 | $value = $this->createByDescription($options, $value); 59 | } 60 | 61 | if (!$value instanceof ClusterInterface) { 62 | throw new InvalidArgumentException( 63 | "An instance of type 'Predis\Connection\Aggregate\ClusterInterface' was expected." 64 | ); 65 | } 66 | 67 | return $value; 68 | } 69 | 70 | /** 71 | * {@inheritdoc} 72 | */ 73 | public function getDefault(OptionsInterface $options) 74 | { 75 | return new PredisCluster(); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /predis/Configuration/ConnectionFactoryOption.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Configuration; 13 | 14 | use InvalidArgumentException; 15 | use Predis\Connection\Factory; 16 | use Predis\Connection\FactoryInterface; 17 | 18 | /** 19 | * Configures a connection factory used by the client to create new connection 20 | * instances for single Redis nodes. 21 | * 22 | * @author Daniele Alessandri 23 | */ 24 | class ConnectionFactoryOption implements OptionInterface 25 | { 26 | /** 27 | * {@inheritdoc} 28 | */ 29 | public function filter(OptionsInterface $options, $value) 30 | { 31 | if ($value instanceof FactoryInterface) { 32 | return $value; 33 | } elseif (is_array($value)) { 34 | $factory = $this->getDefault($options); 35 | 36 | foreach ($value as $scheme => $initializer) { 37 | $factory->define($scheme, $initializer); 38 | } 39 | 40 | return $factory; 41 | } else { 42 | throw new InvalidArgumentException( 43 | 'Invalid value provided for the connections option.' 44 | ); 45 | } 46 | } 47 | 48 | /** 49 | * {@inheritdoc} 50 | */ 51 | public function getDefault(OptionsInterface $options) 52 | { 53 | return new Factory(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /predis/Configuration/ExceptionsOption.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Configuration; 13 | 14 | /** 15 | * Configures whether consumers (such as the client) should throw exceptions on 16 | * Redis errors (-ERR responses) or just return instances of error responses. 17 | * 18 | * @author Daniele Alessandri 19 | */ 20 | class ExceptionsOption implements OptionInterface 21 | { 22 | /** 23 | * {@inheritdoc} 24 | */ 25 | public function filter(OptionsInterface $options, $value) 26 | { 27 | return filter_var($value, FILTER_VALIDATE_BOOLEAN); 28 | } 29 | 30 | /** 31 | * {@inheritdoc} 32 | */ 33 | public function getDefault(OptionsInterface $options) 34 | { 35 | return true; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /predis/Configuration/OptionInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Configuration; 13 | 14 | /** 15 | * Defines an handler used by Predis\Configuration\Options to filter, validate 16 | * or return default values for a given option. 17 | * 18 | * @author Daniele Alessandri 19 | */ 20 | interface OptionInterface 21 | { 22 | /** 23 | * Filters and validates the passed value. 24 | * 25 | * @param OptionsInterface $options Options container. 26 | * @param mixed $value Input value. 27 | * 28 | * @return mixed 29 | */ 30 | public function filter(OptionsInterface $options, $value); 31 | 32 | /** 33 | * Returns the default value for the option. 34 | * 35 | * @param OptionsInterface $options Options container. 36 | * 37 | * @return mixed 38 | */ 39 | public function getDefault(OptionsInterface $options); 40 | } 41 | -------------------------------------------------------------------------------- /predis/Configuration/OptionsInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Configuration; 13 | 14 | /** 15 | * Interface defining a container for client options. 16 | * 17 | * @property-read mixed aggregate Custom connection aggregator. 18 | * @property-read mixed cluster Aggregate connection for clustering. 19 | * @property-read mixed connections Connection factory. 20 | * @property-read mixed exceptions Toggles exceptions in client for -ERR responses. 21 | * @property-read mixed prefix Key prefixing strategy using the given prefix. 22 | * @property-read mixed profile Server profile. 23 | * @property-read mixed replication Aggregate connection for replication. 24 | * 25 | * @author Daniele Alessandri 26 | */ 27 | interface OptionsInterface 28 | { 29 | /** 30 | * Returns the default value for the given option. 31 | * 32 | * @param string $option Name of the option. 33 | * 34 | * @return mixed|null 35 | */ 36 | public function getDefault($option); 37 | 38 | /** 39 | * Checks if the given option has been set by the user upon initialization. 40 | * 41 | * @param string $option Name of the option. 42 | * 43 | * @return bool 44 | */ 45 | public function defined($option); 46 | 47 | /** 48 | * Checks if the given option has been set and does not evaluate to NULL. 49 | * 50 | * @param string $option Name of the option. 51 | * 52 | * @return bool 53 | */ 54 | public function __isset($option); 55 | 56 | /** 57 | * Returns the value of the given option. 58 | * 59 | * @param string $option Name of the option. 60 | * 61 | * @return mixed|null 62 | */ 63 | public function __get($option); 64 | } 65 | -------------------------------------------------------------------------------- /predis/Configuration/PrefixOption.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Configuration; 13 | 14 | use Predis\Command\Processor\KeyPrefixProcessor; 15 | use Predis\Command\Processor\ProcessorInterface; 16 | 17 | /** 18 | * Configures a command processor that apply the specified prefix string to a 19 | * series of Redis commands considered prefixable. 20 | * 21 | * @author Daniele Alessandri 22 | */ 23 | class PrefixOption implements OptionInterface 24 | { 25 | /** 26 | * {@inheritdoc} 27 | */ 28 | public function filter(OptionsInterface $options, $value) 29 | { 30 | if ($value instanceof ProcessorInterface) { 31 | return $value; 32 | } 33 | 34 | return new KeyPrefixProcessor($value); 35 | } 36 | 37 | /** 38 | * {@inheritdoc} 39 | */ 40 | public function getDefault(OptionsInterface $options) 41 | { 42 | // NOOP 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /predis/Configuration/ProfileOption.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Configuration; 13 | 14 | use InvalidArgumentException; 15 | use Predis\Profile\Factory; 16 | use Predis\Profile\ProfileInterface; 17 | use Predis\Profile\RedisProfile; 18 | 19 | /** 20 | * Configures the server profile to be used by the client to create command 21 | * instances depending on the specified version of the Redis server. 22 | * 23 | * @author Daniele Alessandri 24 | */ 25 | class ProfileOption implements OptionInterface 26 | { 27 | /** 28 | * Sets the commands processors that need to be applied to the profile. 29 | * 30 | * @param OptionsInterface $options Client options. 31 | * @param ProfileInterface $profile Server profile. 32 | */ 33 | protected function setProcessors(OptionsInterface $options, ProfileInterface $profile) 34 | { 35 | if (isset($options->prefix) && $profile instanceof RedisProfile) { 36 | // NOTE: directly using __get('prefix') is actually a workaround for 37 | // HHVM 2.3.0. It's correct and respects the options interface, it's 38 | // just ugly. We will remove this hack when HHVM will fix re-entrant 39 | // calls to __get() once and for all. 40 | 41 | $profile->setProcessor($options->__get('prefix')); 42 | } 43 | } 44 | 45 | /** 46 | * {@inheritdoc} 47 | */ 48 | public function filter(OptionsInterface $options, $value) 49 | { 50 | if (is_string($value)) { 51 | $value = Factory::get($value); 52 | $this->setProcessors($options, $value); 53 | } elseif (!$value instanceof ProfileInterface) { 54 | throw new InvalidArgumentException('Invalid value for the profile option.'); 55 | } 56 | 57 | return $value; 58 | } 59 | 60 | /** 61 | * {@inheritdoc} 62 | */ 63 | public function getDefault(OptionsInterface $options) 64 | { 65 | $profile = Factory::getDefault(); 66 | $this->setProcessors($options, $profile); 67 | 68 | return $profile; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /predis/Configuration/ReplicationOption.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Configuration; 13 | 14 | use InvalidArgumentException; 15 | use Predis\Connection\Aggregate\MasterSlaveReplication; 16 | use Predis\Connection\Aggregate\ReplicationInterface; 17 | 18 | /** 19 | * Configures an aggregate connection used for master/slave replication among 20 | * multiple Redis nodes. 21 | * 22 | * @author Daniele Alessandri 23 | */ 24 | class ReplicationOption implements OptionInterface 25 | { 26 | /** 27 | * {@inheritdoc} 28 | * 29 | * @todo There's more code than needed due to a bug in filter_var() as 30 | * discussed here https://bugs.php.net/bug.php?id=49510 and different 31 | * behaviours when encountering NULL values on PHP 5.3. 32 | */ 33 | public function filter(OptionsInterface $options, $value) 34 | { 35 | if ($value instanceof ReplicationInterface) { 36 | return $value; 37 | } 38 | 39 | if (is_bool($value) || $value === null) { 40 | return $value ? $this->getDefault($options) : null; 41 | } 42 | 43 | if ( 44 | !is_object($value) && 45 | null !== $asbool = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) 46 | ) { 47 | return $asbool ? $this->getDefault($options) : null; 48 | } 49 | 50 | throw new InvalidArgumentException( 51 | "An instance of type 'Predis\Connection\Aggregate\ReplicationInterface' was expected." 52 | ); 53 | } 54 | 55 | /** 56 | * {@inheritdoc} 57 | */ 58 | public function getDefault(OptionsInterface $options) 59 | { 60 | return new MasterSlaveReplication(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /predis/Connection/Aggregate/ClusterInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Connection\Aggregate; 13 | 14 | use Predis\Connection\AggregateConnectionInterface; 15 | 16 | /** 17 | * Defines a cluster of Redis servers formed by aggregating multiple connection 18 | * instances to single Redis nodes. 19 | * 20 | * @author Daniele Alessandri 21 | */ 22 | interface ClusterInterface extends AggregateConnectionInterface 23 | { 24 | } 25 | -------------------------------------------------------------------------------- /predis/Connection/Aggregate/ReplicationInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Connection\Aggregate; 13 | 14 | use Predis\Connection\AggregateConnectionInterface; 15 | use Predis\Connection\NodeConnectionInterface; 16 | 17 | /** 18 | * Defines a group of Redis nodes in a master / slave replication setup. 19 | * 20 | * @author Daniele Alessandri 21 | */ 22 | interface ReplicationInterface extends AggregateConnectionInterface 23 | { 24 | /** 25 | * Switches the internal connection instance in use. 26 | * 27 | * @param string $connection Alias of a connection 28 | */ 29 | public function switchTo($connection); 30 | 31 | /** 32 | * Returns the connection instance currently in use by the aggregate 33 | * connection. 34 | * 35 | * @return NodeConnectionInterface 36 | */ 37 | public function getCurrent(); 38 | 39 | /** 40 | * Returns the connection instance for the master Redis node. 41 | * 42 | * @return NodeConnectionInterface 43 | */ 44 | public function getMaster(); 45 | 46 | /** 47 | * Returns a list of connection instances to slave nodes. 48 | * 49 | * @return NodeConnectionInterface 50 | */ 51 | public function getSlaves(); 52 | } 53 | -------------------------------------------------------------------------------- /predis/Connection/AggregateConnectionInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Connection; 13 | 14 | use Predis\Command\CommandInterface; 15 | 16 | /** 17 | * Defines a virtual connection composed of multiple connection instances to 18 | * single Redis nodes. 19 | * 20 | * @author Daniele Alessandri 21 | */ 22 | interface AggregateConnectionInterface extends ConnectionInterface 23 | { 24 | /** 25 | * Adds a connection instance to the aggregate connection. 26 | * 27 | * @param NodeConnectionInterface $connection Connection instance. 28 | */ 29 | public function add(NodeConnectionInterface $connection); 30 | 31 | /** 32 | * Removes the specified connection instance from the aggregate connection. 33 | * 34 | * @param NodeConnectionInterface $connection Connection instance. 35 | * 36 | * @return bool Returns true if the connection was in the pool. 37 | */ 38 | public function remove(NodeConnectionInterface $connection); 39 | 40 | /** 41 | * Returns the connection instance in charge for the given command. 42 | * 43 | * @param CommandInterface $command Command instance. 44 | * 45 | * @return NodeConnectionInterface 46 | */ 47 | public function getConnection(CommandInterface $command); 48 | 49 | /** 50 | * Returns a connection instance from the aggregate connection by its alias. 51 | * 52 | * @param string $connectionID Connection alias. 53 | * 54 | * @return NodeConnectionInterface|null 55 | */ 56 | public function getConnectionById($connectionID); 57 | } 58 | -------------------------------------------------------------------------------- /predis/Connection/CompositeConnectionInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Connection; 13 | 14 | /** 15 | * Defines a connection to communicate with a single Redis server that leverages 16 | * an external protocol processor to handle pluggable protocol handlers. 17 | * 18 | * @author Daniele Alessandri 19 | */ 20 | interface CompositeConnectionInterface extends NodeConnectionInterface 21 | { 22 | /** 23 | * Returns the protocol processor used by the connection. 24 | */ 25 | public function getProtocol(); 26 | 27 | /** 28 | * Writes the buffer containing over the connection. 29 | * 30 | * @param string $buffer String buffer to be sent over the connection. 31 | */ 32 | public function writeBuffer($buffer); 33 | 34 | /** 35 | * Reads the given number of bytes from the connection. 36 | * 37 | * @param int $length Number of bytes to read from the connection. 38 | * 39 | * @return string 40 | */ 41 | public function readBuffer($length); 42 | 43 | /** 44 | * Reads a line from the connection. 45 | * 46 | * @param string 47 | */ 48 | public function readLine(); 49 | } 50 | -------------------------------------------------------------------------------- /predis/Connection/ConnectionException.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Connection; 13 | 14 | use Predis\CommunicationException; 15 | 16 | /** 17 | * Exception class that identifies connection-related errors. 18 | * 19 | * @author Daniele Alessandri 20 | */ 21 | class ConnectionException extends CommunicationException 22 | { 23 | } 24 | -------------------------------------------------------------------------------- /predis/Connection/ConnectionInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Connection; 13 | 14 | use Predis\Command\CommandInterface; 15 | 16 | /** 17 | * Defines a connection object used to communicate with one or multiple 18 | * Redis servers. 19 | * 20 | * @author Daniele Alessandri 21 | */ 22 | interface ConnectionInterface 23 | { 24 | /** 25 | * Opens the connection to Redis. 26 | */ 27 | public function connect(); 28 | 29 | /** 30 | * Closes the connection to Redis. 31 | */ 32 | public function disconnect(); 33 | 34 | /** 35 | * Checks if the connection to Redis is considered open. 36 | * 37 | * @return bool 38 | */ 39 | public function isConnected(); 40 | 41 | /** 42 | * Writes the request for the given command over the connection. 43 | * 44 | * @param CommandInterface $command Command instance. 45 | */ 46 | public function writeRequest(CommandInterface $command); 47 | 48 | /** 49 | * Reads the response to the given command from the connection. 50 | * 51 | * @param CommandInterface $command Command instance. 52 | * 53 | * @return mixed 54 | */ 55 | public function readResponse(CommandInterface $command); 56 | 57 | /** 58 | * Writes a request for the given command over the connection and reads back 59 | * the response returned by Redis. 60 | * 61 | * @param CommandInterface $command Command instance. 62 | * 63 | * @return mixed 64 | */ 65 | public function executeCommand(CommandInterface $command); 66 | } 67 | -------------------------------------------------------------------------------- /predis/Connection/FactoryInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Connection; 13 | 14 | /** 15 | * Interface for classes providing a factory of connections to Redis nodes. 16 | * 17 | * @author Daniele Alessandri 18 | */ 19 | interface FactoryInterface 20 | { 21 | /** 22 | * Defines or overrides the connection class identified by a scheme prefix. 23 | * 24 | * @param string $scheme Target connection scheme. 25 | * @param mixed $initializer Fully-qualified name of a class or a callable for lazy initialization. 26 | */ 27 | public function define($scheme, $initializer); 28 | 29 | /** 30 | * Undefines the connection identified by a scheme prefix. 31 | * 32 | * @param string $scheme Target connection scheme. 33 | */ 34 | public function undefine($scheme); 35 | 36 | /** 37 | * Creates a new connection object. 38 | * 39 | * @param mixed $parameters Initialization parameters for the connection. 40 | * 41 | * @return NodeConnectionInterface 42 | */ 43 | public function create($parameters); 44 | 45 | /** 46 | * Aggregates single connections into an aggregate connection instance. 47 | * 48 | * @param AggregateConnectionInterface $aggregate Aggregate connection instance. 49 | * @param array $parameters List of parameters for each connection. 50 | */ 51 | public function aggregate(AggregateConnectionInterface $aggregate, array $parameters); 52 | } 53 | -------------------------------------------------------------------------------- /predis/Connection/NodeConnectionInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Connection; 13 | 14 | use Predis\Command\CommandInterface; 15 | 16 | /** 17 | * Defines a connection used to communicate with a single Redis node. 18 | * 19 | * @author Daniele Alessandri 20 | */ 21 | interface NodeConnectionInterface extends ConnectionInterface 22 | { 23 | /** 24 | * Returns a string representation of the connection. 25 | * 26 | * @return string 27 | */ 28 | public function __toString(); 29 | 30 | /** 31 | * Returns the underlying resource used to communicate with Redis. 32 | * 33 | * @return mixed 34 | */ 35 | public function getResource(); 36 | 37 | /** 38 | * Returns the parameters used to initialize the connection. 39 | * 40 | * @return ParametersInterface 41 | */ 42 | public function getParameters(); 43 | 44 | /** 45 | * Pushes the given command into a queue of commands executed when 46 | * establishing the actual connection to Redis. 47 | * 48 | * @param CommandInterface $command Instance of a Redis command. 49 | */ 50 | public function addConnectCommand(CommandInterface $command); 51 | 52 | /** 53 | * Reads a response from the server. 54 | * 55 | * @return mixed 56 | */ 57 | public function read(); 58 | } 59 | -------------------------------------------------------------------------------- /predis/NotSupportedException.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis; 13 | 14 | /** 15 | * Exception class thrown when trying to use features not supported by certain 16 | * classes or abstractions of Predis. 17 | * 18 | * @author Daniele Alessandri 19 | */ 20 | class NotSupportedException extends PredisException 21 | { 22 | } 23 | -------------------------------------------------------------------------------- /predis/Pipeline/FireAndForget.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Pipeline; 13 | 14 | use SplQueue; 15 | use Predis\Connection\ConnectionInterface; 16 | 17 | /** 18 | * Command pipeline that writes commands to the servers but discards responses. 19 | * 20 | * @author Daniele Alessandri 21 | */ 22 | class FireAndForget extends Pipeline 23 | { 24 | /** 25 | * {@inheritdoc} 26 | */ 27 | protected function executePipeline(ConnectionInterface $connection, SplQueue $commands) 28 | { 29 | while (!$commands->isEmpty()) { 30 | $connection->writeRequest($commands->dequeue()); 31 | } 32 | 33 | $connection->disconnect(); 34 | 35 | return array(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /predis/PredisException.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis; 13 | 14 | use Exception; 15 | 16 | /** 17 | * Base exception class for Predis-related errors. 18 | * 19 | * @author Daniele Alessandri 20 | */ 21 | abstract class PredisException extends Exception 22 | { 23 | } 24 | -------------------------------------------------------------------------------- /predis/Profile/ProfileInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Profile; 13 | 14 | use Predis\Command\CommandInterface; 15 | 16 | /** 17 | * A profile defines all the features and commands supported by certain versions 18 | * of Redis. Instances of Predis\Client should use a server profile matching the 19 | * version of Redis being used. 20 | * 21 | * @author Daniele Alessandri 22 | */ 23 | interface ProfileInterface 24 | { 25 | /** 26 | * Returns the profile version corresponding to the Redis version. 27 | * 28 | * @return string 29 | */ 30 | public function getVersion(); 31 | 32 | /** 33 | * Checks if the profile supports the specified command. 34 | * 35 | * @param string $commandID Command ID. 36 | * 37 | * @return bool 38 | */ 39 | public function supportsCommand($commandID); 40 | 41 | /** 42 | * Checks if the profile supports the specified list of commands. 43 | * 44 | * @param array $commandIDs List of command IDs. 45 | * 46 | * @return string 47 | */ 48 | public function supportsCommands(array $commandIDs); 49 | 50 | /** 51 | * Creates a new command instance. 52 | * 53 | * @param string $commandID Command ID. 54 | * @param array $arguments Arguments for the command. 55 | * 56 | * @return CommandInterface 57 | */ 58 | public function createCommand($commandID, array $arguments = array()); 59 | } 60 | -------------------------------------------------------------------------------- /predis/Profile/RedisUnstable.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Profile; 13 | 14 | /** 15 | * Server profile for the current unstable version of Redis. 16 | * 17 | * @author Daniele Alessandri 18 | */ 19 | class RedisUnstable extends RedisVersion300 20 | { 21 | /** 22 | * {@inheritdoc} 23 | */ 24 | public function getVersion() 25 | { 26 | return '3.0'; 27 | } 28 | 29 | /** 30 | * {@inheritdoc} 31 | */ 32 | public function getSupportedCommands() 33 | { 34 | return array_merge(parent::getSupportedCommands(), array()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /predis/Protocol/ProtocolException.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Protocol; 13 | 14 | use Predis\CommunicationException; 15 | 16 | /** 17 | * Exception used to indentify errors encountered while parsing the Redis wire 18 | * protocol. 19 | * 20 | * @author Daniele Alessandri 21 | */ 22 | class ProtocolException extends CommunicationException 23 | { 24 | } 25 | -------------------------------------------------------------------------------- /predis/Protocol/ProtocolProcessorInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Protocol; 13 | 14 | use Predis\Command\CommandInterface; 15 | use Predis\Connection\CompositeConnectionInterface; 16 | 17 | /** 18 | * Defines a pluggable protocol processor capable of serializing commands and 19 | * deserializing responses into PHP objects directly from a connection. 20 | * 21 | * @author Daniele Alessandri 22 | */ 23 | interface ProtocolProcessorInterface 24 | { 25 | /** 26 | * Writes a request over a connection to Redis. 27 | * 28 | * @param CompositeConnectionInterface $connection Redis connection. 29 | * @param CommandInterface $command Command instance. 30 | */ 31 | public function write(CompositeConnectionInterface $connection, CommandInterface $command); 32 | 33 | /** 34 | * Reads a response from a connection to Redis. 35 | * 36 | * @param CompositeConnectionInterface $connection Redis connection. 37 | * 38 | * @return mixed 39 | */ 40 | public function read(CompositeConnectionInterface $connection); 41 | } 42 | -------------------------------------------------------------------------------- /predis/Protocol/RequestSerializerInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Protocol; 13 | 14 | use Predis\Command\CommandInterface; 15 | 16 | /** 17 | * Defines a pluggable serializer for Redis commands. 18 | * 19 | * @author Daniele Alessandri 20 | */ 21 | interface RequestSerializerInterface 22 | { 23 | /** 24 | * Serializes a Redis command. 25 | * 26 | * @param CommandInterface $command Redis command. 27 | * 28 | * @return string 29 | */ 30 | public function serialize(CommandInterface $command); 31 | } 32 | -------------------------------------------------------------------------------- /predis/Protocol/ResponseReaderInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Protocol; 13 | 14 | use Predis\Connection\CompositeConnectionInterface; 15 | 16 | /** 17 | * Defines a pluggable reader capable of parsing responses returned by Redis and 18 | * deserializing them to PHP objects. 19 | * 20 | * @author Daniele Alessandri 21 | */ 22 | interface ResponseReaderInterface 23 | { 24 | /** 25 | * Reads a response from a connection to Redis. 26 | * 27 | * @param CompositeConnectionInterface $connection Redis connection. 28 | * 29 | * @return mixed 30 | */ 31 | public function read(CompositeConnectionInterface $connection); 32 | } 33 | -------------------------------------------------------------------------------- /predis/Protocol/Text/Handler/BulkResponse.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Protocol\Text\Handler; 13 | 14 | use Predis\CommunicationException; 15 | use Predis\Connection\CompositeConnectionInterface; 16 | use Predis\Protocol\ProtocolException; 17 | 18 | /** 19 | * Handler for the bulk response type in the standard Redis wire protocol. 20 | * It translates the payload to a string or a NULL. 21 | * 22 | * @link http://redis.io/topics/protocol 23 | * @author Daniele Alessandri 24 | */ 25 | class BulkResponse implements ResponseHandlerInterface 26 | { 27 | /** 28 | * {@inheritdoc} 29 | */ 30 | public function handle(CompositeConnectionInterface $connection, $payload) 31 | { 32 | $length = (int) $payload; 33 | 34 | if ("$length" !== $payload) { 35 | CommunicationException::handle(new ProtocolException( 36 | $connection, "Cannot parse '$payload' as a valid length for a bulk response." 37 | )); 38 | } 39 | 40 | if ($length >= 0) { 41 | return substr($connection->readBuffer($length + 2), 0, -2); 42 | } 43 | 44 | if ($length == -1) { 45 | return null; 46 | } 47 | 48 | CommunicationException::handle(new ProtocolException( 49 | $connection, "Value '$payload' is not a valid length for a bulk response." 50 | )); 51 | 52 | return; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /predis/Protocol/Text/Handler/ErrorResponse.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Protocol\Text\Handler; 13 | 14 | use Predis\Connection\CompositeConnectionInterface; 15 | use Predis\Response\Error; 16 | 17 | /** 18 | * Handler for the error response type in the standard Redis wire protocol. 19 | * It translates the payload to a complex response object for Predis. 20 | * 21 | * @link http://redis.io/topics/protocol 22 | * @author Daniele Alessandri 23 | */ 24 | class ErrorResponse implements ResponseHandlerInterface 25 | { 26 | /** 27 | * {@inheritdoc} 28 | */ 29 | public function handle(CompositeConnectionInterface $connection, $payload) 30 | { 31 | return new Error($payload); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /predis/Protocol/Text/Handler/IntegerResponse.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Protocol\Text\Handler; 13 | 14 | use Predis\CommunicationException; 15 | use Predis\Connection\CompositeConnectionInterface; 16 | use Predis\Protocol\ProtocolException; 17 | 18 | /** 19 | * Handler for the integer response type in the standard Redis wire protocol. 20 | * It translates the payload an integer or NULL. 21 | * 22 | * @link http://redis.io/topics/protocol 23 | * @author Daniele Alessandri 24 | */ 25 | class IntegerResponse implements ResponseHandlerInterface 26 | { 27 | /** 28 | * {@inheritdoc} 29 | */ 30 | public function handle(CompositeConnectionInterface $connection, $payload) 31 | { 32 | if (is_numeric($payload)) { 33 | return (int) $payload; 34 | } 35 | 36 | if ($payload !== 'nil') { 37 | CommunicationException::handle(new ProtocolException( 38 | $connection, "Cannot parse '$payload' as a valid numeric response." 39 | )); 40 | } 41 | 42 | return null; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /predis/Protocol/Text/Handler/MultiBulkResponse.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Protocol\Text\Handler; 13 | 14 | use Predis\CommunicationException; 15 | use Predis\Connection\CompositeConnectionInterface; 16 | use Predis\Protocol\ProtocolException; 17 | 18 | /** 19 | * Handler for the multibulk response type in the standard Redis wire protocol. 20 | * It returns multibulk responses as PHP arrays. 21 | * 22 | * @link http://redis.io/topics/protocol 23 | * @author Daniele Alessandri 24 | */ 25 | class MultiBulkResponse implements ResponseHandlerInterface 26 | { 27 | /** 28 | * {@inheritdoc} 29 | */ 30 | public function handle(CompositeConnectionInterface $connection, $payload) 31 | { 32 | $length = (int) $payload; 33 | 34 | if ("$length" !== $payload) { 35 | CommunicationException::handle(new ProtocolException( 36 | $connection, "Cannot parse '$payload' as a valid length of a multi-bulk response." 37 | )); 38 | } 39 | 40 | if ($length === -1) { 41 | return null; 42 | } 43 | 44 | $list = array(); 45 | 46 | if ($length > 0) { 47 | $handlersCache = array(); 48 | $reader = $connection->getProtocol()->getResponseReader(); 49 | 50 | for ($i = 0; $i < $length; $i++) { 51 | $header = $connection->readLine(); 52 | $prefix = $header[0]; 53 | 54 | if (isset($handlersCache[$prefix])) { 55 | $handler = $handlersCache[$prefix]; 56 | } else { 57 | $handler = $reader->getHandler($prefix); 58 | $handlersCache[$prefix] = $handler; 59 | } 60 | 61 | $list[$i] = $handler->handle($connection, substr($header, 1)); 62 | } 63 | } 64 | 65 | return $list; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /predis/Protocol/Text/Handler/ResponseHandlerInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Protocol\Text\Handler; 13 | 14 | use Predis\Connection\CompositeConnectionInterface; 15 | 16 | /** 17 | * Defines a pluggable handler used to parse a particular type of response. 18 | * 19 | * @author Daniele Alessandri 20 | */ 21 | interface ResponseHandlerInterface 22 | { 23 | /** 24 | * Deserializes a response returned by Redis and reads more data from the 25 | * connection if needed. 26 | * 27 | * @param CompositeConnectionInterface $connection Redis connection. 28 | * @param string $payload String payload. 29 | * 30 | * @return mixed 31 | */ 32 | public function handle(CompositeConnectionInterface $connection, $payload); 33 | } 34 | -------------------------------------------------------------------------------- /predis/Protocol/Text/Handler/StatusResponse.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Protocol\Text\Handler; 13 | 14 | use Predis\Connection\CompositeConnectionInterface; 15 | use Predis\Response\Status; 16 | 17 | /** 18 | * Handler for the status response type in the standard Redis wire protocol. It 19 | * translates certain classes of status response to PHP objects or just returns 20 | * the payload as a string. 21 | * 22 | * @link http://redis.io/topics/protocol 23 | * @author Daniele Alessandri 24 | */ 25 | class StatusResponse implements ResponseHandlerInterface 26 | { 27 | /** 28 | * {@inheritdoc} 29 | */ 30 | public function handle(CompositeConnectionInterface $connection, $payload) 31 | { 32 | return Status::get($payload); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /predis/Protocol/Text/Handler/StreamableMultiBulkResponse.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Protocol\Text\Handler; 13 | 14 | use Predis\CommunicationException; 15 | use Predis\Connection\CompositeConnectionInterface; 16 | use Predis\Response\Iterator\MultiBulk as MultiBulkIterator; 17 | use Predis\Protocol\ProtocolException; 18 | 19 | /** 20 | * Handler for the multibulk response type in the standard Redis wire protocol. 21 | * It returns multibulk responses as iterators that can stream bulk elements. 22 | * 23 | * Streamable multibulk responses are not globally supported by the abstractions 24 | * built-in into Predis, such as transactions or pipelines. Use them with care! 25 | * 26 | * @link http://redis.io/topics/protocol 27 | * @author Daniele Alessandri 28 | */ 29 | class StreamableMultiBulkResponse implements ResponseHandlerInterface 30 | { 31 | /** 32 | * {@inheritdoc} 33 | */ 34 | public function handle(CompositeConnectionInterface $connection, $payload) 35 | { 36 | $length = (int) $payload; 37 | 38 | if ("$length" != $payload) { 39 | CommunicationException::handle(new ProtocolException( 40 | $connection, "Cannot parse '$payload' as a valid length for a multi-bulk response." 41 | )); 42 | } 43 | 44 | return new MultiBulkIterator($connection, $length); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /predis/Protocol/Text/RequestSerializer.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Protocol\Text; 13 | 14 | use Predis\Command\CommandInterface; 15 | use Predis\Protocol\RequestSerializerInterface; 16 | 17 | /** 18 | * Request serializer for the standard Redis wire protocol. 19 | * 20 | * @link http://redis.io/topics/protocol 21 | * @author Daniele Alessandri 22 | */ 23 | class RequestSerializer implements RequestSerializerInterface 24 | { 25 | /** 26 | * {@inheritdoc} 27 | */ 28 | public function serialize(CommandInterface $command) 29 | { 30 | $commandID = $command->getId(); 31 | $arguments = $command->getArguments(); 32 | 33 | $cmdlen = strlen($commandID); 34 | $reqlen = count($arguments) + 1; 35 | 36 | $buffer = "*{$reqlen}\r\n\${$cmdlen}\r\n{$commandID}\r\n"; 37 | 38 | for ($i = 0, $reqlen--; $i < $reqlen; $i++) { 39 | $argument = $arguments[$i]; 40 | $arglen = strlen($argument); 41 | $buffer .= "\${$arglen}\r\n{$argument}\r\n"; 42 | } 43 | 44 | return $buffer; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /predis/Response/Error.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Response; 13 | 14 | /** 15 | * Represents an error returned by Redis (-ERR responses) during the execution 16 | * of a command on the server. 17 | * 18 | * @author Daniele Alessandri 19 | */ 20 | class Error implements ErrorInterface 21 | { 22 | private $message; 23 | 24 | /** 25 | * @param string $message Error message returned by Redis 26 | */ 27 | public function __construct($message) 28 | { 29 | $this->message = $message; 30 | } 31 | 32 | /** 33 | * {@inheritdoc} 34 | */ 35 | public function getMessage() 36 | { 37 | return $this->message; 38 | } 39 | 40 | /** 41 | * {@inheritdoc} 42 | */ 43 | public function getErrorType() 44 | { 45 | list($errorType, ) = explode(' ', $this->getMessage(), 2); 46 | 47 | return $errorType; 48 | } 49 | 50 | /** 51 | * Converts the object to its string representation. 52 | * 53 | * @return string 54 | */ 55 | public function __toString() 56 | { 57 | return $this->getMessage(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /predis/Response/ErrorInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Response; 13 | 14 | /** 15 | * Represents an error returned by Redis (responses identified by "-" in the 16 | * Redis protocol) during the execution of an operation on the server. 17 | * 18 | * @author Daniele Alessandri 19 | */ 20 | interface ErrorInterface extends ResponseInterface 21 | { 22 | /** 23 | * Returns the error message 24 | * 25 | * @return string 26 | */ 27 | public function getMessage(); 28 | 29 | /** 30 | * Returns the error type (e.g. ERR, ASK, MOVED) 31 | * 32 | * @return string 33 | */ 34 | public function getErrorType(); 35 | } 36 | -------------------------------------------------------------------------------- /predis/Response/ResponseInterface.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Response; 13 | 14 | /** 15 | * Represents a complex response object from Redis. 16 | * 17 | * @author Daniele Alessandri 18 | */ 19 | interface ResponseInterface 20 | { 21 | } 22 | -------------------------------------------------------------------------------- /predis/Response/ServerException.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Response; 13 | 14 | use Predis\PredisException; 15 | 16 | /** 17 | * Exception class that identifies server-side Redis errors. 18 | * 19 | * @author Daniele Alessandri 20 | */ 21 | class ServerException extends PredisException implements ErrorInterface 22 | { 23 | /** 24 | * Gets the type of the error returned by Redis. 25 | * 26 | * @return string 27 | */ 28 | public function getErrorType() 29 | { 30 | list($errorType, ) = explode(' ', $this->getMessage(), 2); 31 | 32 | return $errorType; 33 | } 34 | 35 | /** 36 | * Converts the exception to an instance of Predis\Response\Error. 37 | * 38 | * @return Error 39 | */ 40 | public function toErrorResponse() 41 | { 42 | return new Error($this->getMessage()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /predis/Response/Status.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Response; 13 | 14 | /** 15 | * Represents a status response returned by Redis. 16 | * 17 | * @author Daniele Alessandri 18 | */ 19 | class Status implements ResponseInterface 20 | { 21 | private static $OK; 22 | private static $QUEUED; 23 | 24 | private $payload; 25 | 26 | /** 27 | * @param string $payload Payload of the status response as returned by Redis. 28 | */ 29 | public function __construct($payload) 30 | { 31 | $this->payload = $payload; 32 | } 33 | 34 | /** 35 | * Converts the response object to its string representation. 36 | * 37 | * @return string 38 | */ 39 | public function __toString() 40 | { 41 | return $this->payload; 42 | } 43 | 44 | /** 45 | * Returns the payload of status response. 46 | * 47 | * @return string 48 | */ 49 | public function getPayload() 50 | { 51 | return $this->payload; 52 | } 53 | 54 | /** 55 | * Returns an instance of a status response object. 56 | * 57 | * Common status responses such as OK or QUEUED are cached in order to lower 58 | * the global memory usage especially when using pipelines. 59 | * 60 | * @param string $payload Status response payload. 61 | * 62 | * @return string 63 | */ 64 | public static function get($payload) 65 | { 66 | switch ($payload) { 67 | case 'OK': 68 | case 'QUEUED': 69 | if (isset(self::$$payload)) { 70 | return self::$$payload; 71 | } 72 | 73 | return self::$$payload = new self($payload); 74 | 75 | default: 76 | return new self($payload); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /predis/Transaction/AbortedMultiExecException.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace Predis\Transaction; 13 | 14 | use Predis\PredisException; 15 | 16 | /** 17 | * Exception class that identifies a MULTI / EXEC transaction aborted by Redis. 18 | * 19 | * @author Daniele Alessandri 20 | */ 21 | class AbortedMultiExecException extends PredisException 22 | { 23 | private $transaction; 24 | 25 | /** 26 | * @param MultiExec $transaction Transaction that generated the exception. 27 | * @param string $message Error message. 28 | * @param int $code Error code. 29 | */ 30 | public function __construct(MultiExec $transaction, $message, $code = null) 31 | { 32 | parent::__construct($message, $code); 33 | $this->transaction = $transaction; 34 | } 35 | 36 | /** 37 | * Returns the transaction that generated the exception. 38 | * 39 | * @return MultiExec 40 | */ 41 | public function getTransaction() 42 | { 43 | return $this->transaction; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /settings.tpl: -------------------------------------------------------------------------------- 1 | {$message} 2 | 3 | 4 | Settings Redis Cache 5 | 6 | {l s='Please fill in the details about your redis server' mod='hsrediscache'} 7 | 8 | Serveur: 9 | 10 | 11 | 12 | Port: 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | {l s='NB : Please check if Redis server is correctly installed on your server' mod='hsrediscache'} {l s='( Redis Server website ) ' mod='hsrediscache'} 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /translations/fr.php: -------------------------------------------------------------------------------- 1 |
{l s='Please fill in the details about your redis server' mod='hsrediscache'}
8 | Serveur: 9 | 10 |
12 | Port: 13 | 14 |
16 | 17 | 18 |
21 | 22 | {l s='NB : Please check if Redis server is correctly installed on your server' mod='hsrediscache'} {l s='( Redis Server website ) ' mod='hsrediscache'} 23 |