From 84ffe1e5526fd091de1c4e065a7a55aaaf439feb Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Tue, 2 Apr 2024 20:15:23 +0200 Subject: [PATCH] Predis to v2.2.2 --- plugins/cache-redis/Predis/Client.php | 353 ++++++----- .../Predis/ClientContextInterface.php | 235 +++++++- .../cache-redis/Predis/ClientException.php | 5 +- .../cache-redis/Predis/ClientInterface.php | 491 +++++++++++----- .../Predis/Cluster/ClusterStrategy.php | 181 ++++-- .../Distributor/DistributorInterface.php | 5 +- .../Distributor/EmptyRingException.php | 9 +- .../Predis/Cluster/Distributor/HashRing.php | 22 +- .../Predis/Cluster/Distributor/KetamaRing.php | 7 +- .../cache-redis/Predis/Cluster/Hash/CRC16.php | 11 +- .../Cluster/Hash/HashGeneratorInterface.php | 5 +- .../Predis/Cluster/PredisStrategy.php | 8 +- .../Predis/Cluster/RedisStrategy.php | 13 +- .../Predis/Cluster/StrategyInterface.php | 9 +- .../Iterator/CursorBasedIterator.php | 39 +- .../Predis/Collection/Iterator/HashKey.php | 11 +- .../Predis/Collection/Iterator/Keyspace.php | 7 +- .../Predis/Collection/Iterator/ListKey.php | 37 +- .../Predis/Collection/Iterator/SetKey.php | 7 +- .../Collection/Iterator/SortedSetKey.php | 15 +- .../cache-redis/Predis/Command/Command.php | 41 +- .../Predis/Command/CommandInterface.php | 7 +- .../Predis/Command/ConnectionAuth.php | 28 - .../Predis/Command/ConnectionEcho.php | 28 - .../Predis/Command/ConnectionPing.php | 28 - .../Predis/Command/ConnectionQuit.php | 28 - .../Predis/Command/ConnectionSelect.php | 28 - .../cache-redis/Predis/Command/HashDelete.php | 36 -- .../cache-redis/Predis/Command/HashExists.php | 36 -- .../cache-redis/Predis/Command/HashGet.php | 28 - .../cache-redis/Predis/Command/HashGetAll.php | 42 -- .../Predis/Command/HashGetMultiple.php | 36 -- .../Predis/Command/HashIncrementBy.php | 28 - .../Predis/Command/HashIncrementByFloat.php | 28 - .../cache-redis/Predis/Command/HashKeys.php | 28 - .../cache-redis/Predis/Command/HashLength.php | 28 - .../cache-redis/Predis/Command/HashScan.php | 85 --- .../cache-redis/Predis/Command/HashSet.php | 36 -- .../Predis/Command/HashSetMultiple.php | 48 -- .../Predis/Command/HashSetPreserve.php | 36 -- .../Predis/Command/HashStringLength.php | 28 - .../cache-redis/Predis/Command/HashValues.php | 28 - .../Predis/Command/HyperLogLogAdd.php | 44 -- .../Predis/Command/HyperLogLogCount.php | 36 -- .../Predis/Command/HyperLogLogMerge.php | 36 -- .../cache-redis/Predis/Command/KeyDelete.php | 36 -- .../cache-redis/Predis/Command/KeyDump.php | 28 - .../cache-redis/Predis/Command/KeyExists.php | 36 -- .../cache-redis/Predis/Command/KeyExpire.php | 36 -- .../Predis/Command/KeyExpireAt.php | 36 -- .../cache-redis/Predis/Command/KeyKeys.php | 28 - .../cache-redis/Predis/Command/KeyMigrate.php | 50 -- .../cache-redis/Predis/Command/KeyMove.php | 36 -- .../cache-redis/Predis/Command/KeyPersist.php | 36 -- .../Predis/Command/KeyPreciseExpire.php | 28 - .../Predis/Command/KeyPreciseExpireAt.php | 28 - .../Predis/Command/KeyPreciseTimeToLive.php | 28 - .../cache-redis/Predis/Command/KeyRandom.php | 36 -- .../cache-redis/Predis/Command/KeyRename.php | 28 - .../Predis/Command/KeyRenamePreserve.php | 36 -- .../cache-redis/Predis/Command/KeyRestore.php | 28 - .../cache-redis/Predis/Command/KeyScan.php | 66 --- .../cache-redis/Predis/Command/KeySort.php | 83 --- .../Predis/Command/KeyTimeToLive.php | 28 - .../cache-redis/Predis/Command/KeyType.php | 28 - .../cache-redis/Predis/Command/ListIndex.php | 28 - .../cache-redis/Predis/Command/ListInsert.php | 28 - .../cache-redis/Predis/Command/ListLength.php | 28 - .../Predis/Command/ListPopFirst.php | 28 - .../Predis/Command/ListPopFirstBlocking.php | 41 -- .../Predis/Command/ListPopLast.php | 28 - .../Predis/Command/ListPopLastBlocking.php | 28 - .../Predis/Command/ListPopLastPushHead.php | 28 - .../Command/ListPopLastPushHeadBlocking.php | 28 - .../Predis/Command/ListPushHead.php | 28 - .../Predis/Command/ListPushHeadX.php | 28 - .../Predis/Command/ListPushTail.php | 36 -- .../Predis/Command/ListPushTailX.php | 28 - .../cache-redis/Predis/Command/ListRange.php | 28 - .../cache-redis/Predis/Command/ListRemove.php | 28 - .../cache-redis/Predis/Command/ListSet.php | 28 - .../cache-redis/Predis/Command/ListTrim.php | 28 - .../Command/PrefixableCommandInterface.php | 5 +- .../Command/Processor/KeyPrefixProcessor.php | 424 +++++++++----- .../Command/Processor/ProcessorChain.php | 42 +- .../Command/Processor/ProcessorInterface.php | 5 +- .../Predis/Command/PubSubPublish.php | 28 - .../Predis/Command/PubSubPubsub.php | 61 -- .../Predis/Command/PubSubSubscribe.php | 36 -- .../Command/PubSubSubscribeByPattern.php | 28 - .../Predis/Command/PubSubUnsubscribe.php | 36 -- .../Command/PubSubUnsubscribeByPattern.php | 28 - .../cache-redis/Predis/Command/RawCommand.php | 48 +- .../Predis/Command/ScriptCommand.php | 45 +- .../Command/ServerBackgroundRewriteAOF.php | 36 -- .../Predis/Command/ServerBackgroundSave.php | 36 -- .../Predis/Command/ServerClient.php | 74 --- .../Predis/Command/ServerCommand.php | 28 - .../Predis/Command/ServerConfig.php | 49 -- .../Predis/Command/ServerDatabaseSize.php | 28 - .../cache-redis/Predis/Command/ServerEval.php | 38 -- .../Predis/Command/ServerEvalSHA.php | 38 -- .../Predis/Command/ServerFlushAll.php | 28 - .../Predis/Command/ServerFlushDatabase.php | 28 - .../cache-redis/Predis/Command/ServerInfo.php | 111 ---- .../Predis/Command/ServerInfoV26x.php | 56 -- .../Predis/Command/ServerLastSave.php | 28 - .../Predis/Command/ServerMonitor.php | 28 - .../Predis/Command/ServerObject.php | 28 - .../cache-redis/Predis/Command/ServerSave.php | 28 - .../Predis/Command/ServerScript.php | 28 - .../Predis/Command/ServerSentinel.php | 66 --- .../Predis/Command/ServerShutdown.php | 28 - .../Predis/Command/ServerSlaveOf.php | 40 -- .../Predis/Command/ServerSlowlog.php | 51 -- .../cache-redis/Predis/Command/ServerTime.php | 28 - plugins/cache-redis/Predis/Command/SetAdd.php | 36 -- .../Predis/Command/SetCardinality.php | 28 - .../Predis/Command/SetDifference.php | 28 - .../Predis/Command/SetDifferenceStore.php | 28 - .../Predis/Command/SetIntersection.php | 36 -- .../Predis/Command/SetIntersectionStore.php | 40 -- .../Predis/Command/SetIsMember.php | 36 -- .../cache-redis/Predis/Command/SetMembers.php | 28 - .../cache-redis/Predis/Command/SetMove.php | 36 -- plugins/cache-redis/Predis/Command/SetPop.php | 28 - .../Predis/Command/SetRandomMember.php | 28 - .../cache-redis/Predis/Command/SetRemove.php | 36 -- .../cache-redis/Predis/Command/SetScan.php | 66 --- .../cache-redis/Predis/Command/SetUnion.php | 28 - .../Predis/Command/SetUnionStore.php | 28 - .../Predis/Command/StringAppend.php | 28 - .../Predis/Command/StringBitCount.php | 28 - .../Predis/Command/StringBitOp.php | 42 -- .../Predis/Command/StringBitPos.php | 28 - .../Predis/Command/StringDecrement.php | 28 - .../Predis/Command/StringDecrementBy.php | 28 - .../cache-redis/Predis/Command/StringGet.php | 28 - .../Predis/Command/StringGetBit.php | 28 - .../Predis/Command/StringGetMultiple.php | 36 -- .../Predis/Command/StringGetRange.php | 28 - .../Predis/Command/StringGetSet.php | 28 - .../Predis/Command/StringIncrement.php | 28 - .../Predis/Command/StringIncrementBy.php | 28 - .../Predis/Command/StringIncrementByFloat.php | 28 - .../Predis/Command/StringPreciseSetExpire.php | 28 - .../cache-redis/Predis/Command/StringSet.php | 28 - .../Predis/Command/StringSetBit.php | 28 - .../Predis/Command/StringSetExpire.php | 28 - .../Predis/Command/StringSetMultiple.php | 48 -- .../Command/StringSetMultiplePreserve.php | 36 -- .../Predis/Command/StringSetPreserve.php | 36 -- .../Predis/Command/StringSetRange.php | 28 - .../Predis/Command/StringStrlen.php | 28 - .../Predis/Command/StringSubstr.php | 28 - .../Predis/Command/TransactionDiscard.php | 28 - .../Predis/Command/TransactionExec.php | 28 - .../Predis/Command/TransactionMulti.php | 28 - .../Predis/Command/TransactionUnwatch.php | 28 - .../Predis/Command/TransactionWatch.php | 40 -- .../cache-redis/Predis/Command/ZSetAdd.php | 43 -- .../Predis/Command/ZSetCardinality.php | 28 - .../cache-redis/Predis/Command/ZSetCount.php | 28 - .../Predis/Command/ZSetIncrementBy.php | 28 - .../Predis/Command/ZSetIntersectionStore.php | 28 - .../Predis/Command/ZSetLexCount.php | 28 - .../cache-redis/Predis/Command/ZSetRange.php | 105 ---- .../Predis/Command/ZSetRangeByLex.php | 55 -- .../Predis/Command/ZSetRangeByScore.php | 68 --- .../cache-redis/Predis/Command/ZSetRank.php | 28 - .../cache-redis/Predis/Command/ZSetRemove.php | 36 -- .../Predis/Command/ZSetRemoveRangeByLex.php | 28 - .../Predis/Command/ZSetRemoveRangeByRank.php | 28 - .../Predis/Command/ZSetRemoveRangeByScore.php | 28 - .../Predis/Command/ZSetReverseRange.php | 28 - .../Predis/Command/ZSetReverseRangeByLex.php | 23 - .../Command/ZSetReverseRangeByScore.php | 28 - .../Predis/Command/ZSetReverseRank.php | 28 - .../cache-redis/Predis/Command/ZSetScan.php | 85 --- .../cache-redis/Predis/Command/ZSetScore.php | 28 - .../Predis/Command/ZSetUnionStore.php | 78 --- .../Predis/CommunicationException.php | 21 +- .../Predis/Configuration/ClusterOption.php | 76 --- .../Configuration/ConnectionFactoryOption.php | 54 -- .../Predis/Configuration/ExceptionsOption.php | 37 -- .../Predis/Configuration/OptionInterface.php | 5 +- .../Predis/Configuration/Options.php | 72 ++- .../Predis/Configuration/OptionsInterface.php | 31 +- .../Predis/Configuration/PrefixOption.php | 44 -- .../Predis/Configuration/ProfileOption.php | 69 --- .../Configuration/ReplicationOption.php | 61 -- .../Predis/Connection/AbstractConnection.php | 70 +-- .../Connection/Aggregate/ClusterInterface.php | 24 - .../Aggregate/MasterSlaveReplication.php | 264 --------- .../Connection/Aggregate/PredisCluster.php | 235 -------- .../Connection/Aggregate/RedisCluster.php | 553 ------------------ .../Aggregate/ReplicationInterface.php | 52 -- .../AggregateConnectionInterface.php | 7 +- .../CompositeConnectionInterface.php | 9 +- .../Connection/CompositeStreamConnection.php | 10 +- .../Predis/Connection/ConnectionException.php | 5 +- .../Predis/Connection/ConnectionInterface.php | 5 +- .../cache-redis/Predis/Connection/Factory.php | 87 ++- .../Predis/Connection/FactoryInterface.php | 13 +- .../Connection/NodeConnectionInterface.php | 5 +- .../Predis/Connection/Parameters.php | 89 +-- .../Predis/Connection/ParametersInterface.php | 40 +- .../Connection/PhpiredisSocketConnection.php | 79 ++- .../Connection/PhpiredisStreamConnection.php | 96 ++- .../Predis/Connection/StreamConnection.php | 188 ++++-- .../Predis/Connection/WebdisConnection.php | 69 ++- .../cache-redis/Predis/Monitor/Consumer.php | 40 +- .../Predis/NotSupportedException.php | 5 +- .../cache-redis/Predis/Pipeline/Atomic.php | 23 +- .../Predis/Pipeline/ConnectionErrorProof.php | 26 +- .../Predis/Pipeline/FireAndForget.php | 10 +- .../cache-redis/Predis/Pipeline/Pipeline.php | 35 +- .../cache-redis/Predis/PredisException.php | 9 +- .../cache-redis/Predis/Profile/Factory.php | 100 ---- .../Predis/Profile/ProfileInterface.php | 59 -- .../Predis/Profile/RedisProfile.php | 146 ----- .../Predis/Profile/RedisUnstable.php | 41 -- .../Predis/Profile/RedisVersion200.php | 173 ------ .../Predis/Profile/RedisVersion220.php | 202 ------- .../Predis/Profile/RedisVersion240.php | 207 ------- .../Predis/Profile/RedisVersion260.php | 235 -------- .../Predis/Profile/RedisVersion280.php | 267 --------- .../Predis/Profile/RedisVersion300.php | 270 --------- .../Predis/Protocol/ProtocolException.php | 7 +- .../Protocol/ProtocolProcessorInterface.php | 5 +- .../Protocol/RequestSerializerInterface.php | 5 +- .../Protocol/ResponseReaderInterface.php | 5 +- .../Text/CompositeProtocolProcessor.php | 7 +- .../Protocol/Text/Handler/BulkResponse.php | 11 +- .../Protocol/Text/Handler/ErrorResponse.php | 7 +- .../Protocol/Text/Handler/IntegerResponse.php | 13 +- .../Text/Handler/MultiBulkResponse.php | 13 +- .../Text/Handler/ResponseHandlerInterface.php | 5 +- .../Protocol/Text/Handler/StatusResponse.php | 7 +- .../Handler/StreamableMultiBulkResponse.php | 9 +- .../Protocol/Text/ProtocolProcessor.php | 18 +- .../Protocol/Text/RequestSerializer.php | 10 +- .../Predis/Protocol/Text/ResponseReader.php | 24 +- .../Predis/PubSub/AbstractConsumer.php | 63 +- .../cache-redis/Predis/PubSub/Consumer.php | 41 +- .../Predis/PubSub/DispatcherLoop.php | 25 +- .../Replication/ReplicationStrategy.php | 93 ++- plugins/cache-redis/Predis/Response/Error.php | 7 +- .../Predis/Response/ErrorInterface.php | 5 +- .../Predis/Response/Iterator/MultiBulk.php | 5 +- .../Response/Iterator/MultiBulkIterator.php | 26 +- .../Response/Iterator/MultiBulkTuple.php | 27 +- .../Predis/Response/ResponseInterface.php | 5 +- .../Predis/Response/ServerException.php | 7 +- .../cache-redis/Predis/Response/Status.php | 7 +- .../cache-redis/Predis/Session/Handler.php | 37 +- .../Transaction/AbortedMultiExecException.php | 10 +- .../Predis/Transaction/MultiExec.php | 105 ++-- .../Predis/Transaction/MultiExecState.php | 18 +- 259 files changed, 2407 insertions(+), 9937 deletions(-) delete mode 100644 plugins/cache-redis/Predis/Command/ConnectionAuth.php delete mode 100644 plugins/cache-redis/Predis/Command/ConnectionEcho.php delete mode 100644 plugins/cache-redis/Predis/Command/ConnectionPing.php delete mode 100644 plugins/cache-redis/Predis/Command/ConnectionQuit.php delete mode 100644 plugins/cache-redis/Predis/Command/ConnectionSelect.php delete mode 100644 plugins/cache-redis/Predis/Command/HashDelete.php delete mode 100644 plugins/cache-redis/Predis/Command/HashExists.php delete mode 100644 plugins/cache-redis/Predis/Command/HashGet.php delete mode 100644 plugins/cache-redis/Predis/Command/HashGetAll.php delete mode 100644 plugins/cache-redis/Predis/Command/HashGetMultiple.php delete mode 100644 plugins/cache-redis/Predis/Command/HashIncrementBy.php delete mode 100644 plugins/cache-redis/Predis/Command/HashIncrementByFloat.php delete mode 100644 plugins/cache-redis/Predis/Command/HashKeys.php delete mode 100644 plugins/cache-redis/Predis/Command/HashLength.php delete mode 100644 plugins/cache-redis/Predis/Command/HashScan.php delete mode 100644 plugins/cache-redis/Predis/Command/HashSet.php delete mode 100644 plugins/cache-redis/Predis/Command/HashSetMultiple.php delete mode 100644 plugins/cache-redis/Predis/Command/HashSetPreserve.php delete mode 100644 plugins/cache-redis/Predis/Command/HashStringLength.php delete mode 100644 plugins/cache-redis/Predis/Command/HashValues.php delete mode 100644 plugins/cache-redis/Predis/Command/HyperLogLogAdd.php delete mode 100644 plugins/cache-redis/Predis/Command/HyperLogLogCount.php delete mode 100644 plugins/cache-redis/Predis/Command/HyperLogLogMerge.php delete mode 100644 plugins/cache-redis/Predis/Command/KeyDelete.php delete mode 100644 plugins/cache-redis/Predis/Command/KeyDump.php delete mode 100644 plugins/cache-redis/Predis/Command/KeyExists.php delete mode 100644 plugins/cache-redis/Predis/Command/KeyExpire.php delete mode 100644 plugins/cache-redis/Predis/Command/KeyExpireAt.php delete mode 100644 plugins/cache-redis/Predis/Command/KeyKeys.php delete mode 100644 plugins/cache-redis/Predis/Command/KeyMigrate.php delete mode 100644 plugins/cache-redis/Predis/Command/KeyMove.php delete mode 100644 plugins/cache-redis/Predis/Command/KeyPersist.php delete mode 100644 plugins/cache-redis/Predis/Command/KeyPreciseExpire.php delete mode 100644 plugins/cache-redis/Predis/Command/KeyPreciseExpireAt.php delete mode 100644 plugins/cache-redis/Predis/Command/KeyPreciseTimeToLive.php delete mode 100644 plugins/cache-redis/Predis/Command/KeyRandom.php delete mode 100644 plugins/cache-redis/Predis/Command/KeyRename.php delete mode 100644 plugins/cache-redis/Predis/Command/KeyRenamePreserve.php delete mode 100644 plugins/cache-redis/Predis/Command/KeyRestore.php delete mode 100644 plugins/cache-redis/Predis/Command/KeyScan.php delete mode 100644 plugins/cache-redis/Predis/Command/KeySort.php delete mode 100644 plugins/cache-redis/Predis/Command/KeyTimeToLive.php delete mode 100644 plugins/cache-redis/Predis/Command/KeyType.php delete mode 100644 plugins/cache-redis/Predis/Command/ListIndex.php delete mode 100644 plugins/cache-redis/Predis/Command/ListInsert.php delete mode 100644 plugins/cache-redis/Predis/Command/ListLength.php delete mode 100644 plugins/cache-redis/Predis/Command/ListPopFirst.php delete mode 100644 plugins/cache-redis/Predis/Command/ListPopFirstBlocking.php delete mode 100644 plugins/cache-redis/Predis/Command/ListPopLast.php delete mode 100644 plugins/cache-redis/Predis/Command/ListPopLastBlocking.php delete mode 100644 plugins/cache-redis/Predis/Command/ListPopLastPushHead.php delete mode 100644 plugins/cache-redis/Predis/Command/ListPopLastPushHeadBlocking.php delete mode 100644 plugins/cache-redis/Predis/Command/ListPushHead.php delete mode 100644 plugins/cache-redis/Predis/Command/ListPushHeadX.php delete mode 100644 plugins/cache-redis/Predis/Command/ListPushTail.php delete mode 100644 plugins/cache-redis/Predis/Command/ListPushTailX.php delete mode 100644 plugins/cache-redis/Predis/Command/ListRange.php delete mode 100644 plugins/cache-redis/Predis/Command/ListRemove.php delete mode 100644 plugins/cache-redis/Predis/Command/ListSet.php delete mode 100644 plugins/cache-redis/Predis/Command/ListTrim.php delete mode 100644 plugins/cache-redis/Predis/Command/PubSubPublish.php delete mode 100644 plugins/cache-redis/Predis/Command/PubSubPubsub.php delete mode 100644 plugins/cache-redis/Predis/Command/PubSubSubscribe.php delete mode 100644 plugins/cache-redis/Predis/Command/PubSubSubscribeByPattern.php delete mode 100644 plugins/cache-redis/Predis/Command/PubSubUnsubscribe.php delete mode 100644 plugins/cache-redis/Predis/Command/PubSubUnsubscribeByPattern.php delete mode 100644 plugins/cache-redis/Predis/Command/ServerBackgroundRewriteAOF.php delete mode 100644 plugins/cache-redis/Predis/Command/ServerBackgroundSave.php delete mode 100644 plugins/cache-redis/Predis/Command/ServerClient.php delete mode 100644 plugins/cache-redis/Predis/Command/ServerCommand.php delete mode 100644 plugins/cache-redis/Predis/Command/ServerConfig.php delete mode 100644 plugins/cache-redis/Predis/Command/ServerDatabaseSize.php delete mode 100644 plugins/cache-redis/Predis/Command/ServerEval.php delete mode 100644 plugins/cache-redis/Predis/Command/ServerEvalSHA.php delete mode 100644 plugins/cache-redis/Predis/Command/ServerFlushAll.php delete mode 100644 plugins/cache-redis/Predis/Command/ServerFlushDatabase.php delete mode 100644 plugins/cache-redis/Predis/Command/ServerInfo.php delete mode 100644 plugins/cache-redis/Predis/Command/ServerInfoV26x.php delete mode 100644 plugins/cache-redis/Predis/Command/ServerLastSave.php delete mode 100644 plugins/cache-redis/Predis/Command/ServerMonitor.php delete mode 100644 plugins/cache-redis/Predis/Command/ServerObject.php delete mode 100644 plugins/cache-redis/Predis/Command/ServerSave.php delete mode 100644 plugins/cache-redis/Predis/Command/ServerScript.php delete mode 100644 plugins/cache-redis/Predis/Command/ServerSentinel.php delete mode 100644 plugins/cache-redis/Predis/Command/ServerShutdown.php delete mode 100644 plugins/cache-redis/Predis/Command/ServerSlaveOf.php delete mode 100644 plugins/cache-redis/Predis/Command/ServerSlowlog.php delete mode 100644 plugins/cache-redis/Predis/Command/ServerTime.php delete mode 100644 plugins/cache-redis/Predis/Command/SetAdd.php delete mode 100644 plugins/cache-redis/Predis/Command/SetCardinality.php delete mode 100644 plugins/cache-redis/Predis/Command/SetDifference.php delete mode 100644 plugins/cache-redis/Predis/Command/SetDifferenceStore.php delete mode 100644 plugins/cache-redis/Predis/Command/SetIntersection.php delete mode 100644 plugins/cache-redis/Predis/Command/SetIntersectionStore.php delete mode 100644 plugins/cache-redis/Predis/Command/SetIsMember.php delete mode 100644 plugins/cache-redis/Predis/Command/SetMembers.php delete mode 100644 plugins/cache-redis/Predis/Command/SetMove.php delete mode 100644 plugins/cache-redis/Predis/Command/SetPop.php delete mode 100644 plugins/cache-redis/Predis/Command/SetRandomMember.php delete mode 100644 plugins/cache-redis/Predis/Command/SetRemove.php delete mode 100644 plugins/cache-redis/Predis/Command/SetScan.php delete mode 100644 plugins/cache-redis/Predis/Command/SetUnion.php delete mode 100644 plugins/cache-redis/Predis/Command/SetUnionStore.php delete mode 100644 plugins/cache-redis/Predis/Command/StringAppend.php delete mode 100644 plugins/cache-redis/Predis/Command/StringBitCount.php delete mode 100644 plugins/cache-redis/Predis/Command/StringBitOp.php delete mode 100644 plugins/cache-redis/Predis/Command/StringBitPos.php delete mode 100644 plugins/cache-redis/Predis/Command/StringDecrement.php delete mode 100644 plugins/cache-redis/Predis/Command/StringDecrementBy.php delete mode 100644 plugins/cache-redis/Predis/Command/StringGet.php delete mode 100644 plugins/cache-redis/Predis/Command/StringGetBit.php delete mode 100644 plugins/cache-redis/Predis/Command/StringGetMultiple.php delete mode 100644 plugins/cache-redis/Predis/Command/StringGetRange.php delete mode 100644 plugins/cache-redis/Predis/Command/StringGetSet.php delete mode 100644 plugins/cache-redis/Predis/Command/StringIncrement.php delete mode 100644 plugins/cache-redis/Predis/Command/StringIncrementBy.php delete mode 100644 plugins/cache-redis/Predis/Command/StringIncrementByFloat.php delete mode 100644 plugins/cache-redis/Predis/Command/StringPreciseSetExpire.php delete mode 100644 plugins/cache-redis/Predis/Command/StringSet.php delete mode 100644 plugins/cache-redis/Predis/Command/StringSetBit.php delete mode 100644 plugins/cache-redis/Predis/Command/StringSetExpire.php delete mode 100644 plugins/cache-redis/Predis/Command/StringSetMultiple.php delete mode 100644 plugins/cache-redis/Predis/Command/StringSetMultiplePreserve.php delete mode 100644 plugins/cache-redis/Predis/Command/StringSetPreserve.php delete mode 100644 plugins/cache-redis/Predis/Command/StringSetRange.php delete mode 100644 plugins/cache-redis/Predis/Command/StringStrlen.php delete mode 100644 plugins/cache-redis/Predis/Command/StringSubstr.php delete mode 100644 plugins/cache-redis/Predis/Command/TransactionDiscard.php delete mode 100644 plugins/cache-redis/Predis/Command/TransactionExec.php delete mode 100644 plugins/cache-redis/Predis/Command/TransactionMulti.php delete mode 100644 plugins/cache-redis/Predis/Command/TransactionUnwatch.php delete mode 100644 plugins/cache-redis/Predis/Command/TransactionWatch.php delete mode 100644 plugins/cache-redis/Predis/Command/ZSetAdd.php delete mode 100644 plugins/cache-redis/Predis/Command/ZSetCardinality.php delete mode 100644 plugins/cache-redis/Predis/Command/ZSetCount.php delete mode 100644 plugins/cache-redis/Predis/Command/ZSetIncrementBy.php delete mode 100644 plugins/cache-redis/Predis/Command/ZSetIntersectionStore.php delete mode 100644 plugins/cache-redis/Predis/Command/ZSetLexCount.php delete mode 100644 plugins/cache-redis/Predis/Command/ZSetRange.php delete mode 100644 plugins/cache-redis/Predis/Command/ZSetRangeByLex.php delete mode 100644 plugins/cache-redis/Predis/Command/ZSetRangeByScore.php delete mode 100644 plugins/cache-redis/Predis/Command/ZSetRank.php delete mode 100644 plugins/cache-redis/Predis/Command/ZSetRemove.php delete mode 100644 plugins/cache-redis/Predis/Command/ZSetRemoveRangeByLex.php delete mode 100644 plugins/cache-redis/Predis/Command/ZSetRemoveRangeByRank.php delete mode 100644 plugins/cache-redis/Predis/Command/ZSetRemoveRangeByScore.php delete mode 100644 plugins/cache-redis/Predis/Command/ZSetReverseRange.php delete mode 100644 plugins/cache-redis/Predis/Command/ZSetReverseRangeByLex.php delete mode 100644 plugins/cache-redis/Predis/Command/ZSetReverseRangeByScore.php delete mode 100644 plugins/cache-redis/Predis/Command/ZSetReverseRank.php delete mode 100644 plugins/cache-redis/Predis/Command/ZSetScan.php delete mode 100644 plugins/cache-redis/Predis/Command/ZSetScore.php delete mode 100644 plugins/cache-redis/Predis/Command/ZSetUnionStore.php delete mode 100644 plugins/cache-redis/Predis/Configuration/ClusterOption.php delete mode 100644 plugins/cache-redis/Predis/Configuration/ConnectionFactoryOption.php delete mode 100644 plugins/cache-redis/Predis/Configuration/ExceptionsOption.php delete mode 100644 plugins/cache-redis/Predis/Configuration/PrefixOption.php delete mode 100644 plugins/cache-redis/Predis/Configuration/ProfileOption.php delete mode 100644 plugins/cache-redis/Predis/Configuration/ReplicationOption.php delete mode 100644 plugins/cache-redis/Predis/Connection/Aggregate/ClusterInterface.php delete mode 100644 plugins/cache-redis/Predis/Connection/Aggregate/MasterSlaveReplication.php delete mode 100644 plugins/cache-redis/Predis/Connection/Aggregate/PredisCluster.php delete mode 100644 plugins/cache-redis/Predis/Connection/Aggregate/RedisCluster.php delete mode 100644 plugins/cache-redis/Predis/Connection/Aggregate/ReplicationInterface.php delete mode 100644 plugins/cache-redis/Predis/Profile/Factory.php delete mode 100644 plugins/cache-redis/Predis/Profile/ProfileInterface.php delete mode 100644 plugins/cache-redis/Predis/Profile/RedisProfile.php delete mode 100644 plugins/cache-redis/Predis/Profile/RedisUnstable.php delete mode 100644 plugins/cache-redis/Predis/Profile/RedisVersion200.php delete mode 100644 plugins/cache-redis/Predis/Profile/RedisVersion220.php delete mode 100644 plugins/cache-redis/Predis/Profile/RedisVersion240.php delete mode 100644 plugins/cache-redis/Predis/Profile/RedisVersion260.php delete mode 100644 plugins/cache-redis/Predis/Profile/RedisVersion280.php delete mode 100644 plugins/cache-redis/Predis/Profile/RedisVersion300.php diff --git a/plugins/cache-redis/Predis/Client.php b/plugins/cache-redis/Predis/Client.php index 87596ec92..0b4511a52 100644 --- a/plugins/cache-redis/Predis/Client.php +++ b/plugins/cache-redis/Predis/Client.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,21 +12,35 @@ namespace Predis; +use ArrayIterator; +use InvalidArgumentException; +use IteratorAggregate; use Predis\Command\CommandInterface; use Predis\Command\RawCommand; +use Predis\Command\Redis\Container\ContainerFactory; +use Predis\Command\Redis\Container\ContainerInterface; use Predis\Command\ScriptCommand; use Predis\Configuration\Options; use Predis\Configuration\OptionsInterface; -use Predis\Connection\AggregateConnectionInterface; use Predis\Connection\ConnectionInterface; +use Predis\Connection\Parameters; use Predis\Connection\ParametersInterface; +use Predis\Connection\RelayConnection; use Predis\Monitor\Consumer as MonitorConsumer; +use Predis\Pipeline\Atomic; +use Predis\Pipeline\FireAndForget; use Predis\Pipeline\Pipeline; +use Predis\Pipeline\RelayAtomic; +use Predis\Pipeline\RelayPipeline; use Predis\PubSub\Consumer as PubSubConsumer; +use Predis\PubSub\RelayConsumer as RelayPubSubConsumer; use Predis\Response\ErrorInterface as ErrorResponseInterface; use Predis\Response\ResponseInterface; use Predis\Response\ServerException; use Predis\Transaction\MultiExec as MultiExecTransaction; +use ReturnTypeWillChange; +use RuntimeException; +use Traversable; /** * Client class used for connecting and executing commands on Redis. @@ -34,17 +49,20 @@ use Predis\Transaction\MultiExec as MultiExecTransaction; * abstractions are built. Internally it aggregates various other classes each * one with its own responsibility and scope. * - * {@inheritdoc} - * - * @author Daniele Alessandri + * @template-implements \IteratorAggregate */ -class Client implements ClientInterface +class Client implements ClientInterface, IteratorAggregate { - const VERSION = '1.0.3'; + public const VERSION = '2.2.2'; - protected $connection; - protected $options; - private $profile; + /** @var OptionsInterface */ + private $options; + + /** @var ConnectionInterface */ + private $connection; + + /** @var Command\FactoryInterface */ + private $commands; /** * @param mixed $parameters Connection parameters for one or more servers. @@ -52,126 +70,99 @@ class Client implements ClientInterface */ public function __construct($parameters = null, $options = null) { - $this->options = $this->createOptions($options ?: array()); - $this->connection = $this->createConnection($parameters ?: array()); - $this->profile = $this->options->profile; + $this->options = static::createOptions($options ?? new Options()); + $this->connection = static::createConnection($this->options, $parameters ?? new Parameters()); + $this->commands = $this->options->commands; } /** - * Creates a new instance of Predis\Configuration\Options from different - * types of arguments or simply returns the passed argument if it is an - * instance of Predis\Configuration\OptionsInterface. + * Creates a new set of client options for the client. * - * @param mixed $options Client options. - * - * @throws \InvalidArgumentException + * @param array|OptionsInterface $options Set of client options * * @return OptionsInterface + * @throws InvalidArgumentException */ - protected function createOptions($options) + protected static function createOptions($options) { if (is_array($options)) { return new Options($options); - } - - if ($options instanceof OptionsInterface) { + } elseif ($options instanceof OptionsInterface) { return $options; + } else { + throw new InvalidArgumentException('Invalid type for client options'); } - - throw new \InvalidArgumentException('Invalid type for client options.'); } /** - * Creates single or aggregate connections from different types of arguments - * (string, array) or returns the passed argument if it is an instance of a - * class implementing Predis\Connection\ConnectionInterface. + * Creates single or aggregate connections from supplied arguments. * - * Accepted types for connection parameters are: + * This method accepts the following types to create a connection instance: * - * - Instance of Predis\Connection\ConnectionInterface. - * - Instance of Predis\Connection\ParametersInterface. - * - Array - * - String - * - Callable + * - Array (dictionary: single connection, indexed: aggregate connections) + * - String (URI for a single connection) + * - Callable (connection initializer callback) + * - Instance of Predis\Connection\ParametersInterface (used as-is) + * - Instance of Predis\Connection\ConnectionInterface (returned as-is) * - * @param mixed $parameters Connection parameters or connection instance. + * When a callable is passed, it receives the original set of client options + * and must return an instance of Predis\Connection\ConnectionInterface. * - * @throws \InvalidArgumentException + * Connections are created using the connection factory (in case of single + * connections) or a specialized aggregate connection initializer (in case + * of cluster and replication) retrieved from the supplied client options. + * + * @param OptionsInterface $options Client options container + * @param mixed $parameters Connection parameters * * @return ConnectionInterface + * @throws InvalidArgumentException */ - protected function createConnection($parameters) + protected static function createConnection(OptionsInterface $options, $parameters) { if ($parameters instanceof ConnectionInterface) { return $parameters; } if ($parameters instanceof ParametersInterface || is_string($parameters)) { - return $this->options->connections->create($parameters); + return $options->connections->create($parameters); } if (is_array($parameters)) { if (!isset($parameters[0])) { - return $this->options->connections->create($parameters); - } - - $options = $this->options; - - if ($options->defined('aggregate')) { - $initializer = $this->getConnectionInitializerWrapper($options->aggregate); - $connection = $initializer($parameters, $options); + return $options->connections->create($parameters); + } elseif ($options->defined('cluster') && $initializer = $options->cluster) { + return $initializer($parameters, true); + } elseif ($options->defined('replication') && $initializer = $options->replication) { + return $initializer($parameters, true); + } elseif ($options->defined('aggregate') && $initializer = $options->aggregate) { + return $initializer($parameters, false); } else { - if ($options->defined('replication') && $replication = $options->replication) { - $connection = $replication; - } else { - $connection = $options->cluster; - } - - $options->connections->aggregate($connection, $parameters); + throw new InvalidArgumentException( + 'Array of connection parameters requires `cluster`, `replication` or `aggregate` client option' + ); } - - return $connection; } if (is_callable($parameters)) { - $initializer = $this->getConnectionInitializerWrapper($parameters); - $connection = $initializer($this->options); + $connection = call_user_func($parameters, $options); + + if (!$connection instanceof ConnectionInterface) { + throw new InvalidArgumentException('Callable parameters must return a valid connection'); + } return $connection; } - throw new \InvalidArgumentException('Invalid type for connection parameters.'); - } - - /** - * Wraps a callable to make sure that its returned value represents a valid - * connection type. - * - * @param mixed $callable - * - * @return \Closure - */ - protected function getConnectionInitializerWrapper($callable) - { - return function () use ($callable) { - $connection = call_user_func_array($callable, func_get_args()); - - if (!$connection instanceof ConnectionInterface) { - throw new \UnexpectedValueException( - 'The callable connection initializer returned an invalid type.' - ); - } - - return $connection; - }; + throw new InvalidArgumentException('Invalid type for connection parameters'); } /** * {@inheritdoc} */ - public function getProfile() + public function getCommandFactory() { - return $this->profile; + return $this->commands; } /** @@ -183,23 +174,53 @@ class Client implements ClientInterface } /** - * Creates a new client instance for the specified connection ID or alias, - * only when working with an aggregate connection (cluster, replication). - * The new client instances uses the same options of the original one. + * Creates a new client using a specific underlying connection. * - * @param string $connectionID Identifier of a connection. + * This method allows to create a new client instance by picking a specific + * connection out of an aggregate one, with the same options of the original + * client instance. * - * @throws \InvalidArgumentException + * The specified selector defines which logic to use to look for a suitable + * connection by the specified value. Supported selectors are: * - * @return Client + * - `id` + * - `key` + * - `slot` + * - `command` + * - `alias` + * - `role` + * + * Internally the client relies on duck-typing and follows this convention: + * + * $selector string => getConnectionBy$selector($value) method + * + * This means that support for specific selectors may vary depending on the + * actual logic implemented by connection classes and there is no interface + * binding a connection class to implement any of these. + * + * @param string $selector Type of selector. + * @param mixed $value Value to be used by the selector. + * + * @return ClientInterface */ - public function getClientFor($connectionID) + public function getClientBy($selector, $value) { - if (!$connection = $this->getConnectionById($connectionID)) { - throw new \InvalidArgumentException("Invalid connection ID: $connectionID."); + $selector = strtolower($selector); + + if (!in_array($selector, ['id', 'key', 'slot', 'role', 'alias', 'command'])) { + throw new InvalidArgumentException("Invalid selector type: `$selector`"); } - return new static($connection, $this->options); + if (!method_exists($this->connection, $method = "getConnectionBy$selector")) { + $class = get_class($this->connection); + throw new InvalidArgumentException("Selecting connection by $selector is not supported by $class"); + } + + if (!$connection = $this->connection->$method($value)) { + throw new InvalidArgumentException("Cannot find a connection by $selector matching `$value`"); + } + + return new static($connection, $this->getOptions()); } /** @@ -248,24 +269,29 @@ class Client implements ClientInterface } /** - * Retrieves the specified connection from the aggregate connection when the - * client is in cluster or replication mode. + * Applies the configured serializer and compression to given value. * - * @param string $connectionID Index or alias of the single connection. - * - * @throws NotSupportedException - * - * @return Connection\NodeConnectionInterface + * @param mixed $value + * @return string */ - public function getConnectionById($connectionID) + public function pack($value) { - if (!$this->connection instanceof AggregateConnectionInterface) { - throw new NotSupportedException( - 'Retrieving connections by ID is supported only by aggregate connections.' - ); - } + return $this->connection instanceof RelayConnection + ? $this->connection->pack($value) + : $value; + } - return $this->connection->getConnectionById($connectionID); + /** + * Deserializes and decompresses to given value. + * + * @param mixed $value + * @return string + */ + public function unpack($value) + { + return $this->connection instanceof RelayConnection + ? $this->connection->unpack($value) + : $value; } /** @@ -273,7 +299,7 @@ class Client implements ClientInterface * applying any prefix to keys or throwing exceptions on Redis errors even * regardless of client options. * - * It is possibile to indentify Redis error responses from normal responses + * It is possible to identify Redis error responses from normal responses * using the second optional argument which is populated by reference. * * @param array $arguments Command arguments as defined by the command signature. @@ -284,9 +310,10 @@ class Client implements ClientInterface public function executeRaw(array $arguments, &$error = null) { $error = false; + $commandID = array_shift($arguments); $response = $this->connection->executeCommand( - new RawCommand($arguments) + new RawCommand($commandID, $arguments) ); if ($response instanceof ResponseInterface) { @@ -313,9 +340,37 @@ class Client implements ClientInterface /** * {@inheritdoc} */ - public function createCommand($commandID, $arguments = array()) + public function createCommand($commandID, $arguments = []) { - return $this->profile->createCommand($commandID, $arguments); + return $this->commands->create($commandID, $arguments); + } + + /** + * @param string $name + * @return ContainerInterface + */ + public function __get(string $name) + { + return ContainerFactory::create($this, $name); + } + + /** + * @param string $name + * @param mixed $value + * @return mixed + */ + public function __set(string $name, $value) + { + throw new RuntimeException('Not allowed'); + } + + /** + * @param string $name + * @return mixed + */ + public function __isset(string $name) + { + throw new RuntimeException('Not allowed'); } /** @@ -342,17 +397,13 @@ class Client implements ClientInterface * @param CommandInterface $command Redis command that generated the error. * @param ErrorResponseInterface $response Instance of the error response. * - * @throws ServerException - * * @return mixed + * @throws ServerException */ protected function onErrorResponse(CommandInterface $command, ErrorResponseInterface $response) { if ($command instanceof ScriptCommand && $response->getErrorType() === 'NOSCRIPT') { - $eval = $this->createCommand('EVAL'); - $eval->setRawArguments($command->getEvalArguments()); - - $response = $this->executeCommand($eval); + $response = $this->executeCommand($command->getEvalCommand()); if (!$response instanceof ResponseInterface) { $response = $command->parseResponse($response); @@ -370,7 +421,7 @@ class Client implements ClientInterface /** * Executes the specified initializer method on `$this` by adjusting the - * actual invokation depending on the arity (0, 1 or 2 arguments). This is + * actual invocation depending on the arity (0, 1 or 2 arguments). This is * simply an utility method to create Redis contexts instances since they * follow a common initialization path. * @@ -391,7 +442,7 @@ class Client implements ClientInterface : $this->$initializer(null, $argv[0]); case 2: - list($arg0, $arg1) = $argv; + [$arg0, $arg1] = $argv; return $this->$initializer($arg0, $arg1); @@ -404,11 +455,11 @@ class Client implements ClientInterface * Creates a new pipeline context and returns it, or returns the results of * a pipeline executed inside the optionally provided callable object. * - * @param mixed ... Array of options, a callable for execution, or both. + * @param mixed ...$arguments Array of options, a callable for execution, or both. * * @return Pipeline|array */ - public function pipeline(/* arguments */) + public function pipeline(...$arguments) { return $this->sharedContextFactory('createPipeline', func_get_args()); } @@ -416,19 +467,29 @@ class Client implements ClientInterface /** * Actual pipeline context initializer method. * - * @param array $options Options for the context. - * @param mixed $callable Optional callable used to execute the context. + * @param array|null $options Options for the context. + * @param mixed $callable Optional callable used to execute the context. * * @return Pipeline|array */ protected function createPipeline(array $options = null, $callable = null) { if (isset($options['atomic']) && $options['atomic']) { - $class = 'Predis\Pipeline\Atomic'; + $class = Atomic::class; } elseif (isset($options['fire-and-forget']) && $options['fire-and-forget']) { - $class = 'Predis\Pipeline\FireAndForget'; + $class = FireAndForget::class; } else { - $class = 'Predis\Pipeline\Pipeline'; + $class = Pipeline::class; + } + + if ($this->connection instanceof RelayConnection) { + if (isset($options['atomic']) && $options['atomic']) { + $class = RelayAtomic::class; + } elseif (isset($options['fire-and-forget']) && $options['fire-and-forget']) { + throw new NotSupportedException('The "relay" extension does not support fire-and-forget pipelines.'); + } else { + $class = RelayPipeline::class; + } } /* @@ -447,11 +508,11 @@ class Client implements ClientInterface * Creates a new transaction context and returns it, or returns the results * of a transaction executed inside the optionally provided callable object. * - * @param mixed ... Array of options, a callable for execution, or both. + * @param mixed ...$arguments Array of options, a callable for execution, or both. * * @return MultiExecTransaction|array */ - public function transaction(/* arguments */) + public function transaction(...$arguments) { return $this->sharedContextFactory('createTransaction', func_get_args()); } @@ -476,14 +537,14 @@ class Client implements ClientInterface } /** - * Creates a new publis/subscribe context and returns it, or starts its loop + * Creates a new publish/subscribe context and returns it, or starts its loop * inside the optionally provided callable object. * - * @param mixed ... Array of options, a callable for execution, or both. + * @param mixed ...$arguments Array of options, a callable for execution, or both. * * @return PubSubConsumer|null */ - public function pubSubLoop(/* arguments */) + public function pubSubLoop(...$arguments) { return $this->sharedContextFactory('createPubSub', func_get_args()); } @@ -498,7 +559,11 @@ class Client implements ClientInterface */ protected function createPubSub(array $options = null, $callable = null) { - $pubsub = new PubSubConsumer($this, $options); + if ($this->connection instanceof RelayConnection) { + $pubsub = new RelayPubSubConsumer($this, $options); + } else { + $pubsub = new PubSubConsumer($this, $options); + } if (!isset($callable)) { return $pubsub; @@ -509,6 +574,8 @@ class Client implements ClientInterface $pubsub->stop(); } } + + return null; } /** @@ -520,4 +587,26 @@ class Client implements ClientInterface { return new MonitorConsumer($this); } + + /** + * @return Traversable + */ + #[ReturnTypeWillChange] + public function getIterator() + { + $clients = []; + $connection = $this->getConnection(); + + if (!$connection instanceof Traversable) { + return new ArrayIterator([ + (string) $connection => new static($connection, $this->getOptions()), + ]); + } + + foreach ($connection as $node) { + $clients[(string) $node] = new static($node, $this->getOptions()); + } + + return new ArrayIterator($clients); + } } diff --git a/plugins/cache-redis/Predis/ClientContextInterface.php b/plugins/cache-redis/Predis/ClientContextInterface.php index 7f695b78d..e443ee5d1 100644 --- a/plugins/cache-redis/Predis/ClientContextInterface.php +++ b/plugins/cache-redis/Predis/ClientContextInterface.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,16 +12,49 @@ namespace Predis; +use Predis\Command\Argument\Geospatial\ByInterface; +use Predis\Command\Argument\Geospatial\FromInterface; +use Predis\Command\Argument\Search\AggregateArguments; +use Predis\Command\Argument\Search\AlterArguments; +use Predis\Command\Argument\Search\CreateArguments; +use Predis\Command\Argument\Search\DropArguments; +use Predis\Command\Argument\Search\ExplainArguments; +use Predis\Command\Argument\Search\ProfileArguments; +use Predis\Command\Argument\Search\SchemaFields\FieldInterface; +use Predis\Command\Argument\Search\SearchArguments; +use Predis\Command\Argument\Search\SugAddArguments; +use Predis\Command\Argument\Search\SugGetArguments; +use Predis\Command\Argument\Search\SynUpdateArguments; +use Predis\Command\Argument\Server\LimitOffsetCount; +use Predis\Command\Argument\Server\To; +use Predis\Command\Argument\TimeSeries\AddArguments; +use Predis\Command\Argument\TimeSeries\AlterArguments as TSAlterArguments; +use Predis\Command\Argument\TimeSeries\CreateArguments as TSCreateArguments; +use Predis\Command\Argument\TimeSeries\DecrByArguments; +use Predis\Command\Argument\TimeSeries\GetArguments; +use Predis\Command\Argument\TimeSeries\IncrByArguments; +use Predis\Command\Argument\TimeSeries\InfoArguments; +use Predis\Command\Argument\TimeSeries\MGetArguments; +use Predis\Command\Argument\TimeSeries\MRangeArguments; +use Predis\Command\Argument\TimeSeries\RangeArguments; use Predis\Command\CommandInterface; +use Predis\Command\Redis\Container\ACL; +use Predis\Command\Redis\Container\CLUSTER; +use Predis\Command\Redis\Container\FunctionContainer; +use Predis\Command\Redis\Container\Json\JSONDEBUG; +use Predis\Command\Redis\Container\Search\FTCONFIG; +use Predis\Command\Redis\Container\Search\FTCURSOR; /** * Interface defining a client-side context such as a pipeline or transaction. * - * @method $this del(array $keys) + * @method $this copy(string $source, string $destination, int $db = -1, bool $replace = false) + * @method $this del(array|string $keys) * @method $this dump($key) * @method $this exists($key) - * @method $this expire($key, $seconds) - * @method $this expireat($key, $timestamp) + * @method $this expire($key, $seconds, string $expireOption = '') + * @method $this expireat($key, $timestamp, string $expireOption = '') + * @method $this expiretime(string $key) * @method $this keys($pattern) * @method $this move($key, $db) * @method $this object($subcommand, $key) @@ -33,16 +67,77 @@ use Predis\Command\CommandInterface; * @method $this renamenx($key, $target) * @method $this scan($cursor, array $options = null) * @method $this sort($key, array $options = null) + * @method $this sort_ro(string $key, ?string $byPattern = null, ?LimitOffsetCount $limit = null, array $getPatterns = [], ?string $sorting = null, bool $alpha = false) * @method $this ttl($key) * @method $this type($key) * @method $this append($key, $value) - * @method $this bitcount($key, $start = null, $end = null) + * @method $this bfadd(string $key, $item) + * @method $this bfexists(string $key, $item) + * @method $this bfinfo(string $key, string $modifier = '') + * @method $this bfinsert(string $key, int $capacity = -1, float $error = -1, int $expansion = -1, bool $noCreate = false, bool $nonScaling = false, string ...$item) + * @method $this bfloadchunk(string $key, int $iterator, $data) + * @method $this bfmadd(string $key, ...$item) + * @method $this bfmexists(string $key, ...$item) + * @method $this bfreserve(string $key, float $errorRate, int $capacity, int $expansion = -1, bool $nonScaling = false) + * @method $this bfscandump(string $key, int $iterator) + * @method $this bitcount(string $key, $start = null, $end = null, string $index = 'byte') * @method $this bitop($operation, $destkey, $key) + * @method $this bitfield($key, $subcommand, ...$subcommandArg) + * @method $this bitpos($key, $bit, $start = null, $end = null, string $index = 'byte') + * @method $this blmpop(int $timeout, array $keys, string $modifier = 'left', int $count = 1) + * @method $this bzpopmax(array $keys, int $timeout) + * @method $this bzpopmin(array $keys, int $timeout) + * @method $this bzmpop(int $timeout, array $keys, string $modifier = 'min', int $count = 1) + * @method $this cfadd(string $key, $item) + * @method $this cfaddnx(string $key, $item) + * @method $this cfcount(string $key, $item) + * @method $this cfdel(string $key, $item) + * @method $this cfexists(string $key, $item) + * @method $this cfloadchunk(string $key, int $iterator, $data) + * @method $this cfmexists(string $key, ...$item) + * @method $this cfinfo(string $key) + * @method $this cfinsert(string $key, int $capacity = -1, bool $noCreate = false, string ...$item) + * @method $this cfinsertnx(string $key, int $capacity = -1, bool $noCreate = false, string ...$item) + * @method $this cfreserve(string $key, int $capacity, int $bucketSize = -1, int $maxIterations = -1, int $expansion = -1) + * @method $this cfscandump(string $key, int $iterator) + * @method $this cmsincrby(string $key, string|int...$itemIncrementDictionary) + * @method $this cmsinfo(string $key) + * @method $this cmsinitbydim(string $key, int $width, int $depth) + * @method $this cmsinitbyprob(string $key, float $errorRate, float $probability) + * @method $this cmsmerge(string $destination, array $sources, array $weights = []) + * @method $this cmsquery(string $key, string ...$item) * @method $this decr($key) * @method $this decrby($key, $decrement) + * @method $this failover(?To $to = null, bool $abort = false, int $timeout = -1) + * @method $this fcall(string $function, array $keys, ...$args) + * @method $this fcall_ro(string $function, array $keys, ...$args) + * @method $this ftaggregate(string $index, string $query, ?AggregateArguments $arguments = null) + * @method $this ftaliasadd(string $alias, string $index) + * @method $this ftaliasdel(string $alias) + * @method $this ftaliasupdate(string $alias, string $index) + * @method $this ftalter(string $index, FieldInterface[] $schema, ?AlterArguments $arguments = null) + * @method $this ftcreate(string $index, FieldInterface[] $schema, ?CreateArguments $arguments = null) + * @method $this ftdictadd(string $dict, ...$term) + * @method $this ftdictdel(string $dict, ...$term) + * @method $this ftdictdump(string $dict) + * @method $this ftdropindex(string $index, ?DropArguments $arguments = null) + * @method $this ftexplain(string $index, string $query, ?ExplainArguments $arguments = null) + * @method $this ftinfo(string $index) + * @method $this ftprofile(string $index, ProfileArguments $arguments) + * @method $this ftsearch(string $index, string $query, ?SearchArguments $arguments = null) + * @method $this ftspellcheck(string $index, string $query, ?SearchArguments $arguments = null) + * @method $this ftsugadd(string $key, string $string, float $score, ?SugAddArguments $arguments = null) + * @method $this ftsugdel(string $key, string $string) + * @method $this ftsugget(string $key, string $prefix, ?SugGetArguments $arguments = null) + * @method $this ftsuglen(string $key) + * @method $this ftsyndump(string $index) + * @method $this ftsynupdate(string $index, string $synonymGroupId, ?SynUpdateArguments $arguments = null, string ...$terms) + * @method $this fttagvals(string $index, string $fieldName) * @method $this get($key) * @method $this getbit($key, $offset) + * @method $this getex(string $key, $modifier = '', $value = false) * @method $this getrange($key, $start, $end) + * @method $this getdel(string $key) * @method $this getset($key, $value) * @method $this incr($key) * @method $this incrby($key, $increment) @@ -67,19 +162,47 @@ use Predis\Command\CommandInterface; * @method $this hlen($key) * @method $this hmget($key, array $fields) * @method $this hmset($key, array $dictionary) + * @method $this hrandfield(string $key, int $count = 1, bool $withValues = false) * @method $this hscan($key, $cursor, array $options = null) * @method $this hset($key, $field, $value) * @method $this hsetnx($key, $field, $value) * @method $this hvals($key) - * @method $this blpop(array $keys, $timeout) - * @method $this brpop(array $keys, $timeout) + * @method $this hstrlen($key, $field) + * @method $this jsonarrappend(string $key, string $path = '$', ...$value) + * @method $this jsonarrindex(string $key, string $path, string $value, int $start = 0, int $stop = 0) + * @method $this jsonarrinsert(string $key, string $path, int $index, string ...$value) + * @method $this jsonarrlen(string $key, string $path = '$') + * @method $this jsonarrpop(string $key, string $path = '$', int $index = -1) + * @method $this jsonarrtrim(string $key, string $path, int $start, int $stop) + * @method $this jsonclear(string $key, string $path = '$') + * @method $this jsondel(string $key, string $path = '$') + * @method $this jsonforget(string $key, string $path = '$') + * @method $this jsonget(string $key, string $indent = '', string $newline = '', string $space = '', string ...$paths) + * @method $this jsonnumincrby(string $key, string $path, int $value) + * @method $this jsonmerge(string $key, string $path, string $value) + * @method $this jsonmget(array $keys, string $path) + * @method $this jsonmset(string ...$keyPathValue) + * @method $this jsonobjkeys(string $key, string $path = '$') + * @method $this jsonobjlen(string $key, string $path = '$') + * @method $this jsonresp(string $key, string $path = '$') + * @method $this jsonset(string $key, string $path, string $value, ?string $subcommand = null) + * @method $this jsonstrappend(string $key, string $path, string $value) + * @method $this jsonstrlen(string $key, string $path = '$') + * @method $this jsontoggle(string $key, string $path) + * @method $this jsontype(string $key, string $path = '$') + * @method $this blmove(string $source, string $destination, string $where, string $to, int $timeout) + * @method $this blpop(array|string $keys, $timeout) + * @method $this brpop(array|string $keys, $timeout) * @method $this brpoplpush($source, $destination, $timeout) + * @method $this lcs(string $key1, string $key2, bool $len = false, bool $idx = false, int $minMatchLen = 0, bool $withMatchLen = false) * @method $this lindex($key, $index) * @method $this linsert($key, $whence, $pivot, $value) * @method $this llen($key) + * @method $this lmove(string $source, string $destination, string $where, string $to) + * @method $this lmpop(array $keys, string $modifier = 'left', int $count = 1) * @method $this lpop($key) * @method $this lpush($key, array $values) - * @method $this lpushx($key, $value) + * @method $this lpushx($key, array $values) * @method $this lrange($key, $start, $stop) * @method $this lrem($key, $count, $value) * @method $this lset($key, $index, $value) @@ -87,55 +210,109 @@ use Predis\Command\CommandInterface; * @method $this rpop($key) * @method $this rpoplpush($source, $destination) * @method $this rpush($key, array $values) - * @method $this rpushx($key, $value) + * @method $this rpushx($key, array $values) * @method $this sadd($key, array $members) * @method $this scard($key) - * @method $this sdiff(array $keys) - * @method $this sdiffstore($destination, array $keys) - * @method $this sinter(array $keys) - * @method $this sinterstore($destination, array $keys) + * @method $this sdiff(array|string $keys) + * @method $this sdiffstore($destination, array|string $keys) + * @method $this sinter(array|string $keys) + * @method $this sintercard(array $keys, int $limit = 0) + * @method $this sinterstore($destination, array|string $keys) * @method $this sismember($key, $member) * @method $this smembers($key) + * @method $this smismember(string $key, string ...$members) * @method $this smove($source, $destination, $member) - * @method $this spop($key) + * @method $this spop($key, $count = null) * @method $this srandmember($key, $count = null) * @method $this srem($key, $member) * @method $this sscan($key, $cursor, array $options = null) - * @method $this sunion(array $keys) - * @method $this sunionstore($destination, array $keys) + * @method $this sunion(array|string $keys) + * @method $this sunionstore($destination, array|string $keys) + * @method $this tdigestadd(string $key, float ...$value) + * @method $this tdigestbyrank(string $key, int ...$rank) + * @method $this tdigestbyrevrank(string $key, int ...$reverseRank) + * @method $this tdigestcdf(string $key, int ...$value) + * @method $this tdigestcreate(string $key, int $compression = 0) + * @method $this tdigestinfo(string $key) + * @method $this tdigestmax(string $key) + * @method $this tdigestmerge(string $destinationKey, array $sourceKeys, int $compression = 0, bool $override = false) + * @method $this tdigestquantile(string $key, float ...$quantile) + * @method $this tdigestmin(string $key) + * @method $this tdigestrank(string $key, ...$value) + * @method $this tdigestreset(string $key) + * @method $this tdigestrevrank(string $key, float ...$value) + * @method $this tdigesttrimmed_mean(string $key, float $lowCutQuantile, float $highCutQuantile) + * @method $this topkadd(string $key, ...$items) + * @method $this topkincrby(string $key, ...$itemIncrement) + * @method $this topkinfo(string $key) + * @method $this topklist(string $key, bool $withCount = false) + * @method $this topkquery(string $key, ...$items) + * @method $this topkreserve(string $key, int $topK, int $width = 8, int $depth = 7, float $decay = 0.9) + * @method $this tsadd(string $key, int $timestamp, float $value, ?AddArguments $arguments = null) + * @method $this tsalter(string $key, ?TSAlterArguments $arguments = null) + * @method $this tscreate(string $key, ?TSCreateArguments $arguments = null) + * @method $this tscreaterule(string $sourceKey, string $destKey, string $aggregator, int $bucketDuration, int $alignTimestamp = 0) + * @method $this tsdecrby(string $key, float $value, ?DecrByArguments $arguments = null) + * @method $this tsdel(string $key, int $fromTimestamp, int $toTimestamp) + * @method $this tsdeleterule(string $sourceKey, string $destKey) + * @method $this tsget(string $key, GetArguments $arguments = null) + * @method $this tsincrby(string $key, float $value, ?IncrByArguments $arguments = null) + * @method $this tsinfo(string $key, ?InfoArguments $arguments = null) + * @method $this tsmadd(mixed ...$keyTimestampValue) + * @method $this tsmget(MGetArguments $arguments, string ...$filterExpression) + * @method $this tsmrange($fromTimestamp, $toTimestamp, MRangeArguments $arguments) + * @method $this tsmrevrange($fromTimestamp, $toTimestamp, MRangeArguments $arguments) + * @method $this tsqueryindex(string ...$filterExpression) + * @method $this tsrange(string $key, $fromTimestamp, $toTimestamp, ?RangeArguments $arguments = null) + * @method $this tsrevrange(string $key, $fromTimestamp, $toTimestamp, ?RangeArguments $arguments = null) * @method $this zadd($key, array $membersAndScoresDictionary) * @method $this zcard($key) * @method $this zcount($key, $min, $max) + * @method $this zdiff(array $keys, bool $withScores = false) + * @method $this zdiffstore(string $destination, array $keys) * @method $this zincrby($key, $increment, $member) - * @method $this zinterstore($destination, array $keys, array $options = null) + * @method $this zintercard(array $keys, int $limit = 0) + * @method $this zinterstore(string $destination, array $keys, int[] $weights = [], string $aggregate = 'sum') + * @method $this zinter(array $keys, int[] $weights = [], string $aggregate = 'sum', bool $withScores = false) + * @method $this zmpop(array $keys, string $modifier = 'min', int $count = 1) + * @method $this zmscore(string $key, string ...$member) + * @method $this zrandmember(string $key, int $count = 1, bool $withScores = false) * @method $this zrange($key, $start, $stop, array $options = null) * @method $this zrangebyscore($key, $min, $max, array $options = null) + * @method $this zrangestore(string $destination, string $source, int|string $min, string|int $max, string|bool $by = false, bool $reversed = false, bool $limit = false, int $offset = 0, int $count = 0) * @method $this zrank($key, $member) * @method $this zrem($key, $member) * @method $this zremrangebyrank($key, $start, $stop) * @method $this zremrangebyscore($key, $min, $max) * @method $this zrevrange($key, $start, $stop, array $options = null) - * @method $this zrevrangebyscore($key, $min, $max, array $options = null) + * @method $this zrevrangebyscore($key, $max, $min, array $options = null) * @method $this zrevrank($key, $member) - * @method $this zunionstore($destination, array $keys, array $options = null) + * @method $this zunion(array $keys, int[] $weights = [], string $aggregate = 'sum', bool $withScores = false) + * @method $this zunionstore(string $destination, array $keys, int[] $weights = [], string $aggregate = 'sum') * @method $this zscore($key, $member) * @method $this zscan($key, $cursor, array $options = null) * @method $this zrangebylex($key, $start, $stop, array $options = null) + * @method $this zrevrangebylex($key, $start, $stop, array $options = null) * @method $this zremrangebylex($key, $min, $max) * @method $this zlexcount($key, $min, $max) + * @method $this pexpiretime(string $key) * @method $this pfadd($key, array $elements) - * @method $this pfmerge($destinationKey, array $sourceKeys) - * @method $this pfcount(array $keys) + * @method $this pfmerge($destinationKey, array|string $sourceKeys) + * @method $this pfcount(array|string $keys) * @method $this pubsub($subcommand, $argument) * @method $this publish($channel, $message) * @method $this discard() * @method $this exec() * @method $this multi() * @method $this unwatch() + * @method $this waitaof(int $numLocal, int $numReplicas, int $timeout) * @method $this watch($key) * @method $this eval($script, $numkeys, $keyOrArg1 = null, $keyOrArgN = null) + * @method $this eval_ro(string $script, array $keys, ...$argument) * @method $this evalsha($script, $numkeys, $keyOrArg1 = null, $keyOrArgN = null) + * @method $this evalsha_ro(string $sha1, array $keys, ...$argument) * @method $this script($subcommand, $argument = null) + * @method $this shutdown(bool $noSave = null, bool $now = false, bool $force = false, bool $abort = false) * @method $this auth($password) * @method $this echo($message) * @method $this ping($message = null) @@ -154,8 +331,22 @@ use Predis\Command\CommandInterface; * @method $this slowlog($subcommand, $argument = null) * @method $this time() * @method $this command() + * @method $this geoadd($key, $longitude, $latitude, $member) + * @method $this geohash($key, array $members) + * @method $this geopos($key, array $members) + * @method $this geodist($key, $member1, $member2, $unit = null) + * @method $this georadius($key, $longitude, $latitude, $radius, $unit, array $options = null) + * @method $this georadiusbymember($key, $member, $radius, $unit, array $options = null) + * @method $this geosearch(string $key, FromInterface $from, ByInterface $by, ?string $sorting = null, int $count = -1, bool $any = false, bool $withCoord = false, bool $withDist = false, bool $withHash = false) + * @method $this geosearchstore(string $destination, string $source, FromInterface $from, ByInterface $by, ?string $sorting = null, int $count = -1, bool $any = false, bool $storeDist = false) * - * @author Daniele Alessandri + * Container commands + * @property CLUSTER $cluster + * @property FunctionContainer $function + * @property FTCONFIG $ftconfig + * @property FTCURSOR $ftcursor + * @property JSONDEBUG $jsondebug + * @property ACL $acl */ interface ClientContextInterface { diff --git a/plugins/cache-redis/Predis/ClientException.php b/plugins/cache-redis/Predis/ClientException.php index 6c07aaf0d..e52ab0244 100644 --- a/plugins/cache-redis/Predis/ClientException.php +++ b/plugins/cache-redis/Predis/ClientException.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,8 +14,6 @@ namespace Predis; /** * Exception class that identifies client-side errors. - * - * @author Daniele Alessandri */ class ClientException extends PredisException { diff --git a/plugins/cache-redis/Predis/ClientInterface.php b/plugins/cache-redis/Predis/ClientInterface.php index f216c470c..2937c5804 100644 --- a/plugins/cache-redis/Predis/ClientInterface.php +++ b/plugins/cache-redis/Predis/ClientInterface.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,10 +12,42 @@ namespace Predis; +use Predis\Command\Argument\Geospatial\ByInterface; +use Predis\Command\Argument\Geospatial\FromInterface; +use Predis\Command\Argument\Search\AggregateArguments; +use Predis\Command\Argument\Search\AlterArguments; +use Predis\Command\Argument\Search\CreateArguments; +use Predis\Command\Argument\Search\DropArguments; +use Predis\Command\Argument\Search\ExplainArguments; +use Predis\Command\Argument\Search\ProfileArguments; +use Predis\Command\Argument\Search\SchemaFields\FieldInterface; +use Predis\Command\Argument\Search\SearchArguments; +use Predis\Command\Argument\Search\SugAddArguments; +use Predis\Command\Argument\Search\SugGetArguments; +use Predis\Command\Argument\Search\SynUpdateArguments; +use Predis\Command\Argument\Server\LimitOffsetCount; +use Predis\Command\Argument\Server\To; +use Predis\Command\Argument\TimeSeries\AddArguments; +use Predis\Command\Argument\TimeSeries\AlterArguments as TSAlterArguments; +use Predis\Command\Argument\TimeSeries\CreateArguments as TSCreateArguments; +use Predis\Command\Argument\TimeSeries\DecrByArguments; +use Predis\Command\Argument\TimeSeries\GetArguments; +use Predis\Command\Argument\TimeSeries\IncrByArguments; +use Predis\Command\Argument\TimeSeries\InfoArguments; +use Predis\Command\Argument\TimeSeries\MGetArguments; +use Predis\Command\Argument\TimeSeries\MRangeArguments; +use Predis\Command\Argument\TimeSeries\RangeArguments; use Predis\Command\CommandInterface; +use Predis\Command\FactoryInterface; +use Predis\Command\Redis\Container\ACL; +use Predis\Command\Redis\Container\CLUSTER; +use Predis\Command\Redis\Container\FunctionContainer; +use Predis\Command\Redis\Container\Json\JSONDEBUG; +use Predis\Command\Redis\Container\Search\FTCONFIG; +use Predis\Command\Redis\Container\Search\FTCURSOR; use Predis\Configuration\OptionsInterface; use Predis\Connection\ConnectionInterface; -use Predis\Profile\ProfileInterface; +use Predis\Response\Status; /** * Interface defining a client able to execute commands against Redis. @@ -24,155 +57,323 @@ use Predis\Profile\ProfileInterface; * and more friendly interface to ease programming which is described in the * following list of methods: * - * @method int del(array $keys) - * @method string dump($key) - * @method int exists($key) - * @method int expire($key, $seconds) - * @method int expireat($key, $timestamp) - * @method array keys($pattern) - * @method int move($key, $db) - * @method mixed object($subcommand, $key) - * @method int persist($key) - * @method int pexpire($key, $milliseconds) - * @method int pexpireat($key, $timestamp) - * @method int pttl($key) - * @method string randomkey() - * @method mixed rename($key, $target) - * @method int renamenx($key, $target) - * @method array scan($cursor, array $options = null) - * @method array sort($key, array $options = null) - * @method int ttl($key) - * @method mixed type($key) - * @method int append($key, $value) - * @method int bitcount($key, $start = null, $end = null) - * @method int bitop($operation, $destkey, $key) - * @method int decr($key) - * @method int decrby($key, $decrement) - * @method string get($key) - * @method int getbit($key, $offset) - * @method string getrange($key, $start, $end) - * @method string getset($key, $value) - * @method int incr($key) - * @method int incrby($key, $increment) - * @method string incrbyfloat($key, $increment) - * @method array mget(array $keys) - * @method mixed mset(array $dictionary) - * @method int msetnx(array $dictionary) - * @method mixed psetex($key, $milliseconds, $value) - * @method mixed set($key, $value, $expireResolution = null, $expireTTL = null, $flag = null) - * @method int setbit($key, $offset, $value) - * @method int setex($key, $seconds, $value) - * @method int setnx($key, $value) - * @method int setrange($key, $offset, $value) - * @method int strlen($key) - * @method int hdel($key, array $fields) - * @method int hexists($key, $field) - * @method string hget($key, $field) - * @method array hgetall($key) - * @method int hincrby($key, $field, $increment) - * @method string hincrbyfloat($key, $field, $increment) - * @method array hkeys($key) - * @method int hlen($key) - * @method array hmget($key, array $fields) - * @method mixed hmset($key, array $dictionary) - * @method array hscan($key, $cursor, array $options = null) - * @method int hset($key, $field, $value) - * @method int hsetnx($key, $field, $value) - * @method array hvals($key) - * @method array blpop(array $keys, $timeout) - * @method array brpop(array $keys, $timeout) - * @method array brpoplpush($source, $destination, $timeout) - * @method string lindex($key, $index) - * @method int linsert($key, $whence, $pivot, $value) - * @method int llen($key) - * @method string lpop($key) - * @method int lpush($key, array $values) - * @method int lpushx($key, $value) - * @method array lrange($key, $start, $stop) - * @method int lrem($key, $count, $value) - * @method mixed lset($key, $index, $value) - * @method mixed ltrim($key, $start, $stop) - * @method string rpop($key) - * @method string rpoplpush($source, $destination) - * @method int rpush($key, array $values) - * @method int rpushx($key, $value) - * @method int sadd($key, array $members) - * @method int scard($key) - * @method array sdiff(array $keys) - * @method int sdiffstore($destination, array $keys) - * @method array sinter(array $keys) - * @method int sinterstore($destination, array $keys) - * @method int sismember($key, $member) - * @method array smembers($key) - * @method int smove($source, $destination, $member) - * @method string spop($key) - * @method string srandmember($key, $count = null) - * @method int srem($key, $member) - * @method array sscan($key, $cursor, array $options = null) - * @method array sunion(array $keys) - * @method int sunionstore($destination, array $keys) - * @method int zadd($key, array $membersAndScoresDictionary) - * @method int zcard($key) - * @method string zcount($key, $min, $max) - * @method string zincrby($key, $increment, $member) - * @method int zinterstore($destination, array $keys, array $options = null) - * @method array zrange($key, $start, $stop, array $options = null) - * @method array zrangebyscore($key, $min, $max, array $options = null) - * @method int zrank($key, $member) - * @method int zrem($key, $member) - * @method int zremrangebyrank($key, $start, $stop) - * @method int zremrangebyscore($key, $min, $max) - * @method array zrevrange($key, $start, $stop, array $options = null) - * @method array zrevrangebyscore($key, $min, $max, array $options = null) - * @method int zrevrank($key, $member) - * @method int zunionstore($destination, array $keys, array $options = null) - * @method string zscore($key, $member) - * @method array zscan($key, $cursor, array $options = null) - * @method array zrangebylex($key, $start, $stop, array $options = null) - * @method int zremrangebylex($key, $min, $max) - * @method int zlexcount($key, $min, $max) - * @method int pfadd($key, array $elements) - * @method mixed pfmerge($destinationKey, array $sourceKeys) - * @method int pfcount(array $keys) - * @method mixed pubsub($subcommand, $argument) - * @method int publish($channel, $message) - * @method mixed discard() - * @method array exec() - * @method mixed multi() - * @method mixed unwatch() - * @method mixed watch($key) - * @method mixed eval($script, $numkeys, $keyOrArg1 = null, $keyOrArgN = null) - * @method mixed evalsha($script, $numkeys, $keyOrArg1 = null, $keyOrArgN = null) - * @method mixed script($subcommand, $argument = null) - * @method mixed auth($password) - * @method string echo($message) - * @method mixed ping($message = null) - * @method mixed select($database) - * @method mixed bgrewriteaof() - * @method mixed bgsave() - * @method mixed client($subcommand, $argument = null) - * @method mixed config($subcommand, $argument = null) - * @method int dbsize() - * @method mixed flushall() - * @method mixed flushdb() - * @method array info($section = null) - * @method int lastsave() - * @method mixed save() - * @method mixed slaveof($host, $port) - * @method mixed slowlog($subcommand, $argument = null) - * @method array time() - * @method array command() + * @method int copy(string $source, string $destination, int $db = -1, bool $replace = false) + * @method int del(string[]|string $keyOrKeys, string ...$keys = null) + * @method string|null dump(string $key) + * @method int exists(string $key) + * @method int expire(string $key, int $seconds, string $expireOption = '') + * @method int expireat(string $key, int $timestamp, string $expireOption = '') + * @method int expiretime(string $key) + * @method array keys(string $pattern) + * @method int move(string $key, int $db) + * @method mixed object($subcommand, string $key) + * @method int persist(string $key) + * @method int pexpire(string $key, int $milliseconds) + * @method int pexpireat(string $key, int $timestamp) + * @method int pttl(string $key) + * @method string|null randomkey() + * @method mixed rename(string $key, string $target) + * @method int renamenx(string $key, string $target) + * @method array scan($cursor, array $options = null) + * @method array sort(string $key, array $options = null) + * @method array sort_ro(string $key, ?string $byPattern = null, ?LimitOffsetCount $limit = null, array $getPatterns = [], ?string $sorting = null, bool $alpha = false) + * @method int ttl(string $key) + * @method mixed type(string $key) + * @method int append(string $key, $value) + * @method int bfadd(string $key, $item) + * @method int bfexists(string $key, $item) + * @method array bfinfo(string $key, string $modifier = '') + * @method array bfinsert(string $key, int $capacity = -1, float $error = -1, int $expansion = -1, bool $noCreate = false, bool $nonScaling = false, string ...$item) + * @method Status bfloadchunk(string $key, int $iterator, $data) + * @method array bfmadd(string $key, ...$item) + * @method array bfmexists(string $key, ...$item) + * @method Status bfreserve(string $key, float $errorRate, int $capacity, int $expansion = -1, bool $nonScaling = false) + * @method array bfscandump(string $key, int $iterator) + * @method int bitcount(string $key, $start = null, $end = null, string $index = 'byte') + * @method int bitop($operation, $destkey, $key) + * @method array|null bitfield(string $key, $subcommand, ...$subcommandArg) + * @method int bitpos(string $key, $bit, $start = null, $end = null, string $index = 'byte') + * @method array blmpop(int $timeout, array $keys, string $modifier = 'left', int $count = 1) + * @method array bzpopmax(array $keys, int $timeout) + * @method array bzpopmin(array $keys, int $timeout) + * @method array bzmpop(int $timeout, array $keys, string $modifier = 'min', int $count = 1) + * @method int cfadd(string $key, $item) + * @method int cfaddnx(string $key, $item) + * @method int cfcount(string $key, $item) + * @method int cfdel(string $key, $item) + * @method int cfexists(string $key, $item) + * @method Status cfloadchunk(string $key, int $iterator, $data) + * @method int cfmexists(string $key, ...$item) + * @method array cfinfo(string $key) + * @method array cfinsert(string $key, int $capacity = -1, bool $noCreate = false, string ...$item) + * @method array cfinsertnx(string $key, int $capacity = -1, bool $noCreate = false, string ...$item) + * @method Status cfreserve(string $key, int $capacity, int $bucketSize = -1, int $maxIterations = -1, int $expansion = -1) + * @method array cfscandump(string $key, int $iterator) + * @method array cmsincrby(string $key, string|int...$itemIncrementDictionary) + * @method array cmsinfo(string $key) + * @method Status cmsinitbydim(string $key, int $width, int $depth) + * @method Status cmsinitbyprob(string $key, float $errorRate, float $probability) + * @method Status cmsmerge(string $destination, array $sources, array $weights = []) + * @method array cmsquery(string $key, string ...$item) + * @method int decr(string $key) + * @method int decrby(string $key, int $decrement) + * @method Status failover(?To $to = null, bool $abort = false, int $timeout = -1) + * @method mixed fcall(string $function, array $keys, ...$args) + * @method mixed fcall_ro(string $function, array $keys, ...$args) + * @method array ftaggregate(string $index, string $query, ?AggregateArguments $arguments = null) + * @method Status ftaliasadd(string $alias, string $index) + * @method Status ftaliasdel(string $alias) + * @method Status ftaliasupdate(string $alias, string $index) + * @method Status ftalter(string $index, FieldInterface[] $schema, ?AlterArguments $arguments = null) + * @method Status ftcreate(string $index, FieldInterface[] $schema, ?CreateArguments $arguments = null) + * @method int ftdictadd(string $dict, ...$term) + * @method int ftdictdel(string $dict, ...$term) + * @method array ftdictdump(string $dict) + * @method Status ftdropindex(string $index, ?DropArguments $arguments = null) + * @method string ftexplain(string $index, string $query, ?ExplainArguments $arguments = null) + * @method array ftinfo(string $index) + * @method array ftprofile(string $index, ProfileArguments $arguments) + * @method array ftsearch(string $index, string $query, ?SearchArguments $arguments = null) + * @method array ftspellcheck(string $index, string $query, ?SearchArguments $arguments = null) + * @method int ftsugadd(string $key, string $string, float $score, ?SugAddArguments $arguments = null) + * @method int ftsugdel(string $key, string $string) + * @method array ftsugget(string $key, string $prefix, ?SugGetArguments $arguments = null) + * @method int ftsuglen(string $key) + * @method array ftsyndump(string $index) + * @method Status ftsynupdate(string $index, string $synonymGroupId, ?SynUpdateArguments $arguments = null, string ...$terms) + * @method array fttagvals(string $index, string $fieldName) + * @method string|null get(string $key) + * @method int getbit(string $key, $offset) + * @method int|null getex(string $key, $modifier = '', $value = false) + * @method string getrange(string $key, $start, $end) + * @method string getdel(string $key) + * @method string|null getset(string $key, $value) + * @method int incr(string $key) + * @method int incrby(string $key, int $increment) + * @method string incrbyfloat(string $key, int|float $increment) + * @method array mget(string[]|string $keyOrKeys, string ...$keys = null) + * @method mixed mset(array $dictionary) + * @method int msetnx(array $dictionary) + * @method Status psetex(string $key, $milliseconds, $value) + * @method Status set(string $key, $value, $expireResolution = null, $expireTTL = null, $flag = null) + * @method int setbit(string $key, $offset, $value) + * @method Status setex(string $key, $seconds, $value) + * @method int setnx(string $key, $value) + * @method int setrange(string $key, $offset, $value) + * @method int strlen(string $key) + * @method int hdel(string $key, array $fields) + * @method int hexists(string $key, string $field) + * @method string|null hget(string $key, string $field) + * @method array hgetall(string $key) + * @method int hincrby(string $key, string $field, int $increment) + * @method string hincrbyfloat(string $key, string $field, int|float $increment) + * @method array hkeys(string $key) + * @method int hlen(string $key) + * @method array hmget(string $key, array $fields) + * @method mixed hmset(string $key, array $dictionary) + * @method array hrandfield(string $key, int $count = 1, bool $withValues = false) + * @method array hscan(string $key, $cursor, array $options = null) + * @method int hset(string $key, string $field, string $value) + * @method int hsetnx(string $key, string $field, string $value) + * @method array hvals(string $key) + * @method int hstrlen(string $key, string $field) + * @method array jsonarrappend(string $key, string $path = '$', ...$value) + * @method array jsonarrindex(string $key, string $path, string $value, int $start = 0, int $stop = 0) + * @method array jsonarrinsert(string $key, string $path, int $index, string ...$value) + * @method array jsonarrlen(string $key, string $path = '$') + * @method array jsonarrpop(string $key, string $path = '$', int $index = -1) + * @method int jsonclear(string $key, string $path = '$') + * @method array jsonarrtrim(string $key, string $path, int $start, int $stop) + * @method int jsondel(string $key, string $path = '$') + * @method int jsonforget(string $key, string $path = '$') + * @method string jsonget(string $key, string $indent = '', string $newline = '', string $space = '', string ...$paths) + * @method string jsonnumincrby(string $key, string $path, int $value) + * @method Status jsonmerge(string $key, string $path, string $value) + * @method array jsonmget(array $keys, string $path) + * @method Status jsonmset(string ...$keyPathValue) + * @method array jsonobjkeys(string $key, string $path = '$') + * @method array jsonobjlen(string $key, string $path = '$') + * @method array jsonresp(string $key, string $path = '$') + * @method string jsonset(string $key, string $path, string $value, ?string $subcommand = null) + * @method array jsonstrappend(string $key, string $path, string $value) + * @method array jsonstrlen(string $key, string $path = '$') + * @method array jsontoggle(string $key, string $path) + * @method array jsontype(string $key, string $path = '$') + * @method string blmove(string $source, string $destination, string $where, string $to, int $timeout) + * @method array|null blpop(array|string $keys, int|float $timeout) + * @method array|null brpop(array|string $keys, int|float $timeout) + * @method string|null brpoplpush(string $source, string $destination, int|float $timeout) + * @method mixed lcs(string $key1, string $key2, bool $len = false, bool $idx = false, int $minMatchLen = 0, bool $withMatchLen = false) + * @method string|null lindex(string $key, int $index) + * @method int linsert(string $key, $whence, $pivot, $value) + * @method int llen(string $key) + * @method string lmove(string $source, string $destination, string $where, string $to) + * @method array|null lmpop(array $keys, string $modifier = 'left', int $count = 1) + * @method string|null lpop(string $key) + * @method int lpush(string $key, array $values) + * @method int lpushx(string $key, array $values) + * @method string[] lrange(string $key, int $start, int $stop) + * @method int lrem(string $key, int $count, string $value) + * @method mixed lset(string $key, int $index, string $value) + * @method mixed ltrim(string $key, int $start, int $stop) + * @method string|null rpop(string $key) + * @method string|null rpoplpush(string $source, string $destination) + * @method int rpush(string $key, array $values) + * @method int rpushx(string $key, array $values) + * @method int sadd(string $key, array $members) + * @method int scard(string $key) + * @method string[] sdiff(array|string $keys) + * @method int sdiffstore(string $destination, array|string $keys) + * @method string[] sinter(array|string $keys) + * @method int sintercard(array $keys, int $limit = 0) + * @method int sinterstore(string $destination, array|string $keys) + * @method int sismember(string $key, string $member) + * @method string[] smembers(string $key) + * @method array smismember(string $key, string ...$members) + * @method int smove(string $source, string $destination, string $member) + * @method string|array|null spop(string $key, int $count = null) + * @method string|null srandmember(string $key, int $count = null) + * @method int srem(string $key, array|string $member) + * @method array sscan(string $key, int $cursor, array $options = null) + * @method string[] sunion(array|string $keys) + * @method int sunionstore(string $destination, array|string $keys) + * @method int touch(string[]|string $keyOrKeys, string ...$keys = null) + * @method Status tdigestadd(string $key, float ...$value) + * @method array tdigestbyrank(string $key, int ...$rank) + * @method array tdigestbyrevrank(string $key, int ...$reverseRank) + * @method array tdigestcdf(string $key, int ...$value) + * @method Status tdigestcreate(string $key, int $compression = 0) + * @method array tdigestinfo(string $key) + * @method string tdigestmax(string $key) + * @method Status tdigestmerge(string $destinationKey, array $sourceKeys, int $compression = 0, bool $override = false) + * @method string[] tdigestquantile(string $key, float ...$quantile) + * @method string tdigestmin(string $key) + * @method array tdigestrank(string $key, float ...$value) + * @method Status tdigestreset(string $key) + * @method array tdigestrevrank(string $key, float ...$value) + * @method string tdigesttrimmed_mean(string $key, float $lowCutQuantile, float $highCutQuantile) + * @method array topkadd(string $key, ...$items) + * @method array topkincrby(string $key, ...$itemIncrement) + * @method array topkinfo(string $key) + * @method array topklist(string $key, bool $withCount = false) + * @method array topkquery(string $key, ...$items) + * @method Status topkreserve(string $key, int $topK, int $width = 8, int $depth = 7, float $decay = 0.9) + * @method int tsadd(string $key, int $timestamp, float $value, ?AddArguments $arguments = null) + * @method Status tsalter(string $key, ?TSAlterArguments $arguments = null) + * @method Status tscreate(string $key, ?TSCreateArguments $arguments = null) + * @method Status tscreaterule(string $sourceKey, string $destKey, string $aggregator, int $bucketDuration, int $alignTimestamp = 0) + * @method int tsdecrby(string $key, float $value, ?DecrByArguments $arguments = null) + * @method int tsdel(string $key, int $fromTimestamp, int $toTimestamp) + * @method Status tsdeleterule(string $sourceKey, string $destKey) + * @method array tsget(string $key, GetArguments $arguments = null) + * @method int tsincrby(string $key, float $value, ?IncrByArguments $arguments = null) + * @method array tsinfo(string $key, ?InfoArguments $arguments = null) + * @method array tsmadd(mixed ...$keyTimestampValue) + * @method array tsmget(MGetArguments $arguments, string ...$filterExpression) + * @method array tsmrange($fromTimestamp, $toTimestamp, MRangeArguments $arguments) + * @method array tsmrevrange($fromTimestamp, $toTimestamp, MRangeArguments $arguments) + * @method array tsqueryindex(string ...$filterExpression) + * @method array tsrange(string $key, $fromTimestamp, $toTimestamp, ?RangeArguments $arguments = null) + * @method array tsrevrange(string $key, $fromTimestamp, $toTimestamp, ?RangeArguments $arguments = null) + * @method string xadd(string $key, array $dictionary, string $id = '*', array $options = null) + * @method int xdel(string $key, string ...$id) + * @method int xlen(string $key) + * @method array xrevrange(string $key, string $end, string $start, ?int $count = null) + * @method array xrange(string $key, string $start, string $end, ?int $count = null) + * @method string xtrim(string $key, array|string $strategy, string $threshold, array $options = null) + * @method int zadd(string $key, array $membersAndScoresDictionary) + * @method int zcard(string $key) + * @method string zcount(string $key, int|string $min, int|string $max) + * @method array zdiff(array $keys, bool $withScores = false) + * @method int zdiffstore(string $destination, array $keys) + * @method string zincrby(string $key, int $increment, string $member) + * @method int zintercard(array $keys, int $limit = 0) + * @method int zinterstore(string $destination, array $keys, int[] $weights = [], string $aggregate = 'sum') + * @method array zinter(array $keys, int[] $weights = [], string $aggregate = 'sum', bool $withScores = false) + * @method array zmpop(array $keys, string $modifier = 'min', int $count = 1) + * @method array zmscore(string $key, string ...$member) + * @method array zpopmin(string $key, int $count = 1) + * @method array zpopmax(string $key, int $count = 1) + * @method mixed zrandmember(string $key, int $count = 1, bool $withScores = false) + * @method array zrange(string $key, int|string $start, int|string $stop, array $options = null) + * @method array zrangebyscore(string $key, int|string $min, int|string $max, array $options = null) + * @method int zrangestore(string $destination, string $source, int|string $min, int|string $max, string|bool $by = false, bool $reversed = false, bool $limit = false, int $offset = 0, int $count = 0) + * @method int|null zrank(string $key, string $member) + * @method int zrem(string $key, string ...$member) + * @method int zremrangebyrank(string $key, int|string $start, int|string $stop) + * @method int zremrangebyscore(string $key, int|string $min, int|string $max) + * @method array zrevrange(string $key, int|string $start, int|string $stop, array $options = null) + * @method array zrevrangebyscore(string $key, int|string $max, int|string $min, array $options = null) + * @method int|null zrevrank(string $key, string $member) + * @method array zunion(array $keys, int[] $weights = [], string $aggregate = 'sum', bool $withScores = false) + * @method int zunionstore(string $destination, array $keys, int[] $weights = [], string $aggregate = 'sum') + * @method string|null zscore(string $key, string $member) + * @method array zscan(string $key, int $cursor, array $options = null) + * @method array zrangebylex(string $key, string $start, string $stop, array $options = null) + * @method array zrevrangebylex(string $key, string $start, string $stop, array $options = null) + * @method int zremrangebylex(string $key, string $min, string $max) + * @method int zlexcount(string $key, string $min, string $max) + * @method int pexpiretime(string $key) + * @method int pfadd(string $key, array $elements) + * @method mixed pfmerge(string $destinationKey, array|string $sourceKeys) + * @method int pfcount(string[]|string $keyOrKeys, string ...$keys = null) + * @method mixed pubsub($subcommand, $argument) + * @method int publish($channel, $message) + * @method mixed discard() + * @method array|null exec() + * @method mixed multi() + * @method mixed unwatch() + * @method array waitaof(int $numLocal, int $numReplicas, int $timeout) + * @method mixed watch(string $key) + * @method mixed eval(string $script, int $numkeys, string ...$keyOrArg = null) + * @method mixed eval_ro(string $script, array $keys, ...$argument) + * @method mixed evalsha(string $script, int $numkeys, string ...$keyOrArg = null) + * @method mixed evalsha_ro(string $sha1, array $keys, ...$argument) + * @method mixed script($subcommand, $argument = null) + * @method Status shutdown(bool $noSave = null, bool $now = false, bool $force = false, bool $abort = false) + * @method mixed auth(string $password) + * @method string echo(string $message) + * @method mixed ping(string $message = null) + * @method mixed select(int $database) + * @method mixed bgrewriteaof() + * @method mixed bgsave() + * @method mixed client($subcommand, $argument = null) + * @method mixed config($subcommand, $argument = null) + * @method int dbsize() + * @method mixed flushall() + * @method mixed flushdb() + * @method array info($section = null) + * @method int lastsave() + * @method mixed save() + * @method mixed slaveof(string $host, int $port) + * @method mixed slowlog($subcommand, $argument = null) + * @method array time() + * @method array command() + * @method int geoadd(string $key, $longitude, $latitude, $member) + * @method array geohash(string $key, array $members) + * @method array geopos(string $key, array $members) + * @method string|null geodist(string $key, $member1, $member2, $unit = null) + * @method array georadius(string $key, $longitude, $latitude, $radius, $unit, array $options = null) + * @method array georadiusbymember(string $key, $member, $radius, $unit, array $options = null) + * @method array geosearch(string $key, FromInterface $from, ByInterface $by, ?string $sorting = null, int $count = -1, bool $any = false, bool $withCoord = false, bool $withDist = false, bool $withHash = false) + * @method int geosearchstore(string $destination, string $source, FromInterface $from, ByInterface $by, ?string $sorting = null, int $count = -1, bool $any = false, bool $storeDist = false) * - * @author Daniele Alessandri + * Container commands + * @property CLUSTER $cluster + * @property FunctionContainer $function + * @property FTCONFIG $ftconfig + * @property FTCURSOR $ftcursor + * @property JSONDEBUG $jsondebug + * @property ACL $acl */ interface ClientInterface { /** - * Returns the server profile used by the client. + * Returns the command factory used by the client. * - * @return ProfileInterface + * @return FactoryInterface */ - public function getProfile(); + public function getCommandFactory(); /** * Returns the client options specified upon initialization. @@ -206,7 +407,7 @@ interface ClientInterface * * @return CommandInterface */ - public function createCommand($method, $arguments = array()); + public function createCommand($method, $arguments = []); /** * Executes the specified Redis command. diff --git a/plugins/cache-redis/Predis/Cluster/ClusterStrategy.php b/plugins/cache-redis/Predis/Cluster/ClusterStrategy.php index 7635000ec..1965e26dd 100644 --- a/plugins/cache-redis/Predis/Cluster/ClusterStrategy.php +++ b/plugins/cache-redis/Predis/Cluster/ClusterStrategy.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,21 +12,17 @@ namespace Predis\Cluster; +use InvalidArgumentException; use Predis\Command\CommandInterface; use Predis\Command\ScriptCommand; /** * Common class implementing the logic needed to support clustering strategies. - * - * @author Daniele Alessandri */ abstract class ClusterStrategy implements StrategyInterface { protected $commands; - /** - * - */ public function __construct() { $this->commands = $this->getDefaultCommands(); @@ -38,12 +35,12 @@ abstract class ClusterStrategy implements StrategyInterface */ protected function getDefaultCommands() { - $getKeyFromFirstArgument = array($this, 'getKeyFromFirstArgument'); - $getKeyFromAllArguments = array($this, 'getKeyFromAllArguments'); + $getKeyFromFirstArgument = [$this, 'getKeyFromFirstArgument']; + $getKeyFromAllArguments = [$this, 'getKeyFromAllArguments']; - return array( + return [ /* commands operating on the key space */ - 'EXISTS' => $getKeyFromFirstArgument, + 'EXISTS' => $getKeyFromAllArguments, 'DEL' => $getKeyFromAllArguments, 'TYPE' => $getKeyFromFirstArgument, 'EXPIRE' => $getKeyFromFirstArgument, @@ -53,9 +50,10 @@ abstract class ClusterStrategy implements StrategyInterface 'PEXPIREAT' => $getKeyFromFirstArgument, 'TTL' => $getKeyFromFirstArgument, 'PTTL' => $getKeyFromFirstArgument, - 'SORT' => $getKeyFromFirstArgument, // TODO + 'SORT' => [$this, 'getKeyFromSortCommand'], 'DUMP' => $getKeyFromFirstArgument, 'RESTORE' => $getKeyFromFirstArgument, + 'FLUSHDB' => [$this, 'getFakeKey'], /* commands operating on string values */ 'APPEND' => $getKeyFromFirstArgument, @@ -72,14 +70,15 @@ abstract class ClusterStrategy implements StrategyInterface 'INCRBYFLOAT' => $getKeyFromFirstArgument, 'SETBIT' => $getKeyFromFirstArgument, 'SETEX' => $getKeyFromFirstArgument, - 'MSET' => array($this, 'getKeyFromInterleavedArguments'), - 'MSETNX' => array($this, 'getKeyFromInterleavedArguments'), + 'MSET' => [$this, 'getKeyFromInterleavedArguments'], + 'MSETNX' => [$this, 'getKeyFromInterleavedArguments'], 'SETNX' => $getKeyFromFirstArgument, 'SETRANGE' => $getKeyFromFirstArgument, 'STRLEN' => $getKeyFromFirstArgument, 'SUBSTR' => $getKeyFromFirstArgument, - 'BITOP' => array($this, 'getKeyFromBitOp'), + 'BITOP' => [$this, 'getKeyFromBitOp'], 'BITCOUNT' => $getKeyFromFirstArgument, + 'BITFIELD' => $getKeyFromFirstArgument, /* commands operating on lists */ 'LINSERT' => $getKeyFromFirstArgument, @@ -88,9 +87,9 @@ abstract class ClusterStrategy implements StrategyInterface 'LPOP' => $getKeyFromFirstArgument, 'RPOP' => $getKeyFromFirstArgument, 'RPOPLPUSH' => $getKeyFromAllArguments, - 'BLPOP' => array($this, 'getKeyFromBlockingListCommands'), - 'BRPOP' => array($this, 'getKeyFromBlockingListCommands'), - 'BRPOPLPUSH' => array($this, 'getKeyFromBlockingListCommands'), + 'BLPOP' => [$this, 'getKeyFromBlockingListCommands'], + 'BRPOP' => [$this, 'getKeyFromBlockingListCommands'], + 'BRPOPLPUSH' => [$this, 'getKeyFromBlockingListCommands'], 'LPUSH' => $getKeyFromFirstArgument, 'LPUSHX' => $getKeyFromFirstArgument, 'RPUSH' => $getKeyFromFirstArgument, @@ -121,7 +120,7 @@ abstract class ClusterStrategy implements StrategyInterface 'ZCARD' => $getKeyFromFirstArgument, 'ZCOUNT' => $getKeyFromFirstArgument, 'ZINCRBY' => $getKeyFromFirstArgument, - 'ZINTERSTORE' => array($this, 'getKeyFromZsetAggregationCommands'), + 'ZINTERSTORE' => [$this, 'getKeyFromZsetAggregationCommands'], 'ZRANGE' => $getKeyFromFirstArgument, 'ZRANGEBYSCORE' => $getKeyFromFirstArgument, 'ZRANK' => $getKeyFromFirstArgument, @@ -132,7 +131,7 @@ abstract class ClusterStrategy implements StrategyInterface 'ZREVRANGEBYSCORE' => $getKeyFromFirstArgument, 'ZREVRANK' => $getKeyFromFirstArgument, 'ZSCORE' => $getKeyFromFirstArgument, - 'ZUNIONSTORE' => array($this, 'getKeyFromZsetAggregationCommands'), + 'ZUNIONSTORE' => [$this, 'getKeyFromZsetAggregationCommands'], 'ZSCAN' => $getKeyFromFirstArgument, 'ZLEXCOUNT' => $getKeyFromFirstArgument, 'ZRANGEBYLEX' => $getKeyFromFirstArgument, @@ -162,9 +161,23 @@ abstract class ClusterStrategy implements StrategyInterface 'PFMERGE' => $getKeyFromAllArguments, /* scripting */ - 'EVAL' => array($this, 'getKeyFromScriptingCommands'), - 'EVALSHA' => array($this, 'getKeyFromScriptingCommands'), - ); + 'EVAL' => [$this, 'getKeyFromScriptingCommands'], + 'EVALSHA' => [$this, 'getKeyFromScriptingCommands'], + + /* server */ + 'INFO' => [$this, 'getFakeKey'], + + /* commands performing geospatial operations */ + 'GEOADD' => $getKeyFromFirstArgument, + 'GEOHASH' => $getKeyFromFirstArgument, + 'GEOPOS' => $getKeyFromFirstArgument, + 'GEODIST' => $getKeyFromFirstArgument, + 'GEORADIUS' => [$this, 'getKeyFromGeoradiusCommands'], + 'GEORADIUSBYMEMBER' => [$this, 'getKeyFromGeoradiusCommands'], + + /* cluster */ + 'CLUSTER' => [$this, 'getFakeKey'], + ]; } /** @@ -189,7 +202,7 @@ abstract class ClusterStrategy implements StrategyInterface * @param string $commandID Command ID. * @param mixed $callback A valid callable object, or NULL to unset the handler. * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ public function setCommandHandler($commandID, $callback = null) { @@ -202,7 +215,7 @@ abstract class ClusterStrategy implements StrategyInterface } if (!is_callable($callback)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'The argument must be a callable object or NULL.' ); } @@ -210,6 +223,16 @@ abstract class ClusterStrategy implements StrategyInterface $this->commands[$commandID] = $callback; } + /** + * Get fake key for commands with no key argument. + * + * @return string + */ + protected function getFakeKey(): string + { + return 'key'; + } + /** * Extracts the key from the first argument of a command instance. * @@ -234,9 +257,11 @@ abstract class ClusterStrategy implements StrategyInterface { $arguments = $command->getArguments(); - if ($this->checkSameSlotForKeys($arguments)) { - return $arguments[0]; + if (!$this->checkSameSlotForKeys($arguments)) { + return null; } + + return $arguments[0]; } /** @@ -250,15 +275,48 @@ abstract class ClusterStrategy implements StrategyInterface protected function getKeyFromInterleavedArguments(CommandInterface $command) { $arguments = $command->getArguments(); - $keys = array(); + $keys = []; for ($i = 0; $i < count($arguments); $i += 2) { $keys[] = $arguments[$i]; } - if ($this->checkSameSlotForKeys($keys)) { - return $arguments[0]; + if (!$this->checkSameSlotForKeys($keys)) { + return null; } + + return $arguments[0]; + } + + /** + * Extracts the key from SORT command. + * + * @param CommandInterface $command Command instance. + * + * @return string|null + */ + protected function getKeyFromSortCommand(CommandInterface $command) + { + $arguments = $command->getArguments(); + $firstKey = $arguments[0]; + + if (1 === $argc = count($arguments)) { + return $firstKey; + } + + $keys = [$firstKey]; + + for ($i = 1; $i < $argc; ++$i) { + if (strtoupper($arguments[$i]) === 'STORE') { + $keys[] = $arguments[++$i]; + } + } + + if (!$this->checkSameSlotForKeys($keys)) { + return null; + } + + return $firstKey; } /** @@ -272,9 +330,11 @@ abstract class ClusterStrategy implements StrategyInterface { $arguments = $command->getArguments(); - if ($this->checkSameSlotForKeys(array_slice($arguments, 0, count($arguments) - 1))) { - return $arguments[0]; + if (!$this->checkSameSlotForKeys(array_slice($arguments, 0, count($arguments) - 1))) { + return null; } + + return $arguments[0]; } /** @@ -288,9 +348,42 @@ abstract class ClusterStrategy implements StrategyInterface { $arguments = $command->getArguments(); - if ($this->checkSameSlotForKeys(array_slice($arguments, 1, count($arguments)))) { - return $arguments[1]; + if (!$this->checkSameSlotForKeys(array_slice($arguments, 1, count($arguments)))) { + return null; } + + return $arguments[1]; + } + + /** + * Extracts the key from GEORADIUS and GEORADIUSBYMEMBER commands. + * + * @param CommandInterface $command Command instance. + * + * @return string|null + */ + protected function getKeyFromGeoradiusCommands(CommandInterface $command) + { + $arguments = $command->getArguments(); + $argc = count($arguments); + $startIndex = $command->getId() === 'GEORADIUS' ? 5 : 4; + + if ($argc > $startIndex) { + $keys = [$arguments[0]]; + + for ($i = $startIndex; $i < $argc; ++$i) { + $argument = strtoupper($arguments[$i]); + if ($argument === 'STORE' || $argument === 'STOREDIST') { + $keys[] = $arguments[++$i]; + } + } + + if (!$this->checkSameSlotForKeys($keys)) { + return null; + } + } + + return $arguments[0]; } /** @@ -303,11 +396,13 @@ abstract class ClusterStrategy implements StrategyInterface protected function getKeyFromZsetAggregationCommands(CommandInterface $command) { $arguments = $command->getArguments(); - $keys = array_merge(array($arguments[0]), array_slice($arguments, 2, $arguments[1])); + $keys = array_merge([$arguments[0]], array_slice($arguments, 2, $arguments[1])); - if ($this->checkSameSlotForKeys($keys)) { - return $arguments[0]; + if (!$this->checkSameSlotForKeys($keys)) { + return null; } + + return $arguments[0]; } /** @@ -319,15 +414,15 @@ abstract class ClusterStrategy implements StrategyInterface */ protected function getKeyFromScriptingCommands(CommandInterface $command) { - if ($command instanceof ScriptCommand) { - $keys = $command->getKeys(); - } else { - $keys = array_slice($args = $command->getArguments(), 2, $args[1]); + $keys = $command instanceof ScriptCommand + ? $command->getKeys() + : array_slice($args = $command->getArguments(), 2, $args[1]); + + if (!$keys || !$this->checkSameSlotForKeys($keys)) { + return null; } - if ($keys && $this->checkSameSlotForKeys($keys)) { - return $keys[0]; - } + return $keys[0]; } /** diff --git a/plugins/cache-redis/Predis/Cluster/Distributor/DistributorInterface.php b/plugins/cache-redis/Predis/Cluster/Distributor/DistributorInterface.php index 831f52c52..593d9bb3c 100644 --- a/plugins/cache-redis/Predis/Cluster/Distributor/DistributorInterface.php +++ b/plugins/cache-redis/Predis/Cluster/Distributor/DistributorInterface.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -16,8 +17,6 @@ use Predis\Cluster\Hash\HashGeneratorInterface; /** * A distributor implements the logic to automatically distribute keys among * several nodes for client-side sharding. - * - * @author Daniele Alessandri */ interface DistributorInterface { diff --git a/plugins/cache-redis/Predis/Cluster/Distributor/EmptyRingException.php b/plugins/cache-redis/Predis/Cluster/Distributor/EmptyRingException.php index 039f2f2e8..68172066e 100644 --- a/plugins/cache-redis/Predis/Cluster/Distributor/EmptyRingException.php +++ b/plugins/cache-redis/Predis/Cluster/Distributor/EmptyRingException.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,11 +12,11 @@ namespace Predis\Cluster\Distributor; +use Exception; + /** * Exception class that identifies empty rings. - * - * @author Daniele Alessandri */ -class EmptyRingException extends \Exception +class EmptyRingException extends Exception { } diff --git a/plugins/cache-redis/Predis/Cluster/Distributor/HashRing.php b/plugins/cache-redis/Predis/Cluster/Distributor/HashRing.php index db864d912..03e75106f 100644 --- a/plugins/cache-redis/Predis/Cluster/Distributor/HashRing.php +++ b/plugins/cache-redis/Predis/Cluster/Distributor/HashRing.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -17,21 +18,19 @@ use Predis\Cluster\Hash\HashGeneratorInterface; * This class implements an hashring-based distributor that uses the same * algorithm of memcache to distribute keys in a cluster using client-side * sharding. - * - * @author Daniele Alessandri * @author Lorenzo Castelli */ class HashRing implements DistributorInterface, HashGeneratorInterface { - const DEFAULT_REPLICAS = 128; - const DEFAULT_WEIGHT = 100; + public const DEFAULT_REPLICAS = 128; + public const DEFAULT_WEIGHT = 100; private $ring; private $ringKeys; private $ringKeysCount; private $replicas; private $nodeHashCallback; - private $nodes = array(); + private $nodes = []; /** * @param int $replicas Number of replicas in the ring. @@ -53,10 +52,10 @@ class HashRing implements DistributorInterface, HashGeneratorInterface { // In case of collisions in the hashes of the nodes, the node added // last wins, thus the order in which nodes are added is significant. - $this->nodes[] = array( + $this->nodes[] = [ 'object' => $node, 'weight' => (int) $weight ?: $this::DEFAULT_WEIGHT, - ); + ]; $this->reset(); } @@ -131,7 +130,7 @@ class HashRing implements DistributorInterface, HashGeneratorInterface throw new EmptyRingException('Cannot initialize an empty hashring.'); } - $this->ring = array(); + $this->ring = []; $totalWeight = $this->computeTotalWeight(); $nodesCount = count($this->nodes); @@ -161,7 +160,7 @@ class HashRing implements DistributorInterface, HashGeneratorInterface $replicas = (int) round($weightRatio * $totalNodes * $replicas); for ($i = 0; $i < $replicas; ++$i) { - $key = crc32("$nodeHash:$i"); + $key = $this->hash("$nodeHash:$i"); $ring[$key] = $nodeObject; } } @@ -239,9 +238,8 @@ class HashRing implements DistributorInterface, HashGeneratorInterface public function get($value) { $hash = $this->hash($value); - $node = $this->getByHash($hash); - return $node; + return $this->getByHash($hash); } /** diff --git a/plugins/cache-redis/Predis/Cluster/Distributor/KetamaRing.php b/plugins/cache-redis/Predis/Cluster/Distributor/KetamaRing.php index dc77f320f..af3b88455 100644 --- a/plugins/cache-redis/Predis/Cluster/Distributor/KetamaRing.php +++ b/plugins/cache-redis/Predis/Cluster/Distributor/KetamaRing.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -15,13 +16,11 @@ namespace Predis\Cluster\Distributor; * This class implements an hashring-based distributor that uses the same * algorithm of libketama to distribute keys in a cluster using client-side * sharding. - * - * @author Daniele Alessandri * @author Lorenzo Castelli */ class KetamaRing extends HashRing { - const DEFAULT_REPLICAS = 160; + public const DEFAULT_REPLICAS = 160; /** * @param mixed $nodeHashCallback Callback returning a string used to calculate the hash of nodes. diff --git a/plugins/cache-redis/Predis/Cluster/Hash/CRC16.php b/plugins/cache-redis/Predis/Cluster/Hash/CRC16.php index 3add0cef2..4b21d5d21 100644 --- a/plugins/cache-redis/Predis/Cluster/Hash/CRC16.php +++ b/plugins/cache-redis/Predis/Cluster/Hash/CRC16.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,12 +14,10 @@ namespace Predis\Cluster\Hash; /** * Hash generator implementing the CRC-CCITT-16 algorithm used by redis-cluster. - * - * @author Daniele Alessandri */ class CRC16 implements HashGeneratorInterface { - private static $CCITT_16 = array( + private static $CCITT_16 = [ 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF, 0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6, @@ -51,7 +50,7 @@ class CRC16 implements HashGeneratorInterface 0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1, 0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8, 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0, - ); + ]; /** * {@inheritdoc} @@ -61,6 +60,8 @@ class CRC16 implements HashGeneratorInterface // CRC-CCITT-16 algorithm $crc = 0; $CCITT_16 = self::$CCITT_16; + + $value = (string) $value; $strlen = strlen($value); for ($i = 0; $i < $strlen; ++$i) { diff --git a/plugins/cache-redis/Predis/Cluster/Hash/HashGeneratorInterface.php b/plugins/cache-redis/Predis/Cluster/Hash/HashGeneratorInterface.php index 271b9e720..c835c0e66 100644 --- a/plugins/cache-redis/Predis/Cluster/Hash/HashGeneratorInterface.php +++ b/plugins/cache-redis/Predis/Cluster/Hash/HashGeneratorInterface.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,8 +15,6 @@ namespace Predis\Cluster\Hash; /** * An hash generator implements the logic used to calculate the hash of a key to * distribute operations among Redis nodes. - * - * @author Daniele Alessandri */ interface HashGeneratorInterface { diff --git a/plugins/cache-redis/Predis/Cluster/PredisStrategy.php b/plugins/cache-redis/Predis/Cluster/PredisStrategy.php index 206684279..574b86f9e 100644 --- a/plugins/cache-redis/Predis/Cluster/PredisStrategy.php +++ b/plugins/cache-redis/Predis/Cluster/PredisStrategy.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -16,8 +17,6 @@ use Predis\Cluster\Distributor\HashRing; /** * Default cluster strategy used by Predis to handle client-side sharding. - * - * @author Daniele Alessandri */ class PredisStrategy extends ClusterStrategy { @@ -40,9 +39,8 @@ class PredisStrategy extends ClusterStrategy { $key = $this->extractKeyTag($key); $hash = $this->distributor->hash($key); - $slot = $this->distributor->getSlot($hash); - return $slot; + return $this->distributor->getSlot($hash); } /** diff --git a/plugins/cache-redis/Predis/Cluster/RedisStrategy.php b/plugins/cache-redis/Predis/Cluster/RedisStrategy.php index df0bdb49b..8ae5c0f5e 100644 --- a/plugins/cache-redis/Predis/Cluster/RedisStrategy.php +++ b/plugins/cache-redis/Predis/Cluster/RedisStrategy.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -18,8 +19,6 @@ use Predis\NotSupportedException; /** * Default class used by Predis to calculate hashes out of keys of * commands supported by redis-cluster. - * - * @author Daniele Alessandri */ class RedisStrategy extends ClusterStrategy { @@ -41,9 +40,8 @@ class RedisStrategy extends ClusterStrategy public function getSlotByKey($key) { $key = $this->extractKeyTag($key); - $slot = $this->hashGenerator->hash($key) & 0x3FFF; - return $slot; + return $this->hashGenerator->hash($key) & 0x3FFF; } /** @@ -51,8 +49,7 @@ class RedisStrategy extends ClusterStrategy */ public function getDistributor() { - throw new NotSupportedException( - 'This cluster strategy does not provide an external distributor' - ); + $class = get_class($this); + throw new NotSupportedException("$class does not provide an external distributor"); } } diff --git a/plugins/cache-redis/Predis/Cluster/StrategyInterface.php b/plugins/cache-redis/Predis/Cluster/StrategyInterface.php index cdf7d09fa..83801ae6f 100644 --- a/plugins/cache-redis/Predis/Cluster/StrategyInterface.php +++ b/plugins/cache-redis/Predis/Cluster/StrategyInterface.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -19,8 +20,6 @@ use Predis\Command\CommandInterface; * keys extracted from supported commands. * * This is mostly useful to support clustering via client-side sharding. - * - * @author Daniele Alessandri */ interface StrategyInterface { @@ -30,7 +29,7 @@ interface StrategyInterface * * @param CommandInterface $command Command instance. * - * @return int + * @return int|null */ public function getSlot(CommandInterface $command); @@ -40,7 +39,7 @@ interface StrategyInterface * * @param string $key Key string. * - * @return int + * @return int|null */ public function getSlotByKey($key); diff --git a/plugins/cache-redis/Predis/Collection/Iterator/CursorBasedIterator.php b/plugins/cache-redis/Predis/Collection/Iterator/CursorBasedIterator.php index 922883f05..946bbc3a0 100644 --- a/plugins/cache-redis/Predis/Collection/Iterator/CursorBasedIterator.php +++ b/plugins/cache-redis/Predis/Collection/Iterator/CursorBasedIterator.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,8 +12,10 @@ namespace Predis\Collection\Iterator; +use Iterator; use Predis\ClientInterface; use Predis\NotSupportedException; +use ReturnTypeWillChange; /** * Provides the base implementation for a fully-rewindable PHP iterator that can @@ -24,10 +27,8 @@ use Predis\NotSupportedException; * can change several times during the iteration process. * * @see http://redis.io/commands/scan - * - * @author Daniele Alessandri */ -abstract class CursorBasedIterator implements \Iterator +abstract class CursorBasedIterator implements Iterator { protected $client; protected $match; @@ -65,8 +66,8 @@ abstract class CursorBasedIterator implements \Iterator */ protected function requiredCommand(ClientInterface $client, $commandID) { - if (!$client->getProfile()->supportsCommand($commandID)) { - throw new NotSupportedException("The current profile does not support '$commandID'."); + if (!$client->getCommandFactory()->supports($commandID)) { + throw new NotSupportedException("'$commandID' is not supported by the current command factory."); } } @@ -77,7 +78,7 @@ abstract class CursorBasedIterator implements \Iterator { $this->valid = true; $this->fetchmore = true; - $this->elements = array(); + $this->elements = []; $this->cursor = 0; $this->position = -1; $this->current = null; @@ -90,9 +91,9 @@ abstract class CursorBasedIterator implements \Iterator */ protected function getScanOptions() { - $options = array(); + $options = []; - if (strlen($this->match) > 0) { + if (strlen(strval($this->match)) > 0) { $options['MATCH'] = $this->match; } @@ -117,7 +118,7 @@ abstract class CursorBasedIterator implements \Iterator */ protected function fetch() { - list($cursor, $elements) = $this->executeCommand(); + [$cursor, $elements] = $this->executeCommand(); if (!$cursor) { $this->fetchmore = false; @@ -137,8 +138,9 @@ abstract class CursorBasedIterator implements \Iterator } /** - * {@inheritdoc} + * @return void */ + #[ReturnTypeWillChange] public function rewind() { $this->reset(); @@ -146,27 +148,30 @@ abstract class CursorBasedIterator implements \Iterator } /** - * {@inheritdoc} + * @return mixed */ + #[ReturnTypeWillChange] public function current() { return $this->current; } /** - * {@inheritdoc} + * @return int|null */ + #[ReturnTypeWillChange] public function key() { return $this->position; } /** - * {@inheritdoc} + * @return void */ + #[ReturnTypeWillChange] public function next() { - tryFetch: { + tryFetch: if (!$this->elements && $this->fetchmore) { $this->fetch(); } @@ -178,12 +183,12 @@ abstract class CursorBasedIterator implements \Iterator } else { $this->valid = false; } - } } /** - * {@inheritdoc} + * @return bool */ + #[ReturnTypeWillChange] public function valid() { return $this->valid; diff --git a/plugins/cache-redis/Predis/Collection/Iterator/HashKey.php b/plugins/cache-redis/Predis/Collection/Iterator/HashKey.php index aa8aeaf02..91b7d27ff 100644 --- a/plugins/cache-redis/Predis/Collection/Iterator/HashKey.php +++ b/plugins/cache-redis/Predis/Collection/Iterator/HashKey.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -17,9 +18,7 @@ use Predis\ClientInterface; * Abstracts the iteration of fields and values of an hash by leveraging the * HSCAN command (Redis >= 2.8) wrapped in a fully-rewindable PHP iterator. * - * @author Daniele Alessandri - * - * @link http://redis.io/commands/scan + * @see http://redis.io/commands/scan */ class HashKey extends CursorBasedIterator { @@ -51,6 +50,8 @@ class HashKey extends CursorBasedIterator protected function extractNext() { $this->position = key($this->elements); - $this->current = array_shift($this->elements); + $this->current = current($this->elements); + + unset($this->elements[$this->position]); } } diff --git a/plugins/cache-redis/Predis/Collection/Iterator/Keyspace.php b/plugins/cache-redis/Predis/Collection/Iterator/Keyspace.php index 5d985b9bc..b5fa022aa 100644 --- a/plugins/cache-redis/Predis/Collection/Iterator/Keyspace.php +++ b/plugins/cache-redis/Predis/Collection/Iterator/Keyspace.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -17,9 +18,7 @@ use Predis\ClientInterface; * Abstracts the iteration of the keyspace on a Redis instance by leveraging the * SCAN command (Redis >= 2.8) wrapped in a fully-rewindable PHP iterator. * - * @author Daniele Alessandri - * - * @link http://redis.io/commands/scan + * @see http://redis.io/commands/scan */ class Keyspace extends CursorBasedIterator { diff --git a/plugins/cache-redis/Predis/Collection/Iterator/ListKey.php b/plugins/cache-redis/Predis/Collection/Iterator/ListKey.php index 7a6eb479e..79ab3aa19 100644 --- a/plugins/cache-redis/Predis/Collection/Iterator/ListKey.php +++ b/plugins/cache-redis/Predis/Collection/Iterator/ListKey.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,8 +12,11 @@ namespace Predis\Collection\Iterator; +use InvalidArgumentException; +use Iterator; use Predis\ClientInterface; use Predis\NotSupportedException; +use ReturnTypeWillChange; /** * Abstracts the iteration of items stored in a list by leveraging the LRANGE @@ -24,11 +28,9 @@ use Predis\NotSupportedException; * guarantees on the returned elements because the collection can change several * times (trimmed, deleted, overwritten) during the iteration process. * - * @author Daniele Alessandri - * - * @link http://redis.io/commands/lrange + * @see http://redis.io/commands/lrange */ -class ListKey implements \Iterator +class ListKey implements Iterator { protected $client; protected $count; @@ -45,14 +47,14 @@ class ListKey implements \Iterator * @param string $key Redis list key. * @param int $count Number of items retrieved on each fetch operation. * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ public function __construct(ClientInterface $client, $key, $count = 10) { $this->requiredCommand($client, 'LRANGE'); if ((false === $count = filter_var($count, FILTER_VALIDATE_INT)) || $count < 0) { - throw new \InvalidArgumentException('The $count argument must be a positive integer.'); + throw new InvalidArgumentException('The $count argument must be a positive integer.'); } $this->client = $client; @@ -73,8 +75,8 @@ class ListKey implements \Iterator */ protected function requiredCommand(ClientInterface $client, $commandID) { - if (!$client->getProfile()->supportsCommand($commandID)) { - throw new NotSupportedException("The current profile does not support '$commandID'."); + if (!$client->getCommandFactory()->supports($commandID)) { + throw new NotSupportedException("'$commandID' is not supported by the current command factory."); } } @@ -85,7 +87,7 @@ class ListKey implements \Iterator { $this->valid = true; $this->fetchmore = true; - $this->elements = array(); + $this->elements = []; $this->position = -1; $this->current = null; } @@ -126,8 +128,9 @@ class ListKey implements \Iterator } /** - * {@inheritdoc} + * @return void */ + #[ReturnTypeWillChange] public function rewind() { $this->reset(); @@ -135,24 +138,27 @@ class ListKey implements \Iterator } /** - * {@inheritdoc} + * @return mixed */ + #[ReturnTypeWillChange] public function current() { return $this->current; } /** - * {@inheritdoc} + * @return int|null */ + #[ReturnTypeWillChange] public function key() { return $this->position; } /** - * {@inheritdoc} + * @return void */ + #[ReturnTypeWillChange] public function next() { if (!$this->elements && $this->fetchmore) { @@ -167,8 +173,9 @@ class ListKey implements \Iterator } /** - * {@inheritdoc} + * @return bool */ + #[ReturnTypeWillChange] public function valid() { return $this->valid; diff --git a/plugins/cache-redis/Predis/Collection/Iterator/SetKey.php b/plugins/cache-redis/Predis/Collection/Iterator/SetKey.php index bf2543975..74f982346 100644 --- a/plugins/cache-redis/Predis/Collection/Iterator/SetKey.php +++ b/plugins/cache-redis/Predis/Collection/Iterator/SetKey.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -17,9 +18,7 @@ use Predis\ClientInterface; * Abstracts the iteration of members stored in a set by leveraging the SSCAN * command (Redis >= 2.8) wrapped in a fully-rewindable PHP iterator. * - * @author Daniele Alessandri - * - * @link http://redis.io/commands/scan + * @see http://redis.io/commands/scan */ class SetKey extends CursorBasedIterator { diff --git a/plugins/cache-redis/Predis/Collection/Iterator/SortedSetKey.php b/plugins/cache-redis/Predis/Collection/Iterator/SortedSetKey.php index e2f178922..abee8c252 100644 --- a/plugins/cache-redis/Predis/Collection/Iterator/SortedSetKey.php +++ b/plugins/cache-redis/Predis/Collection/Iterator/SortedSetKey.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -17,9 +18,7 @@ use Predis\ClientInterface; * Abstracts the iteration of members stored in a sorted set by leveraging the * ZSCAN command (Redis >= 2.8) wrapped in a fully-rewindable PHP iterator. * - * @author Daniele Alessandri - * - * @link http://redis.io/commands/scan + * @see http://redis.io/commands/scan */ class SortedSetKey extends CursorBasedIterator { @@ -50,11 +49,9 @@ class SortedSetKey extends CursorBasedIterator */ protected function extractNext() { - if ($kv = each($this->elements)) { - $this->position = $kv[0]; - $this->current = $kv[1]; + $this->position = key($this->elements); + $this->current = current($this->elements); - unset($this->elements[$this->position]); - } + unset($this->elements[$this->position]); } } diff --git a/plugins/cache-redis/Predis/Command/Command.php b/plugins/cache-redis/Predis/Command/Command.php index bb538e7c5..68629c454 100644 --- a/plugins/cache-redis/Predis/Command/Command.php +++ b/plugins/cache-redis/Predis/Command/Command.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,32 +14,18 @@ namespace Predis\Command; /** * Base class for Redis commands. - * - * @author Daniele Alessandri */ abstract class Command implements CommandInterface { private $slot; - private $arguments = array(); - - /** - * Returns a filtered array of the arguments. - * - * @param array $arguments List of arguments. - * - * @return array - */ - protected function filterArguments(array $arguments) - { - return $arguments; - } + private $arguments = []; /** * {@inheritdoc} */ public function setArguments(array $arguments) { - $this->arguments = $this->filterArguments($arguments); + $this->arguments = $arguments; unset($this->slot); } @@ -82,9 +69,7 @@ abstract class Command implements CommandInterface */ public function getSlot() { - if (isset($this->slot)) { - return $this->slot; - } + return $this->slot ?? null; } /** @@ -104,7 +89,7 @@ abstract class Command implements CommandInterface */ public static function normalizeArguments(array $arguments) { - if (count($arguments) === 1 && is_array($arguments[0])) { + if (count($arguments) === 1 && isset($arguments[0]) && is_array($arguments[0])) { return $arguments[0]; } @@ -121,9 +106,21 @@ abstract class Command implements CommandInterface public static function normalizeVariadic(array $arguments) { if (count($arguments) === 2 && is_array($arguments[1])) { - return array_merge(array($arguments[0]), $arguments[1]); + return array_merge([$arguments[0]], $arguments[1]); } return $arguments; } + + /** + * Remove all false values from arguments. + * + * @return void + */ + public function filterArguments(): void + { + $this->arguments = array_filter($this->arguments, static function ($argument) { + return $argument !== false && $argument !== null; + }); + } } diff --git a/plugins/cache-redis/Predis/Command/CommandInterface.php b/plugins/cache-redis/Predis/Command/CommandInterface.php index 9f349e1df..20480316d 100644 --- a/plugins/cache-redis/Predis/Command/CommandInterface.php +++ b/plugins/cache-redis/Predis/Command/CommandInterface.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,8 +14,6 @@ namespace Predis\Command; /** * Defines an abstraction representing a Redis command. - * - * @author Daniele Alessandri */ interface CommandInterface { @@ -73,7 +72,7 @@ interface CommandInterface /** * Parses a raw response and returns a PHP object. * - * @param string $data Binary string containing the whole response. + * @param string|array|null $data Binary string containing the whole response. * * @return mixed */ diff --git a/plugins/cache-redis/Predis/Command/ConnectionAuth.php b/plugins/cache-redis/Predis/Command/ConnectionAuth.php deleted file mode 100644 index c8c9dedce..000000000 --- a/plugins/cache-redis/Predis/Command/ConnectionAuth.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/auth - * - * @author Daniele Alessandri - */ -class ConnectionAuth extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'AUTH'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ConnectionEcho.php b/plugins/cache-redis/Predis/Command/ConnectionEcho.php deleted file mode 100644 index fd4960971..000000000 --- a/plugins/cache-redis/Predis/Command/ConnectionEcho.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/echo - * - * @author Daniele Alessandri - */ -class ConnectionEcho extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'ECHO'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ConnectionPing.php b/plugins/cache-redis/Predis/Command/ConnectionPing.php deleted file mode 100644 index fa9d7346f..000000000 --- a/plugins/cache-redis/Predis/Command/ConnectionPing.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/ping - * - * @author Daniele Alessandri - */ -class ConnectionPing extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'PING'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ConnectionQuit.php b/plugins/cache-redis/Predis/Command/ConnectionQuit.php deleted file mode 100644 index e59e31e3e..000000000 --- a/plugins/cache-redis/Predis/Command/ConnectionQuit.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/quit - * - * @author Daniele Alessandri - */ -class ConnectionQuit extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'QUIT'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ConnectionSelect.php b/plugins/cache-redis/Predis/Command/ConnectionSelect.php deleted file mode 100644 index 1da825677..000000000 --- a/plugins/cache-redis/Predis/Command/ConnectionSelect.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/select - * - * @author Daniele Alessandri - */ -class ConnectionSelect extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'SELECT'; - } -} diff --git a/plugins/cache-redis/Predis/Command/HashDelete.php b/plugins/cache-redis/Predis/Command/HashDelete.php deleted file mode 100644 index d5d4c38c0..000000000 --- a/plugins/cache-redis/Predis/Command/HashDelete.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/hdel - * - * @author Daniele Alessandri - */ -class HashDelete extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'HDEL'; - } - - /** - * {@inheritdoc} - */ - protected function filterArguments(array $arguments) - { - return self::normalizeVariadic($arguments); - } -} diff --git a/plugins/cache-redis/Predis/Command/HashExists.php b/plugins/cache-redis/Predis/Command/HashExists.php deleted file mode 100644 index a2c69b90c..000000000 --- a/plugins/cache-redis/Predis/Command/HashExists.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/hexists - * - * @author Daniele Alessandri - */ -class HashExists extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'HEXISTS'; - } - - /** - * {@inheritdoc} - */ - public function parseResponse($data) - { - return (bool) $data; - } -} diff --git a/plugins/cache-redis/Predis/Command/HashGet.php b/plugins/cache-redis/Predis/Command/HashGet.php deleted file mode 100644 index 20f33da54..000000000 --- a/plugins/cache-redis/Predis/Command/HashGet.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/hget - * - * @author Daniele Alessandri - */ -class HashGet extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'HGET'; - } -} diff --git a/plugins/cache-redis/Predis/Command/HashGetAll.php b/plugins/cache-redis/Predis/Command/HashGetAll.php deleted file mode 100644 index d69867521..000000000 --- a/plugins/cache-redis/Predis/Command/HashGetAll.php +++ /dev/null @@ -1,42 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/hgetall - * - * @author Daniele Alessandri - */ -class HashGetAll extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'HGETALL'; - } - - /** - * {@inheritdoc} - */ - public function parseResponse($data) - { - $result = array(); - - for ($i = 0; $i < count($data); ++$i) { - $result[$data[$i]] = $data[++$i]; - } - - return $result; - } -} diff --git a/plugins/cache-redis/Predis/Command/HashGetMultiple.php b/plugins/cache-redis/Predis/Command/HashGetMultiple.php deleted file mode 100644 index 820ce958e..000000000 --- a/plugins/cache-redis/Predis/Command/HashGetMultiple.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/hmget - * - * @author Daniele Alessandri - */ -class HashGetMultiple extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'HMGET'; - } - - /** - * {@inheritdoc} - */ - protected function filterArguments(array $arguments) - { - return self::normalizeVariadic($arguments); - } -} diff --git a/plugins/cache-redis/Predis/Command/HashIncrementBy.php b/plugins/cache-redis/Predis/Command/HashIncrementBy.php deleted file mode 100644 index a37359ffb..000000000 --- a/plugins/cache-redis/Predis/Command/HashIncrementBy.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/hincrby - * - * @author Daniele Alessandri - */ -class HashIncrementBy extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'HINCRBY'; - } -} diff --git a/plugins/cache-redis/Predis/Command/HashIncrementByFloat.php b/plugins/cache-redis/Predis/Command/HashIncrementByFloat.php deleted file mode 100644 index bce9714fc..000000000 --- a/plugins/cache-redis/Predis/Command/HashIncrementByFloat.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/hincrbyfloat - * - * @author Daniele Alessandri - */ -class HashIncrementByFloat extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'HINCRBYFLOAT'; - } -} diff --git a/plugins/cache-redis/Predis/Command/HashKeys.php b/plugins/cache-redis/Predis/Command/HashKeys.php deleted file mode 100644 index 28266020a..000000000 --- a/plugins/cache-redis/Predis/Command/HashKeys.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/hkeys - * - * @author Daniele Alessandri - */ -class HashKeys extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'HKEYS'; - } -} diff --git a/plugins/cache-redis/Predis/Command/HashLength.php b/plugins/cache-redis/Predis/Command/HashLength.php deleted file mode 100644 index d70926f1c..000000000 --- a/plugins/cache-redis/Predis/Command/HashLength.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/hlen - * - * @author Daniele Alessandri - */ -class HashLength extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'HLEN'; - } -} diff --git a/plugins/cache-redis/Predis/Command/HashScan.php b/plugins/cache-redis/Predis/Command/HashScan.php deleted file mode 100644 index afde74eb9..000000000 --- a/plugins/cache-redis/Predis/Command/HashScan.php +++ /dev/null @@ -1,85 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/hscan - * - * @author Daniele Alessandri - */ -class HashScan extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'HSCAN'; - } - - /** - * {@inheritdoc} - */ - protected function filterArguments(array $arguments) - { - if (count($arguments) === 3 && is_array($arguments[2])) { - $options = $this->prepareOptions(array_pop($arguments)); - $arguments = array_merge($arguments, $options); - } - - return $arguments; - } - - /** - * Returns a list of options and modifiers compatible with Redis. - * - * @param array $options List of options. - * - * @return array - */ - protected function prepareOptions($options) - { - $options = array_change_key_case($options, CASE_UPPER); - $normalized = array(); - - if (!empty($options['MATCH'])) { - $normalized[] = 'MATCH'; - $normalized[] = $options['MATCH']; - } - - if (!empty($options['COUNT'])) { - $normalized[] = 'COUNT'; - $normalized[] = $options['COUNT']; - } - - return $normalized; - } - - /** - * {@inheritdoc} - */ - public function parseResponse($data) - { - if (is_array($data)) { - $fields = $data[1]; - $result = array(); - - for ($i = 0; $i < count($fields); ++$i) { - $result[$fields[$i]] = $fields[++$i]; - } - - $data[1] = $result; - } - - return $data; - } -} diff --git a/plugins/cache-redis/Predis/Command/HashSet.php b/plugins/cache-redis/Predis/Command/HashSet.php deleted file mode 100644 index d3154a9b2..000000000 --- a/plugins/cache-redis/Predis/Command/HashSet.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/hset - * - * @author Daniele Alessandri - */ -class HashSet extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'HSET'; - } - - /** - * {@inheritdoc} - */ - public function parseResponse($data) - { - return (bool) $data; - } -} diff --git a/plugins/cache-redis/Predis/Command/HashSetMultiple.php b/plugins/cache-redis/Predis/Command/HashSetMultiple.php deleted file mode 100644 index 6069e2ad9..000000000 --- a/plugins/cache-redis/Predis/Command/HashSetMultiple.php +++ /dev/null @@ -1,48 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/hmset - * - * @author Daniele Alessandri - */ -class HashSetMultiple extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'HMSET'; - } - - /** - * {@inheritdoc} - */ - protected function filterArguments(array $arguments) - { - if (count($arguments) === 2 && is_array($arguments[1])) { - $flattenedKVs = array($arguments[0]); - $args = $arguments[1]; - - foreach ($args as $k => $v) { - $flattenedKVs[] = $k; - $flattenedKVs[] = $v; - } - - return $flattenedKVs; - } - - return $arguments; - } -} diff --git a/plugins/cache-redis/Predis/Command/HashSetPreserve.php b/plugins/cache-redis/Predis/Command/HashSetPreserve.php deleted file mode 100644 index 582100d49..000000000 --- a/plugins/cache-redis/Predis/Command/HashSetPreserve.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/hsetnx - * - * @author Daniele Alessandri - */ -class HashSetPreserve extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'HSETNX'; - } - - /** - * {@inheritdoc} - */ - public function parseResponse($data) - { - return (bool) $data; - } -} diff --git a/plugins/cache-redis/Predis/Command/HashStringLength.php b/plugins/cache-redis/Predis/Command/HashStringLength.php deleted file mode 100644 index 7cfda80df..000000000 --- a/plugins/cache-redis/Predis/Command/HashStringLength.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/hstrlen - * - * @author Daniele Alessandri - */ -class HashStringLength extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'HSTRLEN'; - } -} diff --git a/plugins/cache-redis/Predis/Command/HashValues.php b/plugins/cache-redis/Predis/Command/HashValues.php deleted file mode 100644 index 0a5ea5f61..000000000 --- a/plugins/cache-redis/Predis/Command/HashValues.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/hvals - * - * @author Daniele Alessandri - */ -class HashValues extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'HVALS'; - } -} diff --git a/plugins/cache-redis/Predis/Command/HyperLogLogAdd.php b/plugins/cache-redis/Predis/Command/HyperLogLogAdd.php deleted file mode 100644 index 18d2bd7b5..000000000 --- a/plugins/cache-redis/Predis/Command/HyperLogLogAdd.php +++ /dev/null @@ -1,44 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/pfadd - * - * @author Daniele Alessandri - */ -class HyperLogLogAdd extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'PFADD'; - } - - /** - * {@inheritdoc} - */ - protected function filterArguments(array $arguments) - { - return self::normalizeVariadic($arguments); - } - - /** - * {@inheritdoc} - */ - public function parseResponse($data) - { - return (bool) $data; - } -} diff --git a/plugins/cache-redis/Predis/Command/HyperLogLogCount.php b/plugins/cache-redis/Predis/Command/HyperLogLogCount.php deleted file mode 100644 index 0afe54270..000000000 --- a/plugins/cache-redis/Predis/Command/HyperLogLogCount.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/pfcount - * - * @author Daniele Alessandri - */ -class HyperLogLogCount extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'PFCOUNT'; - } - - /** - * {@inheritdoc} - */ - protected function filterArguments(array $arguments) - { - return self::normalizeArguments($arguments); - } -} diff --git a/plugins/cache-redis/Predis/Command/HyperLogLogMerge.php b/plugins/cache-redis/Predis/Command/HyperLogLogMerge.php deleted file mode 100644 index c160be5b2..000000000 --- a/plugins/cache-redis/Predis/Command/HyperLogLogMerge.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/pfmerge - * - * @author Daniele Alessandri - */ -class HyperLogLogMerge extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'PFMERGE'; - } - - /** - * {@inheritdoc} - */ - protected function filterArguments(array $arguments) - { - return self::normalizeArguments($arguments); - } -} diff --git a/plugins/cache-redis/Predis/Command/KeyDelete.php b/plugins/cache-redis/Predis/Command/KeyDelete.php deleted file mode 100644 index 89bdfdb7f..000000000 --- a/plugins/cache-redis/Predis/Command/KeyDelete.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/del - * - * @author Daniele Alessandri - */ -class KeyDelete extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'DEL'; - } - - /** - * {@inheritdoc} - */ - protected function filterArguments(array $arguments) - { - return self::normalizeArguments($arguments); - } -} diff --git a/plugins/cache-redis/Predis/Command/KeyDump.php b/plugins/cache-redis/Predis/Command/KeyDump.php deleted file mode 100644 index 6d9c48800..000000000 --- a/plugins/cache-redis/Predis/Command/KeyDump.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/dump - * - * @author Daniele Alessandri - */ -class KeyDump extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'DUMP'; - } -} diff --git a/plugins/cache-redis/Predis/Command/KeyExists.php b/plugins/cache-redis/Predis/Command/KeyExists.php deleted file mode 100644 index 5196ca16b..000000000 --- a/plugins/cache-redis/Predis/Command/KeyExists.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/exists - * - * @author Daniele Alessandri - */ -class KeyExists extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'EXISTS'; - } - - /** - * {@inheritdoc} - */ - public function parseResponse($data) - { - return (bool) $data; - } -} diff --git a/plugins/cache-redis/Predis/Command/KeyExpire.php b/plugins/cache-redis/Predis/Command/KeyExpire.php deleted file mode 100644 index fd7c9c802..000000000 --- a/plugins/cache-redis/Predis/Command/KeyExpire.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/expire - * - * @author Daniele Alessandri - */ -class KeyExpire extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'EXPIRE'; - } - - /** - * {@inheritdoc} - */ - public function parseResponse($data) - { - return (bool) $data; - } -} diff --git a/plugins/cache-redis/Predis/Command/KeyExpireAt.php b/plugins/cache-redis/Predis/Command/KeyExpireAt.php deleted file mode 100644 index e2fe7aeb6..000000000 --- a/plugins/cache-redis/Predis/Command/KeyExpireAt.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/expireat - * - * @author Daniele Alessandri - */ -class KeyExpireAt extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'EXPIREAT'; - } - - /** - * {@inheritdoc} - */ - public function parseResponse($data) - { - return (bool) $data; - } -} diff --git a/plugins/cache-redis/Predis/Command/KeyKeys.php b/plugins/cache-redis/Predis/Command/KeyKeys.php deleted file mode 100644 index 6d74c40d2..000000000 --- a/plugins/cache-redis/Predis/Command/KeyKeys.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/keys - * - * @author Daniele Alessandri - */ -class KeyKeys extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'KEYS'; - } -} diff --git a/plugins/cache-redis/Predis/Command/KeyMigrate.php b/plugins/cache-redis/Predis/Command/KeyMigrate.php deleted file mode 100644 index 3324ef94c..000000000 --- a/plugins/cache-redis/Predis/Command/KeyMigrate.php +++ /dev/null @@ -1,50 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/migrate - * - * @author Daniele Alessandri - */ -class KeyMigrate extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'MIGRATE'; - } - - /** - * {@inheritdoc} - */ - protected function filterArguments(array $arguments) - { - if (is_array(end($arguments))) { - foreach (array_pop($arguments) as $modifier => $value) { - $modifier = strtoupper($modifier); - - if ($modifier === 'COPY' && $value == true) { - $arguments[] = $modifier; - } - - if ($modifier === 'REPLACE' && $value == true) { - $arguments[] = $modifier; - } - } - } - - return $arguments; - } -} diff --git a/plugins/cache-redis/Predis/Command/KeyMove.php b/plugins/cache-redis/Predis/Command/KeyMove.php deleted file mode 100644 index 8f1ab2a73..000000000 --- a/plugins/cache-redis/Predis/Command/KeyMove.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/move - * - * @author Daniele Alessandri - */ -class KeyMove extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'MOVE'; - } - - /** - * {@inheritdoc} - */ - public function parseResponse($data) - { - return (bool) $data; - } -} diff --git a/plugins/cache-redis/Predis/Command/KeyPersist.php b/plugins/cache-redis/Predis/Command/KeyPersist.php deleted file mode 100644 index e77295536..000000000 --- a/plugins/cache-redis/Predis/Command/KeyPersist.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/persist - * - * @author Daniele Alessandri - */ -class KeyPersist extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'PERSIST'; - } - - /** - * {@inheritdoc} - */ - public function parseResponse($data) - { - return (bool) $data; - } -} diff --git a/plugins/cache-redis/Predis/Command/KeyPreciseExpire.php b/plugins/cache-redis/Predis/Command/KeyPreciseExpire.php deleted file mode 100644 index 258ec4766..000000000 --- a/plugins/cache-redis/Predis/Command/KeyPreciseExpire.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/pexpire - * - * @author Daniele Alessandri - */ -class KeyPreciseExpire extends KeyExpire -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'PEXPIRE'; - } -} diff --git a/plugins/cache-redis/Predis/Command/KeyPreciseExpireAt.php b/plugins/cache-redis/Predis/Command/KeyPreciseExpireAt.php deleted file mode 100644 index e41921870..000000000 --- a/plugins/cache-redis/Predis/Command/KeyPreciseExpireAt.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/pexpireat - * - * @author Daniele Alessandri - */ -class KeyPreciseExpireAt extends KeyExpireAt -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'PEXPIREAT'; - } -} diff --git a/plugins/cache-redis/Predis/Command/KeyPreciseTimeToLive.php b/plugins/cache-redis/Predis/Command/KeyPreciseTimeToLive.php deleted file mode 100644 index bdcd34b92..000000000 --- a/plugins/cache-redis/Predis/Command/KeyPreciseTimeToLive.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/pttl - * - * @author Daniele Alessandri - */ -class KeyPreciseTimeToLive extends KeyTimeToLive -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'PTTL'; - } -} diff --git a/plugins/cache-redis/Predis/Command/KeyRandom.php b/plugins/cache-redis/Predis/Command/KeyRandom.php deleted file mode 100644 index b208b2db4..000000000 --- a/plugins/cache-redis/Predis/Command/KeyRandom.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/randomkey - * - * @author Daniele Alessandri - */ -class KeyRandom extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'RANDOMKEY'; - } - - /** - * {@inheritdoc} - */ - public function parseResponse($data) - { - return $data !== '' ? $data : null; - } -} diff --git a/plugins/cache-redis/Predis/Command/KeyRename.php b/plugins/cache-redis/Predis/Command/KeyRename.php deleted file mode 100644 index 82e44fb2e..000000000 --- a/plugins/cache-redis/Predis/Command/KeyRename.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/rename - * - * @author Daniele Alessandri - */ -class KeyRename extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'RENAME'; - } -} diff --git a/plugins/cache-redis/Predis/Command/KeyRenamePreserve.php b/plugins/cache-redis/Predis/Command/KeyRenamePreserve.php deleted file mode 100644 index 773ece6d3..000000000 --- a/plugins/cache-redis/Predis/Command/KeyRenamePreserve.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/renamenx - * - * @author Daniele Alessandri - */ -class KeyRenamePreserve extends KeyRename -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'RENAMENX'; - } - - /** - * {@inheritdoc} - */ - public function parseResponse($data) - { - return (bool) $data; - } -} diff --git a/plugins/cache-redis/Predis/Command/KeyRestore.php b/plugins/cache-redis/Predis/Command/KeyRestore.php deleted file mode 100644 index a5b0b2dbc..000000000 --- a/plugins/cache-redis/Predis/Command/KeyRestore.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/restore - * - * @author Daniele Alessandri - */ -class KeyRestore extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'RESTORE'; - } -} diff --git a/plugins/cache-redis/Predis/Command/KeyScan.php b/plugins/cache-redis/Predis/Command/KeyScan.php deleted file mode 100644 index 05f5bb3ac..000000000 --- a/plugins/cache-redis/Predis/Command/KeyScan.php +++ /dev/null @@ -1,66 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/scan - * - * @author Daniele Alessandri - */ -class KeyScan extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'SCAN'; - } - - /** - * {@inheritdoc} - */ - protected function filterArguments(array $arguments) - { - if (count($arguments) === 2 && is_array($arguments[1])) { - $options = $this->prepareOptions(array_pop($arguments)); - $arguments = array_merge($arguments, $options); - } - - return $arguments; - } - - /** - * Returns a list of options and modifiers compatible with Redis. - * - * @param array $options List of options. - * - * @return array - */ - protected function prepareOptions($options) - { - $options = array_change_key_case($options, CASE_UPPER); - $normalized = array(); - - if (!empty($options['MATCH'])) { - $normalized[] = 'MATCH'; - $normalized[] = $options['MATCH']; - } - - if (!empty($options['COUNT'])) { - $normalized[] = 'COUNT'; - $normalized[] = $options['COUNT']; - } - - return $normalized; - } -} diff --git a/plugins/cache-redis/Predis/Command/KeySort.php b/plugins/cache-redis/Predis/Command/KeySort.php deleted file mode 100644 index fd449f13d..000000000 --- a/plugins/cache-redis/Predis/Command/KeySort.php +++ /dev/null @@ -1,83 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/sort - * - * @author Daniele Alessandri - */ -class KeySort extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'SORT'; - } - - /** - * {@inheritdoc} - */ - protected function filterArguments(array $arguments) - { - if (count($arguments) === 1) { - return $arguments; - } - - $query = array($arguments[0]); - $sortParams = array_change_key_case($arguments[1], CASE_UPPER); - - if (isset($sortParams['BY'])) { - $query[] = 'BY'; - $query[] = $sortParams['BY']; - } - - if (isset($sortParams['GET'])) { - $getargs = $sortParams['GET']; - - if (is_array($getargs)) { - foreach ($getargs as $getarg) { - $query[] = 'GET'; - $query[] = $getarg; - } - } else { - $query[] = 'GET'; - $query[] = $getargs; - } - } - - if (isset($sortParams['LIMIT']) && - is_array($sortParams['LIMIT']) && - count($sortParams['LIMIT']) == 2) { - $query[] = 'LIMIT'; - $query[] = $sortParams['LIMIT'][0]; - $query[] = $sortParams['LIMIT'][1]; - } - - if (isset($sortParams['SORT'])) { - $query[] = strtoupper($sortParams['SORT']); - } - - if (isset($sortParams['ALPHA']) && $sortParams['ALPHA'] == true) { - $query[] = 'ALPHA'; - } - - if (isset($sortParams['STORE'])) { - $query[] = 'STORE'; - $query[] = $sortParams['STORE']; - } - - return $query; - } -} diff --git a/plugins/cache-redis/Predis/Command/KeyTimeToLive.php b/plugins/cache-redis/Predis/Command/KeyTimeToLive.php deleted file mode 100644 index 67697a6fb..000000000 --- a/plugins/cache-redis/Predis/Command/KeyTimeToLive.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/ttl - * - * @author Daniele Alessandri - */ -class KeyTimeToLive extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'TTL'; - } -} diff --git a/plugins/cache-redis/Predis/Command/KeyType.php b/plugins/cache-redis/Predis/Command/KeyType.php deleted file mode 100644 index f4f06e451..000000000 --- a/plugins/cache-redis/Predis/Command/KeyType.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/type - * - * @author Daniele Alessandri - */ -class KeyType extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'TYPE'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ListIndex.php b/plugins/cache-redis/Predis/Command/ListIndex.php deleted file mode 100644 index 27c64be73..000000000 --- a/plugins/cache-redis/Predis/Command/ListIndex.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/lindex - * - * @author Daniele Alessandri - */ -class ListIndex extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'LINDEX'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ListInsert.php b/plugins/cache-redis/Predis/Command/ListInsert.php deleted file mode 100644 index 7d53d11b2..000000000 --- a/plugins/cache-redis/Predis/Command/ListInsert.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/linsert - * - * @author Daniele Alessandri - */ -class ListInsert extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'LINSERT'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ListLength.php b/plugins/cache-redis/Predis/Command/ListLength.php deleted file mode 100644 index 6495beb77..000000000 --- a/plugins/cache-redis/Predis/Command/ListLength.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/llen - * - * @author Daniele Alessandri - */ -class ListLength extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'LLEN'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ListPopFirst.php b/plugins/cache-redis/Predis/Command/ListPopFirst.php deleted file mode 100644 index 84d5d6734..000000000 --- a/plugins/cache-redis/Predis/Command/ListPopFirst.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/lpop - * - * @author Daniele Alessandri - */ -class ListPopFirst extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'LPOP'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ListPopFirstBlocking.php b/plugins/cache-redis/Predis/Command/ListPopFirstBlocking.php deleted file mode 100644 index 7dc7c0002..000000000 --- a/plugins/cache-redis/Predis/Command/ListPopFirstBlocking.php +++ /dev/null @@ -1,41 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/blpop - * - * @author Daniele Alessandri - */ -class ListPopFirstBlocking extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'BLPOP'; - } - - /** - * {@inheritdoc} - */ - protected function filterArguments(array $arguments) - { - if (count($arguments) === 2 && is_array($arguments[0])) { - list($arguments, $timeout) = $arguments; - array_push($arguments, $timeout); - } - - return $arguments; - } -} diff --git a/plugins/cache-redis/Predis/Command/ListPopLast.php b/plugins/cache-redis/Predis/Command/ListPopLast.php deleted file mode 100644 index 9e92db5f4..000000000 --- a/plugins/cache-redis/Predis/Command/ListPopLast.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/rpop - * - * @author Daniele Alessandri - */ -class ListPopLast extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'RPOP'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ListPopLastBlocking.php b/plugins/cache-redis/Predis/Command/ListPopLastBlocking.php deleted file mode 100644 index 781eb9192..000000000 --- a/plugins/cache-redis/Predis/Command/ListPopLastBlocking.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/brpop - * - * @author Daniele Alessandri - */ -class ListPopLastBlocking extends ListPopFirstBlocking -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'BRPOP'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ListPopLastPushHead.php b/plugins/cache-redis/Predis/Command/ListPopLastPushHead.php deleted file mode 100644 index f430eb227..000000000 --- a/plugins/cache-redis/Predis/Command/ListPopLastPushHead.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/rpoplpush - * - * @author Daniele Alessandri - */ -class ListPopLastPushHead extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'RPOPLPUSH'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ListPopLastPushHeadBlocking.php b/plugins/cache-redis/Predis/Command/ListPopLastPushHeadBlocking.php deleted file mode 100644 index ee9c93c85..000000000 --- a/plugins/cache-redis/Predis/Command/ListPopLastPushHeadBlocking.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/brpoplpush - * - * @author Daniele Alessandri - */ -class ListPopLastPushHeadBlocking extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'BRPOPLPUSH'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ListPushHead.php b/plugins/cache-redis/Predis/Command/ListPushHead.php deleted file mode 100644 index 74bf7c491..000000000 --- a/plugins/cache-redis/Predis/Command/ListPushHead.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/lpush - * - * @author Daniele Alessandri - */ -class ListPushHead extends ListPushTail -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'LPUSH'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ListPushHeadX.php b/plugins/cache-redis/Predis/Command/ListPushHeadX.php deleted file mode 100644 index 8e136b880..000000000 --- a/plugins/cache-redis/Predis/Command/ListPushHeadX.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/lpushx - * - * @author Daniele Alessandri - */ -class ListPushHeadX extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'LPUSHX'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ListPushTail.php b/plugins/cache-redis/Predis/Command/ListPushTail.php deleted file mode 100644 index f2a057c0b..000000000 --- a/plugins/cache-redis/Predis/Command/ListPushTail.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/rpush - * - * @author Daniele Alessandri - */ -class ListPushTail extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'RPUSH'; - } - - /** - * {@inheritdoc} - */ - protected function filterArguments(array $arguments) - { - return self::normalizeVariadic($arguments); - } -} diff --git a/plugins/cache-redis/Predis/Command/ListPushTailX.php b/plugins/cache-redis/Predis/Command/ListPushTailX.php deleted file mode 100644 index 1af3645b4..000000000 --- a/plugins/cache-redis/Predis/Command/ListPushTailX.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/rpushx - * - * @author Daniele Alessandri - */ -class ListPushTailX extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'RPUSHX'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ListRange.php b/plugins/cache-redis/Predis/Command/ListRange.php deleted file mode 100644 index 32a21a6e6..000000000 --- a/plugins/cache-redis/Predis/Command/ListRange.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/lrange - * - * @author Daniele Alessandri - */ -class ListRange extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'LRANGE'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ListRemove.php b/plugins/cache-redis/Predis/Command/ListRemove.php deleted file mode 100644 index c5800899b..000000000 --- a/plugins/cache-redis/Predis/Command/ListRemove.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/lrem - * - * @author Daniele Alessandri - */ -class ListRemove extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'LREM'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ListSet.php b/plugins/cache-redis/Predis/Command/ListSet.php deleted file mode 100644 index 5e59864de..000000000 --- a/plugins/cache-redis/Predis/Command/ListSet.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/lset - * - * @author Daniele Alessandri - */ -class ListSet extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'LSET'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ListTrim.php b/plugins/cache-redis/Predis/Command/ListTrim.php deleted file mode 100644 index 193141809..000000000 --- a/plugins/cache-redis/Predis/Command/ListTrim.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/ltrim - * - * @author Daniele Alessandri - */ -class ListTrim extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'LTRIM'; - } -} diff --git a/plugins/cache-redis/Predis/Command/PrefixableCommandInterface.php b/plugins/cache-redis/Predis/Command/PrefixableCommandInterface.php index 6d54554fa..66b5d19c2 100644 --- a/plugins/cache-redis/Predis/Command/PrefixableCommandInterface.php +++ b/plugins/cache-redis/Predis/Command/PrefixableCommandInterface.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,8 +14,6 @@ namespace Predis\Command; /** * Defines a command whose keys can be prefixed. - * - * @author Daniele Alessandri */ interface PrefixableCommandInterface extends CommandInterface { diff --git a/plugins/cache-redis/Predis/Command/Processor/KeyPrefixProcessor.php b/plugins/cache-redis/Predis/Command/Processor/KeyPrefixProcessor.php index d966d0e10..d7a30c880 100644 --- a/plugins/cache-redis/Predis/Command/Processor/KeyPrefixProcessor.php +++ b/plugins/cache-redis/Predis/Command/Processor/KeyPrefixProcessor.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,14 +12,13 @@ namespace Predis\Command\Processor; +use InvalidArgumentException; use Predis\Command\CommandInterface; use Predis\Command\PrefixableCommandInterface; /** * Command processor capable of prefixing keys stored in the arguments of Redis * commands supported. - * - * @author Daniele Alessandri */ class KeyPrefixProcessor implements ProcessorInterface { @@ -31,135 +31,270 @@ class KeyPrefixProcessor implements ProcessorInterface public function __construct($prefix) { $this->prefix = $prefix; - $this->commands = array( + + $prefixFirst = static::class . '::first'; + $prefixAll = static::class . '::all'; + $prefixInterleaved = static::class . '::interleaved'; + $prefixSkipFirst = static::class . '::skipFirst'; + $prefixSkipLast = static::class . '::skipLast'; + $prefixSort = static::class . '::sort'; + $prefixEvalKeys = static::class . '::evalKeys'; + $prefixZsetStore = static::class . '::zsetStore'; + $prefixMigrate = static::class . '::migrate'; + $prefixGeoradius = static::class . '::georadius'; + + $this->commands = [ /* ---------------- Redis 1.2 ---------------- */ - 'EXISTS' => 'static::first', - 'DEL' => 'static::all', - 'TYPE' => 'static::first', - 'KEYS' => 'static::first', - 'RENAME' => 'static::all', - 'RENAMENX' => 'static::all', - 'EXPIRE' => 'static::first', - 'EXPIREAT' => 'static::first', - 'TTL' => 'static::first', - 'MOVE' => 'static::first', - 'SORT' => 'static::sort', - 'DUMP' => 'static::first', - 'RESTORE' => 'static::first', - 'SET' => 'static::first', - 'SETNX' => 'static::first', - 'MSET' => 'static::interleaved', - 'MSETNX' => 'static::interleaved', - 'GET' => 'static::first', - 'MGET' => 'static::all', - 'GETSET' => 'static::first', - 'INCR' => 'static::first', - 'INCRBY' => 'static::first', - 'DECR' => 'static::first', - 'DECRBY' => 'static::first', - 'RPUSH' => 'static::first', - 'LPUSH' => 'static::first', - 'LLEN' => 'static::first', - 'LRANGE' => 'static::first', - 'LTRIM' => 'static::first', - 'LINDEX' => 'static::first', - 'LSET' => 'static::first', - 'LREM' => 'static::first', - 'LPOP' => 'static::first', - 'RPOP' => 'static::first', - 'RPOPLPUSH' => 'static::all', - 'SADD' => 'static::first', - 'SREM' => 'static::first', - 'SPOP' => 'static::first', - 'SMOVE' => 'static::skipLast', - 'SCARD' => 'static::first', - 'SISMEMBER' => 'static::first', - 'SINTER' => 'static::all', - 'SINTERSTORE' => 'static::all', - 'SUNION' => 'static::all', - 'SUNIONSTORE' => 'static::all', - 'SDIFF' => 'static::all', - 'SDIFFSTORE' => 'static::all', - 'SMEMBERS' => 'static::first', - 'SRANDMEMBER' => 'static::first', - 'ZADD' => 'static::first', - 'ZINCRBY' => 'static::first', - 'ZREM' => 'static::first', - 'ZRANGE' => 'static::first', - 'ZREVRANGE' => 'static::first', - 'ZRANGEBYSCORE' => 'static::first', - 'ZCARD' => 'static::first', - 'ZSCORE' => 'static::first', - 'ZREMRANGEBYSCORE' => 'static::first', + 'EXISTS' => $prefixAll, + 'DEL' => $prefixAll, + 'TYPE' => $prefixFirst, + 'KEYS' => $prefixFirst, + 'RENAME' => $prefixAll, + 'RENAMENX' => $prefixAll, + 'EXPIRE' => $prefixFirst, + 'EXPIREAT' => $prefixFirst, + 'TTL' => $prefixFirst, + 'MOVE' => $prefixFirst, + 'SORT' => $prefixSort, + 'DUMP' => $prefixFirst, + 'RESTORE' => $prefixFirst, + 'SET' => $prefixFirst, + 'SETNX' => $prefixFirst, + 'MSET' => $prefixInterleaved, + 'MSETNX' => $prefixInterleaved, + 'GET' => $prefixFirst, + 'MGET' => $prefixAll, + 'GETSET' => $prefixFirst, + 'INCR' => $prefixFirst, + 'INCRBY' => $prefixFirst, + 'DECR' => $prefixFirst, + 'DECRBY' => $prefixFirst, + 'RPUSH' => $prefixFirst, + 'LPUSH' => $prefixFirst, + 'LLEN' => $prefixFirst, + 'LRANGE' => $prefixFirst, + 'LTRIM' => $prefixFirst, + 'LINDEX' => $prefixFirst, + 'LSET' => $prefixFirst, + 'LREM' => $prefixFirst, + 'LPOP' => $prefixFirst, + 'RPOP' => $prefixFirst, + 'RPOPLPUSH' => $prefixAll, + 'SADD' => $prefixFirst, + 'SREM' => $prefixFirst, + 'SPOP' => $prefixFirst, + 'SMOVE' => $prefixSkipLast, + 'SCARD' => $prefixFirst, + 'SISMEMBER' => $prefixFirst, + 'SINTER' => $prefixAll, + 'SINTERSTORE' => $prefixAll, + 'SUNION' => $prefixAll, + 'SUNIONSTORE' => $prefixAll, + 'SDIFF' => $prefixAll, + 'SDIFFSTORE' => $prefixAll, + 'SMEMBERS' => $prefixFirst, + 'SRANDMEMBER' => $prefixFirst, + 'ZADD' => $prefixFirst, + 'ZINCRBY' => $prefixFirst, + 'ZREM' => $prefixFirst, + 'ZRANGE' => $prefixFirst, + 'ZREVRANGE' => $prefixFirst, + 'ZRANGEBYSCORE' => $prefixFirst, + 'ZCARD' => $prefixFirst, + 'ZSCORE' => $prefixFirst, + 'ZREMRANGEBYSCORE' => $prefixFirst, /* ---------------- Redis 2.0 ---------------- */ - 'SETEX' => 'static::first', - 'APPEND' => 'static::first', - 'SUBSTR' => 'static::first', - 'BLPOP' => 'static::skipLast', - 'BRPOP' => 'static::skipLast', - 'ZUNIONSTORE' => 'static::zsetStore', - 'ZINTERSTORE' => 'static::zsetStore', - 'ZCOUNT' => 'static::first', - 'ZRANK' => 'static::first', - 'ZREVRANK' => 'static::first', - 'ZREMRANGEBYRANK' => 'static::first', - 'HSET' => 'static::first', - 'HSETNX' => 'static::first', - 'HMSET' => 'static::first', - 'HINCRBY' => 'static::first', - 'HGET' => 'static::first', - 'HMGET' => 'static::first', - 'HDEL' => 'static::first', - 'HEXISTS' => 'static::first', - 'HLEN' => 'static::first', - 'HKEYS' => 'static::first', - 'HVALS' => 'static::first', - 'HGETALL' => 'static::first', - 'SUBSCRIBE' => 'static::all', - 'UNSUBSCRIBE' => 'static::all', - 'PSUBSCRIBE' => 'static::all', - 'PUNSUBSCRIBE' => 'static::all', - 'PUBLISH' => 'static::first', + 'SETEX' => $prefixFirst, + 'APPEND' => $prefixFirst, + 'SUBSTR' => $prefixFirst, + 'BLPOP' => $prefixSkipLast, + 'BRPOP' => $prefixSkipLast, + 'ZUNIONSTORE' => $prefixZsetStore, + 'ZINTERSTORE' => $prefixZsetStore, + 'ZCOUNT' => $prefixFirst, + 'ZRANK' => $prefixFirst, + 'ZREVRANK' => $prefixFirst, + 'ZREMRANGEBYRANK' => $prefixFirst, + 'HSET' => $prefixFirst, + 'HSETNX' => $prefixFirst, + 'HMSET' => $prefixFirst, + 'HINCRBY' => $prefixFirst, + 'HGET' => $prefixFirst, + 'HMGET' => $prefixFirst, + 'HDEL' => $prefixFirst, + 'HEXISTS' => $prefixFirst, + 'HLEN' => $prefixFirst, + 'HKEYS' => $prefixFirst, + 'HVALS' => $prefixFirst, + 'HGETALL' => $prefixFirst, + 'SUBSCRIBE' => $prefixAll, + 'UNSUBSCRIBE' => $prefixAll, + 'PSUBSCRIBE' => $prefixAll, + 'PUNSUBSCRIBE' => $prefixAll, + 'PUBLISH' => $prefixFirst, /* ---------------- Redis 2.2 ---------------- */ - 'PERSIST' => 'static::first', - 'STRLEN' => 'static::first', - 'SETRANGE' => 'static::first', - 'GETRANGE' => 'static::first', - 'SETBIT' => 'static::first', - 'GETBIT' => 'static::first', - 'RPUSHX' => 'static::first', - 'LPUSHX' => 'static::first', - 'LINSERT' => 'static::first', - 'BRPOPLPUSH' => 'static::skipLast', - 'ZREVRANGEBYSCORE' => 'static::first', - 'WATCH' => 'static::all', + 'PERSIST' => $prefixFirst, + 'STRLEN' => $prefixFirst, + 'SETRANGE' => $prefixFirst, + 'GETRANGE' => $prefixFirst, + 'SETBIT' => $prefixFirst, + 'GETBIT' => $prefixFirst, + 'RPUSHX' => $prefixFirst, + 'LPUSHX' => $prefixFirst, + 'LINSERT' => $prefixFirst, + 'BRPOPLPUSH' => $prefixSkipLast, + 'ZREVRANGEBYSCORE' => $prefixFirst, + 'WATCH' => $prefixAll, /* ---------------- Redis 2.6 ---------------- */ - 'PTTL' => 'static::first', - 'PEXPIRE' => 'static::first', - 'PEXPIREAT' => 'static::first', - 'PSETEX' => 'static::first', - 'INCRBYFLOAT' => 'static::first', - 'BITOP' => 'static::skipFirst', - 'BITCOUNT' => 'static::first', - 'HINCRBYFLOAT' => 'static::first', - 'EVAL' => 'static::evalKeys', - 'EVALSHA' => 'static::evalKeys', - 'MIGRATE' => 'static::migrate', + 'PTTL' => $prefixFirst, + 'PEXPIRE' => $prefixFirst, + 'PEXPIREAT' => $prefixFirst, + 'PSETEX' => $prefixFirst, + 'INCRBYFLOAT' => $prefixFirst, + 'BITOP' => $prefixSkipFirst, + 'BITCOUNT' => $prefixFirst, + 'HINCRBYFLOAT' => $prefixFirst, + 'EVAL' => $prefixEvalKeys, + 'EVALSHA' => $prefixEvalKeys, + 'MIGRATE' => $prefixMigrate, /* ---------------- Redis 2.8 ---------------- */ - 'SSCAN' => 'static::first', - 'ZSCAN' => 'static::first', - 'HSCAN' => 'static::first', - 'PFADD' => 'static::first', - 'PFCOUNT' => 'static::all', - 'PFMERGE' => 'static::all', - 'ZLEXCOUNT' => 'static::first', - 'ZRANGEBYLEX' => 'static::first', - 'ZREMRANGEBYLEX' => 'static::first', - 'ZREVRANGEBYLEX' => 'static::first', - 'BITPOS' => 'static::first', + 'SSCAN' => $prefixFirst, + 'ZSCAN' => $prefixFirst, + 'HSCAN' => $prefixFirst, + 'PFADD' => $prefixFirst, + 'PFCOUNT' => $prefixAll, + 'PFMERGE' => $prefixAll, + 'ZLEXCOUNT' => $prefixFirst, + 'ZRANGEBYLEX' => $prefixFirst, + 'ZREMRANGEBYLEX' => $prefixFirst, + 'ZREVRANGEBYLEX' => $prefixFirst, + 'BITPOS' => $prefixFirst, /* ---------------- Redis 3.2 ---------------- */ - 'HSTRLEN' => 'static::first', - ); + 'HSTRLEN' => $prefixFirst, + 'BITFIELD' => $prefixFirst, + 'GEOADD' => $prefixFirst, + 'GEOHASH' => $prefixFirst, + 'GEOPOS' => $prefixFirst, + 'GEODIST' => $prefixFirst, + 'GEORADIUS' => $prefixGeoradius, + 'GEORADIUSBYMEMBER' => $prefixGeoradius, + /* ---------------- Redis 5.0 ---------------- */ + 'XADD' => $prefixFirst, + 'XRANGE' => $prefixFirst, + 'XREVRANGE' => $prefixFirst, + 'XDEL' => $prefixFirst, + 'XLEN' => $prefixFirst, + 'XACK' => $prefixFirst, + 'XTRIM' => $prefixFirst, + + /* ---------------- Redis 6.2 ---------------- */ + 'GETDEL' => $prefixFirst, + + /* ---------------- Redis 7.0 ---------------- */ + 'EXPIRETIME' => $prefixFirst, + + /* RedisJSON */ + 'JSON.ARRAPPEND' => $prefixFirst, + 'JSON.ARRINDEX' => $prefixFirst, + 'JSON.ARRINSERT' => $prefixFirst, + 'JSON.ARRLEN' => $prefixFirst, + 'JSON.ARRPOP' => $prefixFirst, + 'JSON.ARRTRIM' => $prefixFirst, + 'JSON.CLEAR' => $prefixFirst, + 'JSON.DEBUG MEMORY' => $prefixFirst, + 'JSON.DEL' => $prefixFirst, + 'JSON.FORGET' => $prefixFirst, + 'JSON.GET' => $prefixFirst, + 'JSON.MGET' => $prefixAll, + 'JSON.NUMINCRBY' => $prefixFirst, + 'JSON.OBJKEYS' => $prefixFirst, + 'JSON.OBJLEN' => $prefixFirst, + 'JSON.RESP' => $prefixFirst, + 'JSON.SET' => $prefixFirst, + 'JSON.STRAPPEND' => $prefixFirst, + 'JSON.STRLEN' => $prefixFirst, + 'JSON.TOGGLE' => $prefixFirst, + 'JSON.TYPE' => $prefixFirst, + + /* RedisBloom */ + 'BF.ADD' => $prefixFirst, + 'BF.EXISTS' => $prefixFirst, + 'BF.INFO' => $prefixFirst, + 'BF.INSERT' => $prefixFirst, + 'BF.LOADCHUNK' => $prefixFirst, + 'BF.MADD' => $prefixFirst, + 'BF.MEXISTS' => $prefixFirst, + 'BF.RESERVE' => $prefixFirst, + 'BF.SCANDUMP' => $prefixFirst, + 'CF.ADD' => $prefixFirst, + 'CF.ADDNX' => $prefixFirst, + 'CF.COUNT' => $prefixFirst, + 'CF.DEL' => $prefixFirst, + 'CF.EXISTS' => $prefixFirst, + 'CF.INFO' => $prefixFirst, + 'CF.INSERT' => $prefixFirst, + 'CF.INSERTNX' => $prefixFirst, + 'CF.LOADCHUNK' => $prefixFirst, + 'CF.MEXISTS' => $prefixFirst, + 'CF.RESERVE' => $prefixFirst, + 'CF.SCANDUMP' => $prefixFirst, + 'CMS.INCRBY' => $prefixFirst, + 'CMS.INFO' => $prefixFirst, + 'CMS.INITBYDIM' => $prefixFirst, + 'CMS.INITBYPROB' => $prefixFirst, + 'CMS.QUERY' => $prefixFirst, + 'TDIGEST.ADD' => $prefixFirst, + 'TDIGEST.BYRANK' => $prefixFirst, + 'TDIGEST.BYREVRANK' => $prefixFirst, + 'TDIGEST.CDF' => $prefixFirst, + 'TDIGEST.CREATE' => $prefixFirst, + 'TDIGEST.INFO' => $prefixFirst, + 'TDIGEST.MAX' => $prefixFirst, + 'TDIGEST.MIN' => $prefixFirst, + 'TDIGEST.QUANTILE' => $prefixFirst, + 'TDIGEST.RANK' => $prefixFirst, + 'TDIGEST.RESET' => $prefixFirst, + 'TDIGEST.REVRANK' => $prefixFirst, + 'TDIGEST.TRIMMED_MEAN' => $prefixFirst, + 'TOPK.ADD' => $prefixFirst, + 'TOPK.INCRBY' => $prefixFirst, + 'TOPK.INFO' => $prefixFirst, + 'TOPK.LIST' => $prefixFirst, + 'TOPK.QUERY' => $prefixFirst, + 'TOPK.RESERVE' => $prefixFirst, + + /* RediSearch */ + 'FT.AGGREGATE' => $prefixFirst, + 'FT.ALTER' => $prefixFirst, + 'FT.CREATE' => $prefixFirst, + 'FT.CURSOR DEL' => $prefixFirst, + 'FT.CURSOR READ' => $prefixFirst, + 'FT.DROPINDEX' => $prefixFirst, + 'FT.EXPLAIN' => $prefixFirst, + 'FT.INFO' => $prefixFirst, + 'FT.PROFILE' => $prefixFirst, + 'FT.SEARCH' => $prefixFirst, + 'FT.SPELLCHECK' => $prefixFirst, + 'FT.SYNDUMP' => $prefixFirst, + 'FT.SYNUPDATE' => $prefixFirst, + 'FT.TAGVALS' => $prefixFirst, + + /* Redis TimeSeries */ + 'TS.ADD' => $prefixFirst, + 'TS.ALTER' => $prefixFirst, + 'TS.CREATE' => $prefixFirst, + 'TS.DECRBY' => $prefixFirst, + 'TS.DEL' => $prefixFirst, + 'TS.GET' => $prefixFirst, + 'TS.INCRBY' => $prefixFirst, + 'TS.INFO' => $prefixFirst, + 'TS.MGET' => $prefixFirst, + 'TS.MRANGE' => $prefixFirst, + 'TS.MREVRANGE' => $prefixFirst, + 'TS.QUERYINDEX' => $prefixFirst, + 'TS.RANGE' => $prefixFirst, + 'TS.REVRANGE' => $prefixFirst, + ]; } /** @@ -190,7 +325,7 @@ class KeyPrefixProcessor implements ProcessorInterface if ($command instanceof PrefixableCommandInterface) { $command->prefixKeys($this->prefix); } elseif (isset($this->commands[$commandID = strtoupper($command->getId())])) { - call_user_func($this->commands[$commandID], $command, $this->prefix); + $this->commands[$commandID]($command, $this->prefix); } } @@ -208,7 +343,7 @@ class KeyPrefixProcessor implements ProcessorInterface * @param string $commandID The ID of the command to be handled. * @param mixed $callback A valid callable object or NULL. * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ public function setCommandHandler($commandID, $callback = null) { @@ -221,7 +356,7 @@ class KeyPrefixProcessor implements ProcessorInterface } if (!is_callable($callback)) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Callback must be a valid callable object or NULL' ); } @@ -338,7 +473,7 @@ class KeyPrefixProcessor implements ProcessorInterface if (($count = count($arguments)) > 1) { for ($i = 1; $i < $count; ++$i) { - switch ($arguments[$i]) { + switch (strtoupper($arguments[$i])) { case 'BY': case 'STORE': $arguments[$i] = "$prefix{$arguments[++$i]}"; @@ -351,7 +486,7 @@ class KeyPrefixProcessor implements ProcessorInterface } break; - case 'LIMIT'; + case 'LIMIT': $i += 2; break; } @@ -412,4 +547,31 @@ class KeyPrefixProcessor implements ProcessorInterface $command->setRawArguments($arguments); } } + + /** + * Applies the specified prefix to the key of a GEORADIUS command. + * + * @param CommandInterface $command Command instance. + * @param string $prefix Prefix string. + */ + public static function georadius(CommandInterface $command, $prefix) + { + if ($arguments = $command->getArguments()) { + $arguments[0] = "$prefix{$arguments[0]}"; + $startIndex = $command->getId() === 'GEORADIUS' ? 5 : 4; + + if (($count = count($arguments)) > $startIndex) { + for ($i = $startIndex; $i < $count; ++$i) { + switch (strtoupper($arguments[$i])) { + case 'STORE': + case 'STOREDIST': + $arguments[$i] = "$prefix{$arguments[++$i]}"; + break; + } + } + } + + $command->setRawArguments($arguments); + } + } } diff --git a/plugins/cache-redis/Predis/Command/Processor/ProcessorChain.php b/plugins/cache-redis/Predis/Command/Processor/ProcessorChain.php index 0a4768b0a..1ce915e2b 100644 --- a/plugins/cache-redis/Predis/Command/Processor/ProcessorChain.php +++ b/plugins/cache-redis/Predis/Command/Processor/ProcessorChain.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,21 +12,24 @@ namespace Predis\Command\Processor; +use ArrayAccess; +use ArrayIterator; +use InvalidArgumentException; use Predis\Command\CommandInterface; +use ReturnTypeWillChange; +use Traversable; /** * Default implementation of a command processors chain. - * - * @author Daniele Alessandri */ -class ProcessorChain implements \ArrayAccess, ProcessorInterface +class ProcessorChain implements ArrayAccess, ProcessorInterface { - private $processors = array(); + private $processors = []; /** * @param array $processors List of instances of ProcessorInterface. */ - public function __construct($processors = array()) + public function __construct($processors = []) { foreach ($processors as $processor) { $this->add($processor); @@ -71,11 +75,11 @@ class ProcessorChain implements \ArrayAccess, ProcessorInterface /** * Returns an iterator over the list of command processor in the chain. * - * @return \ArrayIterator + * @return Traversable */ public function getIterator() { - return new \ArrayIterator($this->processors); + return new ArrayIterator($this->processors); } /** @@ -89,30 +93,36 @@ class ProcessorChain implements \ArrayAccess, ProcessorInterface } /** - * {@inheritdoc} + * @param int $index + * @return bool */ + #[ReturnTypeWillChange] public function offsetExists($index) { return isset($this->processors[$index]); } /** - * {@inheritdoc} + * @param int $index + * @return ProcessorInterface */ + #[ReturnTypeWillChange] public function offsetGet($index) { return $this->processors[$index]; } /** - * {@inheritdoc} + * @param int $index + * @param ProcessorInterface $processor + * @return void */ + #[ReturnTypeWillChange] public function offsetSet($index, $processor) { if (!$processor instanceof ProcessorInterface) { - throw new \InvalidArgumentException( - 'A processor chain accepts only instances of '. - "'Predis\Command\Processor\ProcessorInterface'." + throw new InvalidArgumentException( + 'Processor chain accepts only instances of `Predis\Command\Processor\ProcessorInterface`' ); } @@ -120,8 +130,10 @@ class ProcessorChain implements \ArrayAccess, ProcessorInterface } /** - * {@inheritdoc} + * @param int $index + * @return void */ + #[ReturnTypeWillChange] public function offsetUnset($index) { unset($this->processors[$index]); diff --git a/plugins/cache-redis/Predis/Command/Processor/ProcessorInterface.php b/plugins/cache-redis/Predis/Command/Processor/ProcessorInterface.php index 2f9105802..f915b9eb6 100644 --- a/plugins/cache-redis/Predis/Command/Processor/ProcessorInterface.php +++ b/plugins/cache-redis/Predis/Command/Processor/ProcessorInterface.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -15,8 +16,6 @@ use Predis\Command\CommandInterface; /** * A command processor processes Redis commands before they are sent to Redis. - * - * @author Daniele Alessandri */ interface ProcessorInterface { diff --git a/plugins/cache-redis/Predis/Command/PubSubPublish.php b/plugins/cache-redis/Predis/Command/PubSubPublish.php deleted file mode 100644 index 55508f8d9..000000000 --- a/plugins/cache-redis/Predis/Command/PubSubPublish.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/publish - * - * @author Daniele Alessandri - */ -class PubSubPublish extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'PUBLISH'; - } -} diff --git a/plugins/cache-redis/Predis/Command/PubSubPubsub.php b/plugins/cache-redis/Predis/Command/PubSubPubsub.php deleted file mode 100644 index 8cf812973..000000000 --- a/plugins/cache-redis/Predis/Command/PubSubPubsub.php +++ /dev/null @@ -1,61 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/pubsub - * - * @author Daniele Alessandri - */ -class PubSubPubsub extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'PUBSUB'; - } - - /** - * {@inheritdoc} - */ - public function parseResponse($data) - { - switch (strtolower($this->getArgument(0))) { - case 'numsub': - return self::processNumsub($data); - - default: - return $data; - } - } - - /** - * Returns the processed response to PUBSUB NUMSUB. - * - * @param array $channels List of channels - * - * @return array - */ - protected static function processNumsub(array $channels) - { - $processed = array(); - $count = count($channels); - - for ($i = 0; $i < $count; ++$i) { - $processed[$channels[$i]] = $channels[++$i]; - } - - return $processed; - } -} diff --git a/plugins/cache-redis/Predis/Command/PubSubSubscribe.php b/plugins/cache-redis/Predis/Command/PubSubSubscribe.php deleted file mode 100644 index e477b313b..000000000 --- a/plugins/cache-redis/Predis/Command/PubSubSubscribe.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/subscribe - * - * @author Daniele Alessandri - */ -class PubSubSubscribe extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'SUBSCRIBE'; - } - - /** - * {@inheritdoc} - */ - protected function filterArguments(array $arguments) - { - return self::normalizeArguments($arguments); - } -} diff --git a/plugins/cache-redis/Predis/Command/PubSubSubscribeByPattern.php b/plugins/cache-redis/Predis/Command/PubSubSubscribeByPattern.php deleted file mode 100644 index 011828066..000000000 --- a/plugins/cache-redis/Predis/Command/PubSubSubscribeByPattern.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/psubscribe - * - * @author Daniele Alessandri - */ -class PubSubSubscribeByPattern extends PubSubSubscribe -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'PSUBSCRIBE'; - } -} diff --git a/plugins/cache-redis/Predis/Command/PubSubUnsubscribe.php b/plugins/cache-redis/Predis/Command/PubSubUnsubscribe.php deleted file mode 100644 index d57c3ac6d..000000000 --- a/plugins/cache-redis/Predis/Command/PubSubUnsubscribe.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/unsubscribe - * - * @author Daniele Alessandri - */ -class PubSubUnsubscribe extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'UNSUBSCRIBE'; - } - - /** - * {@inheritdoc} - */ - protected function filterArguments(array $arguments) - { - return self::normalizeArguments($arguments); - } -} diff --git a/plugins/cache-redis/Predis/Command/PubSubUnsubscribeByPattern.php b/plugins/cache-redis/Predis/Command/PubSubUnsubscribeByPattern.php deleted file mode 100644 index 4d76508b2..000000000 --- a/plugins/cache-redis/Predis/Command/PubSubUnsubscribeByPattern.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/punsubscribe - * - * @author Daniele Alessandri - */ -class PubSubUnsubscribeByPattern extends PubSubUnsubscribe -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'PUNSUBSCRIBE'; - } -} diff --git a/plugins/cache-redis/Predis/Command/RawCommand.php b/plugins/cache-redis/Predis/Command/RawCommand.php index 2dd48ca17..61b223112 100644 --- a/plugins/cache-redis/Predis/Command/RawCommand.php +++ b/plugins/cache-redis/Predis/Command/RawCommand.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -12,52 +13,45 @@ namespace Predis\Command; /** - * Class for generic "anonymous" Redis commands. + * Class representing a generic Redis command. * - * This command class does not filter input arguments or parse responses, but - * can be used to leverage the standard Predis API to execute any command simply - * by providing the needed arguments following the command signature as defined - * by Redis in its documentation. + * Arguments and responses for these commands are not normalized and they follow + * what is defined by the Redis documentation. * - * @author Daniele Alessandri + * Raw commands can be useful when implementing higher level abstractions on top + * of Predis\Client or managing internals like Redis Sentinel or Cluster as they + * are not potentially subject to hijacking from third party libraries when they + * override command handlers for standard Redis commands. */ -class RawCommand implements CommandInterface +final class RawCommand implements CommandInterface { private $slot; private $commandID; private $arguments; /** - * @param array $arguments Command ID and its arguments. - * - * @throws \InvalidArgumentException + * @param string $commandID Command ID + * @param array $arguments Command arguments */ - public function __construct(array $arguments) + public function __construct($commandID, array $arguments = []) { - if (!$arguments) { - throw new \InvalidArgumentException( - 'The arguments array must contain at least the command ID.' - ); - } - - $this->commandID = strtoupper(array_shift($arguments)); - $this->arguments = $arguments; + $this->commandID = strtoupper($commandID); + $this->setArguments($arguments); } /** * Creates a new raw command using a variadic method. * - * @param string $commandID Redis command ID. - * @param string ... Arguments list for the command. + * @param string $commandID Redis command ID + * @param string ...$args Arguments list for the command * * @return CommandInterface */ - public static function create($commandID /* [ $arg, ... */) + public static function create($commandID, ...$args) { $arguments = func_get_args(); - $command = new self($arguments); - return $command; + return new static(array_shift($arguments), $arguments); } /** @@ -116,9 +110,7 @@ class RawCommand implements CommandInterface */ public function getSlot() { - if (isset($this->slot)) { - return $this->slot; - } + return $this->slot ?? null; } /** diff --git a/plugins/cache-redis/Predis/Command/ScriptCommand.php b/plugins/cache-redis/Predis/Command/ScriptCommand.php index a30bc1d28..330ee94b3 100644 --- a/plugins/cache-redis/Predis/Command/ScriptCommand.php +++ b/plugins/cache-redis/Predis/Command/ScriptCommand.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -15,12 +16,18 @@ namespace Predis\Command; * Base class used to implement an higher level abstraction for commands based * on Lua scripting with EVAL and EVALSHA. * - * @link http://redis.io/commands/eval - * - * @author Daniele Alessandri + * @see http://redis.io/commands/eval */ -abstract class ScriptCommand extends ServerEvalSHA +abstract class ScriptCommand extends Command { + /** + * {@inheritdoc} + */ + public function getId() + { + return 'EVALSHA'; + } + /** * Gets the body of a Lua script. * @@ -28,6 +35,16 @@ abstract class ScriptCommand extends ServerEvalSHA */ abstract public function getScript(); + /** + * Calculates the SHA1 hash of the body of the script. + * + * @return string SHA1 hash. + */ + public function getScriptHash() + { + return sha1($this->getScript()); + } + /** * Specifies the number of arguments that should be considered as keys. * @@ -55,16 +72,20 @@ abstract class ScriptCommand extends ServerEvalSHA /** * {@inheritdoc} */ - protected function filterArguments(array $arguments) + public function setArguments(array $arguments) { if (($numkeys = $this->getKeysCount()) && $numkeys < 0) { $numkeys = count($arguments) + $numkeys; } - return array_merge(array(sha1($this->getScript()), (int) $numkeys), $arguments); + $arguments = array_merge([$this->getScriptHash(), (int) $numkeys], $arguments); + + parent::setArguments($arguments); } /** + * Returns arguments for EVAL command. + * * @return array */ public function getEvalArguments() @@ -74,4 +95,14 @@ abstract class ScriptCommand extends ServerEvalSHA return $arguments; } + + /** + * Returns the equivalent EVAL command as a raw command instance. + * + * @return RawCommand + */ + public function getEvalCommand() + { + return new RawCommand('EVAL', $this->getEvalArguments()); + } } diff --git a/plugins/cache-redis/Predis/Command/ServerBackgroundRewriteAOF.php b/plugins/cache-redis/Predis/Command/ServerBackgroundRewriteAOF.php deleted file mode 100644 index c66a294e5..000000000 --- a/plugins/cache-redis/Predis/Command/ServerBackgroundRewriteAOF.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/bgrewriteaof - * - * @author Daniele Alessandri - */ -class ServerBackgroundRewriteAOF extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'BGREWRITEAOF'; - } - - /** - * {@inheritdoc} - */ - public function parseResponse($data) - { - return $data == 'Background append only file rewriting started'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ServerBackgroundSave.php b/plugins/cache-redis/Predis/Command/ServerBackgroundSave.php deleted file mode 100644 index 4bf67ef30..000000000 --- a/plugins/cache-redis/Predis/Command/ServerBackgroundSave.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/bgsave - * - * @author Daniele Alessandri - */ -class ServerBackgroundSave extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'BGSAVE'; - } - - /** - * {@inheritdoc} - */ - public function parseResponse($data) - { - return $data === 'Background saving started' ? true : $data; - } -} diff --git a/plugins/cache-redis/Predis/Command/ServerClient.php b/plugins/cache-redis/Predis/Command/ServerClient.php deleted file mode 100644 index d00ebbfff..000000000 --- a/plugins/cache-redis/Predis/Command/ServerClient.php +++ /dev/null @@ -1,74 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/client-list - * @link http://redis.io/commands/client-kill - * @link http://redis.io/commands/client-getname - * @link http://redis.io/commands/client-setname - * - * @author Daniele Alessandri - */ -class ServerClient extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'CLIENT'; - } - - /** - * {@inheritdoc} - */ - public function parseResponse($data) - { - $args = array_change_key_case($this->getArguments(), CASE_UPPER); - - switch (strtoupper($args[0])) { - case 'LIST': - return $this->parseClientList($data); - case 'KILL': - case 'GETNAME': - case 'SETNAME': - default: - return $data; - } - } - - /** - * Parses the response to CLIENT LIST and returns a structured list. - * - * @param string $data Response buffer. - * - * @return array - */ - protected function parseClientList($data) - { - $clients = array(); - - foreach (explode("\n", $data, -1) as $clientData) { - $client = array(); - - foreach (explode(' ', $clientData) as $kv) { - @list($k, $v) = explode('=', $kv); - $client[$k] = $v; - } - - $clients[] = $client; - } - - return $clients; - } -} diff --git a/plugins/cache-redis/Predis/Command/ServerCommand.php b/plugins/cache-redis/Predis/Command/ServerCommand.php deleted file mode 100644 index e9b3393c7..000000000 --- a/plugins/cache-redis/Predis/Command/ServerCommand.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/command - * - * @author Daniele Alessandri - */ -class ServerCommand extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'COMMAND'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ServerConfig.php b/plugins/cache-redis/Predis/Command/ServerConfig.php deleted file mode 100644 index 81e497aea..000000000 --- a/plugins/cache-redis/Predis/Command/ServerConfig.php +++ /dev/null @@ -1,49 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/config-set - * @link http://redis.io/commands/config-get - * @link http://redis.io/commands/config-resetstat - * @link http://redis.io/commands/config-rewrite - * - * @author Daniele Alessandri - */ -class ServerConfig extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'CONFIG'; - } - - /** - * {@inheritdoc} - */ - public function parseResponse($data) - { - if (is_array($data)) { - $result = array(); - - for ($i = 0; $i < count($data); ++$i) { - $result[$data[$i]] = $data[++$i]; - } - - return $result; - } - - return $data; - } -} diff --git a/plugins/cache-redis/Predis/Command/ServerDatabaseSize.php b/plugins/cache-redis/Predis/Command/ServerDatabaseSize.php deleted file mode 100644 index 6bc89724d..000000000 --- a/plugins/cache-redis/Predis/Command/ServerDatabaseSize.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/dbsize - * - * @author Daniele Alessandri - */ -class ServerDatabaseSize extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'DBSIZE'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ServerEval.php b/plugins/cache-redis/Predis/Command/ServerEval.php deleted file mode 100644 index f5eefd811..000000000 --- a/plugins/cache-redis/Predis/Command/ServerEval.php +++ /dev/null @@ -1,38 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/eval - * - * @author Daniele Alessandri - */ -class ServerEval extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'EVAL'; - } - - /** - * Calculates the SHA1 hash of the body of the script. - * - * @return string SHA1 hash. - */ - public function getScriptHash() - { - return sha1($this->getArgument(0)); - } -} diff --git a/plugins/cache-redis/Predis/Command/ServerEvalSHA.php b/plugins/cache-redis/Predis/Command/ServerEvalSHA.php deleted file mode 100644 index 520a8e985..000000000 --- a/plugins/cache-redis/Predis/Command/ServerEvalSHA.php +++ /dev/null @@ -1,38 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/evalsha - * - * @author Daniele Alessandri - */ -class ServerEvalSHA extends ServerEval -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'EVALSHA'; - } - - /** - * Returns the SHA1 hash of the body of the script. - * - * @return string SHA1 hash. - */ - public function getScriptHash() - { - return $this->getArgument(0); - } -} diff --git a/plugins/cache-redis/Predis/Command/ServerFlushAll.php b/plugins/cache-redis/Predis/Command/ServerFlushAll.php deleted file mode 100644 index c35b2ad6a..000000000 --- a/plugins/cache-redis/Predis/Command/ServerFlushAll.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/flushall - * - * @author Daniele Alessandri - */ -class ServerFlushAll extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'FLUSHALL'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ServerFlushDatabase.php b/plugins/cache-redis/Predis/Command/ServerFlushDatabase.php deleted file mode 100644 index 3da6b320d..000000000 --- a/plugins/cache-redis/Predis/Command/ServerFlushDatabase.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/flushdb - * - * @author Daniele Alessandri - */ -class ServerFlushDatabase extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'FLUSHDB'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ServerInfo.php b/plugins/cache-redis/Predis/Command/ServerInfo.php deleted file mode 100644 index 96d6adad9..000000000 --- a/plugins/cache-redis/Predis/Command/ServerInfo.php +++ /dev/null @@ -1,111 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/info - * - * @author Daniele Alessandri - */ -class ServerInfo extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'INFO'; - } - - /** - * {@inheritdoc} - */ - public function parseResponse($data) - { - $info = array(); - $infoLines = preg_split('/\r?\n/', $data); - - foreach ($infoLines as $row) { - if (strpos($row, ':') === false) { - continue; - } - - list($k, $v) = $this->parseRow($row); - $info[$k] = $v; - } - - return $info; - } - - /** - * Parses a single row of the response and returns the key-value pair. - * - * @param string $row Single row of the response. - * - * @return array - */ - protected function parseRow($row) - { - list($k, $v) = explode(':', $row, 2); - - if (preg_match('/^db\d+$/', $k)) { - $v = $this->parseDatabaseStats($v); - } - - return array($k, $v); - } - - /** - * Extracts the statistics of each logical DB from the string buffer. - * - * @param string $str Response buffer. - * - * @return array - */ - protected function parseDatabaseStats($str) - { - $db = array(); - - foreach (explode(',', $str) as $dbvar) { - list($dbvk, $dbvv) = explode('=', $dbvar); - $db[trim($dbvk)] = $dbvv; - } - - return $db; - } - - /** - * Parses the response and extracts the allocation statistics. - * - * @param string $str Response buffer. - * - * @return array - */ - protected function parseAllocationStats($str) - { - $stats = array(); - - foreach (explode(',', $str) as $kv) { - @list($size, $objects, $extra) = explode('=', $kv); - - // hack to prevent incorrect values when parsing the >=256 key - if (isset($extra)) { - $size = ">=$objects"; - $objects = $extra; - } - - $stats[$size] = $objects; - } - - return $stats; - } -} diff --git a/plugins/cache-redis/Predis/Command/ServerInfoV26x.php b/plugins/cache-redis/Predis/Command/ServerInfoV26x.php deleted file mode 100644 index 90c9b7163..000000000 --- a/plugins/cache-redis/Predis/Command/ServerInfoV26x.php +++ /dev/null @@ -1,56 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/info - * - * @author Daniele Alessandri - */ -class ServerInfoV26x extends ServerInfo -{ - /** - * {@inheritdoc} - */ - public function parseResponse($data) - { - if ($data === '') { - return array(); - } - - $info = array(); - - $current = null; - $infoLines = preg_split('/\r?\n/', $data); - - if (isset($infoLines[0]) && $infoLines[0][0] !== '#') { - return parent::parseResponse($data); - } - - foreach ($infoLines as $row) { - if ($row === '') { - continue; - } - - if (preg_match('/^# (\w+)$/', $row, $matches)) { - $info[$matches[1]] = array(); - $current = &$info[$matches[1]]; - continue; - } - - list($k, $v) = $this->parseRow($row); - $current[$k] = $v; - } - - return $info; - } -} diff --git a/plugins/cache-redis/Predis/Command/ServerLastSave.php b/plugins/cache-redis/Predis/Command/ServerLastSave.php deleted file mode 100644 index feeb19a8a..000000000 --- a/plugins/cache-redis/Predis/Command/ServerLastSave.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/lastsave - * - * @author Daniele Alessandri - */ -class ServerLastSave extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'LASTSAVE'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ServerMonitor.php b/plugins/cache-redis/Predis/Command/ServerMonitor.php deleted file mode 100644 index 1c3d33095..000000000 --- a/plugins/cache-redis/Predis/Command/ServerMonitor.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/monitor - * - * @author Daniele Alessandri - */ -class ServerMonitor extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'MONITOR'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ServerObject.php b/plugins/cache-redis/Predis/Command/ServerObject.php deleted file mode 100644 index f921701c2..000000000 --- a/plugins/cache-redis/Predis/Command/ServerObject.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/object - * - * @author Daniele Alessandri - */ -class ServerObject extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'OBJECT'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ServerSave.php b/plugins/cache-redis/Predis/Command/ServerSave.php deleted file mode 100644 index addefe20f..000000000 --- a/plugins/cache-redis/Predis/Command/ServerSave.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/save - * - * @author Daniele Alessandri - */ -class ServerSave extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'SAVE'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ServerScript.php b/plugins/cache-redis/Predis/Command/ServerScript.php deleted file mode 100644 index 7a01018d9..000000000 --- a/plugins/cache-redis/Predis/Command/ServerScript.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/script - * - * @author Daniele Alessandri - */ -class ServerScript extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'SCRIPT'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ServerSentinel.php b/plugins/cache-redis/Predis/Command/ServerSentinel.php deleted file mode 100644 index c0962db3d..000000000 --- a/plugins/cache-redis/Predis/Command/ServerSentinel.php +++ /dev/null @@ -1,66 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/topics/sentinel - * - * @author Daniele Alessandri - */ -class ServerSentinel extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'SENTINEL'; - } - - /** - * {@inheritdoc} - */ - public function parseResponse($data) - { - switch (strtolower($this->getArgument(0))) { - case 'masters': - case 'slaves': - return self::processMastersOrSlaves($data); - - default: - return $data; - } - } - - /** - * Returns a processed response to SENTINEL MASTERS or SENTINEL SLAVES. - * - * @param array $servers List of Redis servers. - * - * @return array - */ - protected static function processMastersOrSlaves(array $servers) - { - foreach ($servers as $idx => $node) { - $processed = array(); - $count = count($node); - - for ($i = 0; $i < $count; ++$i) { - $processed[$node[$i]] = $node[++$i]; - } - - $servers[$idx] = $processed; - } - - return $servers; - } -} diff --git a/plugins/cache-redis/Predis/Command/ServerShutdown.php b/plugins/cache-redis/Predis/Command/ServerShutdown.php deleted file mode 100644 index f5b745a21..000000000 --- a/plugins/cache-redis/Predis/Command/ServerShutdown.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/shutdown - * - * @author Daniele Alessandri - */ -class ServerShutdown extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'SHUTDOWN'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ServerSlaveOf.php b/plugins/cache-redis/Predis/Command/ServerSlaveOf.php deleted file mode 100644 index 4ff44556a..000000000 --- a/plugins/cache-redis/Predis/Command/ServerSlaveOf.php +++ /dev/null @@ -1,40 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/slaveof - * - * @author Daniele Alessandri - */ -class ServerSlaveOf extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'SLAVEOF'; - } - - /** - * {@inheritdoc} - */ - protected function filterArguments(array $arguments) - { - if (count($arguments) === 0 || $arguments[0] === 'NO ONE') { - return array('NO', 'ONE'); - } - - return $arguments; - } -} diff --git a/plugins/cache-redis/Predis/Command/ServerSlowlog.php b/plugins/cache-redis/Predis/Command/ServerSlowlog.php deleted file mode 100644 index 137ff59e7..000000000 --- a/plugins/cache-redis/Predis/Command/ServerSlowlog.php +++ /dev/null @@ -1,51 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/slowlog - * - * @author Daniele Alessandri - */ -class ServerSlowlog extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'SLOWLOG'; - } - - /** - * {@inheritdoc} - */ - public function parseResponse($data) - { - if (is_array($data)) { - $log = array(); - - foreach ($data as $index => $entry) { - $log[$index] = array( - 'id' => $entry[0], - 'timestamp' => $entry[1], - 'duration' => $entry[2], - 'command' => $entry[3], - ); - } - - return $log; - } - - return $data; - } -} diff --git a/plugins/cache-redis/Predis/Command/ServerTime.php b/plugins/cache-redis/Predis/Command/ServerTime.php deleted file mode 100644 index 589f92c55..000000000 --- a/plugins/cache-redis/Predis/Command/ServerTime.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/time - * - * @author Daniele Alessandri - */ -class ServerTime extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'TIME'; - } -} diff --git a/plugins/cache-redis/Predis/Command/SetAdd.php b/plugins/cache-redis/Predis/Command/SetAdd.php deleted file mode 100644 index c11881816..000000000 --- a/plugins/cache-redis/Predis/Command/SetAdd.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/sadd - * - * @author Daniele Alessandri - */ -class SetAdd extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'SADD'; - } - - /** - * {@inheritdoc} - */ - protected function filterArguments(array $arguments) - { - return self::normalizeVariadic($arguments); - } -} diff --git a/plugins/cache-redis/Predis/Command/SetCardinality.php b/plugins/cache-redis/Predis/Command/SetCardinality.php deleted file mode 100644 index a9f959b78..000000000 --- a/plugins/cache-redis/Predis/Command/SetCardinality.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/scard - * - * @author Daniele Alessandri - */ -class SetCardinality extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'SCARD'; - } -} diff --git a/plugins/cache-redis/Predis/Command/SetDifference.php b/plugins/cache-redis/Predis/Command/SetDifference.php deleted file mode 100644 index 35f23f98a..000000000 --- a/plugins/cache-redis/Predis/Command/SetDifference.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/sdiff - * - * @author Daniele Alessandri - */ -class SetDifference extends SetIntersection -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'SDIFF'; - } -} diff --git a/plugins/cache-redis/Predis/Command/SetDifferenceStore.php b/plugins/cache-redis/Predis/Command/SetDifferenceStore.php deleted file mode 100644 index 0cb78155f..000000000 --- a/plugins/cache-redis/Predis/Command/SetDifferenceStore.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/sdiffstore - * - * @author Daniele Alessandri - */ -class SetDifferenceStore extends SetIntersectionStore -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'SDIFFSTORE'; - } -} diff --git a/plugins/cache-redis/Predis/Command/SetIntersection.php b/plugins/cache-redis/Predis/Command/SetIntersection.php deleted file mode 100644 index d18258fd7..000000000 --- a/plugins/cache-redis/Predis/Command/SetIntersection.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/sinter - * - * @author Daniele Alessandri - */ -class SetIntersection extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'SINTER'; - } - - /** - * {@inheritdoc} - */ - protected function filterArguments(array $arguments) - { - return self::normalizeArguments($arguments); - } -} diff --git a/plugins/cache-redis/Predis/Command/SetIntersectionStore.php b/plugins/cache-redis/Predis/Command/SetIntersectionStore.php deleted file mode 100644 index b748618aa..000000000 --- a/plugins/cache-redis/Predis/Command/SetIntersectionStore.php +++ /dev/null @@ -1,40 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/sinterstore - * - * @author Daniele Alessandri - */ -class SetIntersectionStore extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'SINTERSTORE'; - } - - /** - * {@inheritdoc} - */ - protected function filterArguments(array $arguments) - { - if (count($arguments) === 2 && is_array($arguments[1])) { - return array_merge(array($arguments[0]), $arguments[1]); - } - - return $arguments; - } -} diff --git a/plugins/cache-redis/Predis/Command/SetIsMember.php b/plugins/cache-redis/Predis/Command/SetIsMember.php deleted file mode 100644 index 1b484907e..000000000 --- a/plugins/cache-redis/Predis/Command/SetIsMember.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/sismember - * - * @author Daniele Alessandri - */ -class SetIsMember extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'SISMEMBER'; - } - - /** - * {@inheritdoc} - */ - public function parseResponse($data) - { - return (bool) $data; - } -} diff --git a/plugins/cache-redis/Predis/Command/SetMembers.php b/plugins/cache-redis/Predis/Command/SetMembers.php deleted file mode 100644 index f4076ae8b..000000000 --- a/plugins/cache-redis/Predis/Command/SetMembers.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/smembers - * - * @author Daniele Alessandri - */ -class SetMembers extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'SMEMBERS'; - } -} diff --git a/plugins/cache-redis/Predis/Command/SetMove.php b/plugins/cache-redis/Predis/Command/SetMove.php deleted file mode 100644 index 72d514be7..000000000 --- a/plugins/cache-redis/Predis/Command/SetMove.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/smove - * - * @author Daniele Alessandri - */ -class SetMove extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'SMOVE'; - } - - /** - * {@inheritdoc} - */ - public function parseResponse($data) - { - return (bool) $data; - } -} diff --git a/plugins/cache-redis/Predis/Command/SetPop.php b/plugins/cache-redis/Predis/Command/SetPop.php deleted file mode 100644 index b78d3f33b..000000000 --- a/plugins/cache-redis/Predis/Command/SetPop.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/spop - * - * @author Daniele Alessandri - */ -class SetPop extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'SPOP'; - } -} diff --git a/plugins/cache-redis/Predis/Command/SetRandomMember.php b/plugins/cache-redis/Predis/Command/SetRandomMember.php deleted file mode 100644 index 2cb79a049..000000000 --- a/plugins/cache-redis/Predis/Command/SetRandomMember.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/srandmember - * - * @author Daniele Alessandri - */ -class SetRandomMember extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'SRANDMEMBER'; - } -} diff --git a/plugins/cache-redis/Predis/Command/SetRemove.php b/plugins/cache-redis/Predis/Command/SetRemove.php deleted file mode 100644 index b34710c62..000000000 --- a/plugins/cache-redis/Predis/Command/SetRemove.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/srem - * - * @author Daniele Alessandri - */ -class SetRemove extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'SREM'; - } - - /** - * {@inheritdoc} - */ - protected function filterArguments(array $arguments) - { - return self::normalizeVariadic($arguments); - } -} diff --git a/plugins/cache-redis/Predis/Command/SetScan.php b/plugins/cache-redis/Predis/Command/SetScan.php deleted file mode 100644 index d42b28dfb..000000000 --- a/plugins/cache-redis/Predis/Command/SetScan.php +++ /dev/null @@ -1,66 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/sscan - * - * @author Daniele Alessandri - */ -class SetScan extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'SSCAN'; - } - - /** - * {@inheritdoc} - */ - protected function filterArguments(array $arguments) - { - if (count($arguments) === 3 && is_array($arguments[2])) { - $options = $this->prepareOptions(array_pop($arguments)); - $arguments = array_merge($arguments, $options); - } - - return $arguments; - } - - /** - * Returns a list of options and modifiers compatible with Redis. - * - * @param array $options List of options. - * - * @return array - */ - protected function prepareOptions($options) - { - $options = array_change_key_case($options, CASE_UPPER); - $normalized = array(); - - if (!empty($options['MATCH'])) { - $normalized[] = 'MATCH'; - $normalized[] = $options['MATCH']; - } - - if (!empty($options['COUNT'])) { - $normalized[] = 'COUNT'; - $normalized[] = $options['COUNT']; - } - - return $normalized; - } -} diff --git a/plugins/cache-redis/Predis/Command/SetUnion.php b/plugins/cache-redis/Predis/Command/SetUnion.php deleted file mode 100644 index 7da842b45..000000000 --- a/plugins/cache-redis/Predis/Command/SetUnion.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/sunion - * - * @author Daniele Alessandri - */ -class SetUnion extends SetIntersection -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'SUNION'; - } -} diff --git a/plugins/cache-redis/Predis/Command/SetUnionStore.php b/plugins/cache-redis/Predis/Command/SetUnionStore.php deleted file mode 100644 index eac821ad7..000000000 --- a/plugins/cache-redis/Predis/Command/SetUnionStore.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/sunionstore - * - * @author Daniele Alessandri - */ -class SetUnionStore extends SetIntersectionStore -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'SUNIONSTORE'; - } -} diff --git a/plugins/cache-redis/Predis/Command/StringAppend.php b/plugins/cache-redis/Predis/Command/StringAppend.php deleted file mode 100644 index dac8b8479..000000000 --- a/plugins/cache-redis/Predis/Command/StringAppend.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/append - * - * @author Daniele Alessandri - */ -class StringAppend extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'APPEND'; - } -} diff --git a/plugins/cache-redis/Predis/Command/StringBitCount.php b/plugins/cache-redis/Predis/Command/StringBitCount.php deleted file mode 100644 index 193cce916..000000000 --- a/plugins/cache-redis/Predis/Command/StringBitCount.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/bitcount - * - * @author Daniele Alessandri - */ -class StringBitCount extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'BITCOUNT'; - } -} diff --git a/plugins/cache-redis/Predis/Command/StringBitOp.php b/plugins/cache-redis/Predis/Command/StringBitOp.php deleted file mode 100644 index e04ee79c2..000000000 --- a/plugins/cache-redis/Predis/Command/StringBitOp.php +++ /dev/null @@ -1,42 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/bitop - * - * @author Daniele Alessandri - */ -class StringBitOp extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'BITOP'; - } - - /** - * {@inheritdoc} - */ - protected function filterArguments(array $arguments) - { - if (count($arguments) === 3 && is_array($arguments[2])) { - list($operation, $destination) = $arguments; - $arguments = $arguments[2]; - array_unshift($arguments, $operation, $destination); - } - - return $arguments; - } -} diff --git a/plugins/cache-redis/Predis/Command/StringBitPos.php b/plugins/cache-redis/Predis/Command/StringBitPos.php deleted file mode 100644 index 42957665d..000000000 --- a/plugins/cache-redis/Predis/Command/StringBitPos.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/bitpos - * - * @author Daniele Alessandri - */ -class StringBitPos extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'BITPOS'; - } -} diff --git a/plugins/cache-redis/Predis/Command/StringDecrement.php b/plugins/cache-redis/Predis/Command/StringDecrement.php deleted file mode 100644 index aa5808cd0..000000000 --- a/plugins/cache-redis/Predis/Command/StringDecrement.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/decr - * - * @author Daniele Alessandri - */ -class StringDecrement extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'DECR'; - } -} diff --git a/plugins/cache-redis/Predis/Command/StringDecrementBy.php b/plugins/cache-redis/Predis/Command/StringDecrementBy.php deleted file mode 100644 index cbf3e1124..000000000 --- a/plugins/cache-redis/Predis/Command/StringDecrementBy.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/decrby - * - * @author Daniele Alessandri - */ -class StringDecrementBy extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'DECRBY'; - } -} diff --git a/plugins/cache-redis/Predis/Command/StringGet.php b/plugins/cache-redis/Predis/Command/StringGet.php deleted file mode 100644 index 138e915c2..000000000 --- a/plugins/cache-redis/Predis/Command/StringGet.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/get - * - * @author Daniele Alessandri - */ -class StringGet extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'GET'; - } -} diff --git a/plugins/cache-redis/Predis/Command/StringGetBit.php b/plugins/cache-redis/Predis/Command/StringGetBit.php deleted file mode 100644 index 3c5b4f9b7..000000000 --- a/plugins/cache-redis/Predis/Command/StringGetBit.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/getbit - * - * @author Daniele Alessandri - */ -class StringGetBit extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'GETBIT'; - } -} diff --git a/plugins/cache-redis/Predis/Command/StringGetMultiple.php b/plugins/cache-redis/Predis/Command/StringGetMultiple.php deleted file mode 100644 index e340f9cfc..000000000 --- a/plugins/cache-redis/Predis/Command/StringGetMultiple.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/mget - * - * @author Daniele Alessandri - */ -class StringGetMultiple extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'MGET'; - } - - /** - * {@inheritdoc} - */ - protected function filterArguments(array $arguments) - { - return self::normalizeArguments($arguments); - } -} diff --git a/plugins/cache-redis/Predis/Command/StringGetRange.php b/plugins/cache-redis/Predis/Command/StringGetRange.php deleted file mode 100644 index bb10565b5..000000000 --- a/plugins/cache-redis/Predis/Command/StringGetRange.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/getrange - * - * @author Daniele Alessandri - */ -class StringGetRange extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'GETRANGE'; - } -} diff --git a/plugins/cache-redis/Predis/Command/StringGetSet.php b/plugins/cache-redis/Predis/Command/StringGetSet.php deleted file mode 100644 index b68870d4c..000000000 --- a/plugins/cache-redis/Predis/Command/StringGetSet.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/getset - * - * @author Daniele Alessandri - */ -class StringGetSet extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'GETSET'; - } -} diff --git a/plugins/cache-redis/Predis/Command/StringIncrement.php b/plugins/cache-redis/Predis/Command/StringIncrement.php deleted file mode 100644 index fa1846e2e..000000000 --- a/plugins/cache-redis/Predis/Command/StringIncrement.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/incr - * - * @author Daniele Alessandri - */ -class StringIncrement extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'INCR'; - } -} diff --git a/plugins/cache-redis/Predis/Command/StringIncrementBy.php b/plugins/cache-redis/Predis/Command/StringIncrementBy.php deleted file mode 100644 index 9d8241a25..000000000 --- a/plugins/cache-redis/Predis/Command/StringIncrementBy.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/incrby - * - * @author Daniele Alessandri - */ -class StringIncrementBy extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'INCRBY'; - } -} diff --git a/plugins/cache-redis/Predis/Command/StringIncrementByFloat.php b/plugins/cache-redis/Predis/Command/StringIncrementByFloat.php deleted file mode 100644 index 164a0869b..000000000 --- a/plugins/cache-redis/Predis/Command/StringIncrementByFloat.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/incrbyfloat - * - * @author Daniele Alessandri - */ -class StringIncrementByFloat extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'INCRBYFLOAT'; - } -} diff --git a/plugins/cache-redis/Predis/Command/StringPreciseSetExpire.php b/plugins/cache-redis/Predis/Command/StringPreciseSetExpire.php deleted file mode 100644 index 2faa954d0..000000000 --- a/plugins/cache-redis/Predis/Command/StringPreciseSetExpire.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/psetex - * - * @author Daniele Alessandri - */ -class StringPreciseSetExpire extends StringSetExpire -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'PSETEX'; - } -} diff --git a/plugins/cache-redis/Predis/Command/StringSet.php b/plugins/cache-redis/Predis/Command/StringSet.php deleted file mode 100644 index b1469945c..000000000 --- a/plugins/cache-redis/Predis/Command/StringSet.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/set - * - * @author Daniele Alessandri - */ -class StringSet extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'SET'; - } -} diff --git a/plugins/cache-redis/Predis/Command/StringSetBit.php b/plugins/cache-redis/Predis/Command/StringSetBit.php deleted file mode 100644 index 7933b6be3..000000000 --- a/plugins/cache-redis/Predis/Command/StringSetBit.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/setbit - * - * @author Daniele Alessandri - */ -class StringSetBit extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'SETBIT'; - } -} diff --git a/plugins/cache-redis/Predis/Command/StringSetExpire.php b/plugins/cache-redis/Predis/Command/StringSetExpire.php deleted file mode 100644 index f08817085..000000000 --- a/plugins/cache-redis/Predis/Command/StringSetExpire.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/setex - * - * @author Daniele Alessandri - */ -class StringSetExpire extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'SETEX'; - } -} diff --git a/plugins/cache-redis/Predis/Command/StringSetMultiple.php b/plugins/cache-redis/Predis/Command/StringSetMultiple.php deleted file mode 100644 index a3c5324dc..000000000 --- a/plugins/cache-redis/Predis/Command/StringSetMultiple.php +++ /dev/null @@ -1,48 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/mset - * - * @author Daniele Alessandri - */ -class StringSetMultiple extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'MSET'; - } - - /** - * {@inheritdoc} - */ - protected function filterArguments(array $arguments) - { - if (count($arguments) === 1 && is_array($arguments[0])) { - $flattenedKVs = array(); - $args = $arguments[0]; - - foreach ($args as $k => $v) { - $flattenedKVs[] = $k; - $flattenedKVs[] = $v; - } - - return $flattenedKVs; - } - - return $arguments; - } -} diff --git a/plugins/cache-redis/Predis/Command/StringSetMultiplePreserve.php b/plugins/cache-redis/Predis/Command/StringSetMultiplePreserve.php deleted file mode 100644 index f98f1f7c2..000000000 --- a/plugins/cache-redis/Predis/Command/StringSetMultiplePreserve.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/msetnx - * - * @author Daniele Alessandri - */ -class StringSetMultiplePreserve extends StringSetMultiple -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'MSETNX'; - } - - /** - * {@inheritdoc} - */ - public function parseResponse($data) - { - return (bool) $data; - } -} diff --git a/plugins/cache-redis/Predis/Command/StringSetPreserve.php b/plugins/cache-redis/Predis/Command/StringSetPreserve.php deleted file mode 100644 index 726c35c87..000000000 --- a/plugins/cache-redis/Predis/Command/StringSetPreserve.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/setnx - * - * @author Daniele Alessandri - */ -class StringSetPreserve extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'SETNX'; - } - - /** - * {@inheritdoc} - */ - public function parseResponse($data) - { - return (bool) $data; - } -} diff --git a/plugins/cache-redis/Predis/Command/StringSetRange.php b/plugins/cache-redis/Predis/Command/StringSetRange.php deleted file mode 100644 index 4d9389f48..000000000 --- a/plugins/cache-redis/Predis/Command/StringSetRange.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/setrange - * - * @author Daniele Alessandri - */ -class StringSetRange extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'SETRANGE'; - } -} diff --git a/plugins/cache-redis/Predis/Command/StringStrlen.php b/plugins/cache-redis/Predis/Command/StringStrlen.php deleted file mode 100644 index 10f492fd9..000000000 --- a/plugins/cache-redis/Predis/Command/StringStrlen.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/strlen - * - * @author Daniele Alessandri - */ -class StringStrlen extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'STRLEN'; - } -} diff --git a/plugins/cache-redis/Predis/Command/StringSubstr.php b/plugins/cache-redis/Predis/Command/StringSubstr.php deleted file mode 100644 index 3aab7ade8..000000000 --- a/plugins/cache-redis/Predis/Command/StringSubstr.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/substr - * - * @author Daniele Alessandri - */ -class StringSubstr extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'SUBSTR'; - } -} diff --git a/plugins/cache-redis/Predis/Command/TransactionDiscard.php b/plugins/cache-redis/Predis/Command/TransactionDiscard.php deleted file mode 100644 index 44aca2b11..000000000 --- a/plugins/cache-redis/Predis/Command/TransactionDiscard.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/discard - * - * @author Daniele Alessandri - */ -class TransactionDiscard extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'DISCARD'; - } -} diff --git a/plugins/cache-redis/Predis/Command/TransactionExec.php b/plugins/cache-redis/Predis/Command/TransactionExec.php deleted file mode 100644 index dbd81aae9..000000000 --- a/plugins/cache-redis/Predis/Command/TransactionExec.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/exec - * - * @author Daniele Alessandri - */ -class TransactionExec extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'EXEC'; - } -} diff --git a/plugins/cache-redis/Predis/Command/TransactionMulti.php b/plugins/cache-redis/Predis/Command/TransactionMulti.php deleted file mode 100644 index 673bf55da..000000000 --- a/plugins/cache-redis/Predis/Command/TransactionMulti.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/multi - * - * @author Daniele Alessandri - */ -class TransactionMulti extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'MULTI'; - } -} diff --git a/plugins/cache-redis/Predis/Command/TransactionUnwatch.php b/plugins/cache-redis/Predis/Command/TransactionUnwatch.php deleted file mode 100644 index 792555449..000000000 --- a/plugins/cache-redis/Predis/Command/TransactionUnwatch.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/unwatch - * - * @author Daniele Alessandri - */ -class TransactionUnwatch extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'UNWATCH'; - } -} diff --git a/plugins/cache-redis/Predis/Command/TransactionWatch.php b/plugins/cache-redis/Predis/Command/TransactionWatch.php deleted file mode 100644 index d3607801b..000000000 --- a/plugins/cache-redis/Predis/Command/TransactionWatch.php +++ /dev/null @@ -1,40 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/watch - * - * @author Daniele Alessandri - */ -class TransactionWatch extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'WATCH'; - } - - /** - * {@inheritdoc} - */ - protected function filterArguments(array $arguments) - { - if (isset($arguments[0]) && is_array($arguments[0])) { - return $arguments[0]; - } - - return $arguments; - } -} diff --git a/plugins/cache-redis/Predis/Command/ZSetAdd.php b/plugins/cache-redis/Predis/Command/ZSetAdd.php deleted file mode 100644 index 55e4729e5..000000000 --- a/plugins/cache-redis/Predis/Command/ZSetAdd.php +++ /dev/null @@ -1,43 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/zadd - * - * @author Daniele Alessandri - */ -class ZSetAdd extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'ZADD'; - } - - /** - * {@inheritdoc} - */ - protected function filterArguments(array $arguments) - { - if (is_array(end($arguments))) { - foreach (array_pop($arguments) as $member => $score) { - $arguments[] = $score; - $arguments[] = $member; - } - } - - return $arguments; - } -} diff --git a/plugins/cache-redis/Predis/Command/ZSetCardinality.php b/plugins/cache-redis/Predis/Command/ZSetCardinality.php deleted file mode 100644 index 10332009a..000000000 --- a/plugins/cache-redis/Predis/Command/ZSetCardinality.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/zcard - * - * @author Daniele Alessandri - */ -class ZSetCardinality extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'ZCARD'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ZSetCount.php b/plugins/cache-redis/Predis/Command/ZSetCount.php deleted file mode 100644 index 918bd2b80..000000000 --- a/plugins/cache-redis/Predis/Command/ZSetCount.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/zcount - * - * @author Daniele Alessandri - */ -class ZSetCount extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'ZCOUNT'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ZSetIncrementBy.php b/plugins/cache-redis/Predis/Command/ZSetIncrementBy.php deleted file mode 100644 index 245a8e0f5..000000000 --- a/plugins/cache-redis/Predis/Command/ZSetIncrementBy.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/zincrby - * - * @author Daniele Alessandri - */ -class ZSetIncrementBy extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'ZINCRBY'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ZSetIntersectionStore.php b/plugins/cache-redis/Predis/Command/ZSetIntersectionStore.php deleted file mode 100644 index 572a7a324..000000000 --- a/plugins/cache-redis/Predis/Command/ZSetIntersectionStore.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/zinterstore - * - * @author Daniele Alessandri - */ -class ZSetIntersectionStore extends ZSetUnionStore -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'ZINTERSTORE'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ZSetLexCount.php b/plugins/cache-redis/Predis/Command/ZSetLexCount.php deleted file mode 100644 index 447b8eb32..000000000 --- a/plugins/cache-redis/Predis/Command/ZSetLexCount.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/zlexcount - * - * @author Daniele Alessandri - */ -class ZSetLexCount extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'ZLEXCOUNT'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ZSetRange.php b/plugins/cache-redis/Predis/Command/ZSetRange.php deleted file mode 100644 index ce72c7c07..000000000 --- a/plugins/cache-redis/Predis/Command/ZSetRange.php +++ /dev/null @@ -1,105 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/zrange - * - * @author Daniele Alessandri - */ -class ZSetRange extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'ZRANGE'; - } - - /** - * {@inheritdoc} - */ - protected function filterArguments(array $arguments) - { - if (count($arguments) === 4) { - $lastType = gettype($arguments[3]); - - if ($lastType === 'string' && strtoupper($arguments[3]) === 'WITHSCORES') { - // Used for compatibility with older versions - $arguments[3] = array('WITHSCORES' => true); - $lastType = 'array'; - } - - if ($lastType === 'array') { - $options = $this->prepareOptions(array_pop($arguments)); - - return array_merge($arguments, $options); - } - } - - return $arguments; - } - - /** - * Returns a list of options and modifiers compatible with Redis. - * - * @param array $options List of options. - * - * @return array - */ - protected function prepareOptions($options) - { - $opts = array_change_key_case($options, CASE_UPPER); - $finalizedOpts = array(); - - if (!empty($opts['WITHSCORES'])) { - $finalizedOpts[] = 'WITHSCORES'; - } - - return $finalizedOpts; - } - - /** - * Checks for the presence of the WITHSCORES modifier. - * - * @return bool - */ - protected function withScores() - { - $arguments = $this->getArguments(); - - if (count($arguments) < 4) { - return false; - } - - return strtoupper($arguments[3]) === 'WITHSCORES'; - } - - /** - * {@inheritdoc} - */ - public function parseResponse($data) - { - if ($this->withScores()) { - $result = array(); - - for ($i = 0; $i < count($data); ++$i) { - $result[$data[$i]] = $data[++$i]; - } - - return $result; - } - - return $data; - } -} diff --git a/plugins/cache-redis/Predis/Command/ZSetRangeByLex.php b/plugins/cache-redis/Predis/Command/ZSetRangeByLex.php deleted file mode 100644 index 9b2991a81..000000000 --- a/plugins/cache-redis/Predis/Command/ZSetRangeByLex.php +++ /dev/null @@ -1,55 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/zrangebylex - * - * @author Daniele Alessandri - */ -class ZSetRangeByLex extends ZSetRange -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'ZRANGEBYLEX'; - } - - /** - * {@inheritdoc} - */ - protected function prepareOptions($options) - { - $opts = array_change_key_case($options, CASE_UPPER); - $finalizedOpts = array(); - - if (isset($opts['LIMIT']) && is_array($opts['LIMIT'])) { - $limit = array_change_key_case($opts['LIMIT'], CASE_UPPER); - - $finalizedOpts[] = 'LIMIT'; - $finalizedOpts[] = isset($limit['OFFSET']) ? $limit['OFFSET'] : $limit[0]; - $finalizedOpts[] = isset($limit['COUNT']) ? $limit['COUNT'] : $limit[1]; - } - - return $finalizedOpts; - } - - /** - * {@inheritdoc} - */ - protected function withScores() - { - return false; - } -} diff --git a/plugins/cache-redis/Predis/Command/ZSetRangeByScore.php b/plugins/cache-redis/Predis/Command/ZSetRangeByScore.php deleted file mode 100644 index 961a5bc2e..000000000 --- a/plugins/cache-redis/Predis/Command/ZSetRangeByScore.php +++ /dev/null @@ -1,68 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/zrangebyscore - * - * @author Daniele Alessandri - */ -class ZSetRangeByScore extends ZSetRange -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'ZRANGEBYSCORE'; - } - - /** - * {@inheritdoc} - */ - protected function prepareOptions($options) - { - $opts = array_change_key_case($options, CASE_UPPER); - $finalizedOpts = array(); - - if (isset($opts['LIMIT']) && is_array($opts['LIMIT'])) { - $limit = array_change_key_case($opts['LIMIT'], CASE_UPPER); - - $finalizedOpts[] = 'LIMIT'; - $finalizedOpts[] = isset($limit['OFFSET']) ? $limit['OFFSET'] : $limit[0]; - $finalizedOpts[] = isset($limit['COUNT']) ? $limit['COUNT'] : $limit[1]; - } - - return array_merge($finalizedOpts, parent::prepareOptions($options)); - } - - /** - * {@inheritdoc} - */ - protected function withScores() - { - $arguments = $this->getArguments(); - - for ($i = 3; $i < count($arguments); ++$i) { - switch (strtoupper($arguments[$i])) { - case 'WITHSCORES': - return true; - - case 'LIMIT': - $i += 2; - break; - } - } - - return false; - } -} diff --git a/plugins/cache-redis/Predis/Command/ZSetRank.php b/plugins/cache-redis/Predis/Command/ZSetRank.php deleted file mode 100644 index d0c9c536e..000000000 --- a/plugins/cache-redis/Predis/Command/ZSetRank.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/zrank - * - * @author Daniele Alessandri - */ -class ZSetRank extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'ZRANK'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ZSetRemove.php b/plugins/cache-redis/Predis/Command/ZSetRemove.php deleted file mode 100644 index cd8ada05c..000000000 --- a/plugins/cache-redis/Predis/Command/ZSetRemove.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/zrem - * - * @author Daniele Alessandri - */ -class ZSetRemove extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'ZREM'; - } - - /** - * {@inheritdoc} - */ - protected function filterArguments(array $arguments) - { - return self::normalizeVariadic($arguments); - } -} diff --git a/plugins/cache-redis/Predis/Command/ZSetRemoveRangeByLex.php b/plugins/cache-redis/Predis/Command/ZSetRemoveRangeByLex.php deleted file mode 100644 index 9ea2d9e5b..000000000 --- a/plugins/cache-redis/Predis/Command/ZSetRemoveRangeByLex.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/zremrangebylex - * - * @author Daniele Alessandri - */ -class ZSetRemoveRangeByLex extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'ZREMRANGEBYLEX'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ZSetRemoveRangeByRank.php b/plugins/cache-redis/Predis/Command/ZSetRemoveRangeByRank.php deleted file mode 100644 index 89cd5baff..000000000 --- a/plugins/cache-redis/Predis/Command/ZSetRemoveRangeByRank.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/zremrangebyrank - * - * @author Daniele Alessandri - */ -class ZSetRemoveRangeByRank extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'ZREMRANGEBYRANK'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ZSetRemoveRangeByScore.php b/plugins/cache-redis/Predis/Command/ZSetRemoveRangeByScore.php deleted file mode 100644 index a7c30814b..000000000 --- a/plugins/cache-redis/Predis/Command/ZSetRemoveRangeByScore.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/zremrangebyscore - * - * @author Daniele Alessandri - */ -class ZSetRemoveRangeByScore extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'ZREMRANGEBYSCORE'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ZSetReverseRange.php b/plugins/cache-redis/Predis/Command/ZSetReverseRange.php deleted file mode 100644 index 6a46a7a5a..000000000 --- a/plugins/cache-redis/Predis/Command/ZSetReverseRange.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/zrevrange - * - * @author Daniele Alessandri - */ -class ZSetReverseRange extends ZSetRange -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'ZREVRANGE'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ZSetReverseRangeByLex.php b/plugins/cache-redis/Predis/Command/ZSetReverseRangeByLex.php deleted file mode 100644 index cdd8ba623..000000000 --- a/plugins/cache-redis/Predis/Command/ZSetReverseRangeByLex.php +++ /dev/null @@ -1,23 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -class ZSetReverseRangeByLex extends ZSetRangeByLex -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'ZREVRANGEBYLEX'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ZSetReverseRangeByScore.php b/plugins/cache-redis/Predis/Command/ZSetReverseRangeByScore.php deleted file mode 100644 index 1078eb72b..000000000 --- a/plugins/cache-redis/Predis/Command/ZSetReverseRangeByScore.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/zrevrangebyscore - * - * @author Daniele Alessandri - */ -class ZSetReverseRangeByScore extends ZSetRangeByScore -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'ZREVRANGEBYSCORE'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ZSetReverseRank.php b/plugins/cache-redis/Predis/Command/ZSetReverseRank.php deleted file mode 100644 index 33fb81584..000000000 --- a/plugins/cache-redis/Predis/Command/ZSetReverseRank.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/zrevrank - * - * @author Daniele Alessandri - */ -class ZSetReverseRank extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'ZREVRANK'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ZSetScan.php b/plugins/cache-redis/Predis/Command/ZSetScan.php deleted file mode 100644 index 1dc2352ed..000000000 --- a/plugins/cache-redis/Predis/Command/ZSetScan.php +++ /dev/null @@ -1,85 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/zscan - * - * @author Daniele Alessandri - */ -class ZSetScan extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'ZSCAN'; - } - - /** - * {@inheritdoc} - */ - protected function filterArguments(array $arguments) - { - if (count($arguments) === 3 && is_array($arguments[2])) { - $options = $this->prepareOptions(array_pop($arguments)); - $arguments = array_merge($arguments, $options); - } - - return $arguments; - } - - /** - * Returns a list of options and modifiers compatible with Redis. - * - * @param array $options List of options. - * - * @return array - */ - protected function prepareOptions($options) - { - $options = array_change_key_case($options, CASE_UPPER); - $normalized = array(); - - if (!empty($options['MATCH'])) { - $normalized[] = 'MATCH'; - $normalized[] = $options['MATCH']; - } - - if (!empty($options['COUNT'])) { - $normalized[] = 'COUNT'; - $normalized[] = $options['COUNT']; - } - - return $normalized; - } - - /** - * {@inheritdoc} - */ - public function parseResponse($data) - { - if (is_array($data)) { - $members = $data[1]; - $result = array(); - - for ($i = 0; $i < count($members); ++$i) { - $result[$members[$i]] = (float) $members[++$i]; - } - - $data[1] = $result; - } - - return $data; - } -} diff --git a/plugins/cache-redis/Predis/Command/ZSetScore.php b/plugins/cache-redis/Predis/Command/ZSetScore.php deleted file mode 100644 index 2e7fce8ed..000000000 --- a/plugins/cache-redis/Predis/Command/ZSetScore.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/zscore - * - * @author Daniele Alessandri - */ -class ZSetScore extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'ZSCORE'; - } -} diff --git a/plugins/cache-redis/Predis/Command/ZSetUnionStore.php b/plugins/cache-redis/Predis/Command/ZSetUnionStore.php deleted file mode 100644 index befc5ce7c..000000000 --- a/plugins/cache-redis/Predis/Command/ZSetUnionStore.php +++ /dev/null @@ -1,78 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Command; - -/** - * @link http://redis.io/commands/zunionstore - * - * @author Daniele Alessandri - */ -class ZSetUnionStore extends Command -{ - /** - * {@inheritdoc} - */ - public function getId() - { - return 'ZUNIONSTORE'; - } - - /** - * {@inheritdoc} - */ - protected function filterArguments(array $arguments) - { - $options = array(); - $argc = count($arguments); - - if ($argc > 2 && is_array($arguments[$argc - 1])) { - $options = $this->prepareOptions(array_pop($arguments)); - } - - if (is_array($arguments[1])) { - $arguments = array_merge( - array($arguments[0], count($arguments[1])), - $arguments[1] - ); - } - - return array_merge($arguments, $options); - } - - /** - * Returns a list of options and modifiers compatible with Redis. - * - * @param array $options List of options. - * - * @return array - */ - private function prepareOptions($options) - { - $opts = array_change_key_case($options, CASE_UPPER); - $finalizedOpts = array(); - - if (isset($opts['WEIGHTS']) && is_array($opts['WEIGHTS'])) { - $finalizedOpts[] = 'WEIGHTS'; - - foreach ($opts['WEIGHTS'] as $weight) { - $finalizedOpts[] = $weight; - } - } - - if (isset($opts['AGGREGATE'])) { - $finalizedOpts[] = 'AGGREGATE'; - $finalizedOpts[] = $opts['AGGREGATE']; - } - - return $finalizedOpts; - } -} diff --git a/plugins/cache-redis/Predis/CommunicationException.php b/plugins/cache-redis/Predis/CommunicationException.php index 13fe357c3..0fc7c07a6 100644 --- a/plugins/cache-redis/Predis/CommunicationException.php +++ b/plugins/cache-redis/Predis/CommunicationException.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,12 +12,11 @@ namespace Predis; +use Exception; use Predis\Connection\NodeConnectionInterface; /** * Base exception class for network-related errors. - * - * @author Daniele Alessandri */ abstract class CommunicationException extends PredisException { @@ -26,15 +26,20 @@ abstract class CommunicationException extends PredisException * @param NodeConnectionInterface $connection Connection that generated the exception. * @param string $message Error message. * @param int $code Error code. - * @param \Exception $innerException Inner exception for wrapping the original error. + * @param Exception|null $innerException Inner exception for wrapping the original error. */ public function __construct( NodeConnectionInterface $connection, - $message = null, - $code = null, - \Exception $innerException = null + $message = '', + $code = 0, + Exception $innerException = null ) { - parent::__construct($message, $code, $innerException); + parent::__construct( + is_null($message) ? '' : $message, + is_null($code) ? 0 : $code, + $innerException + ); + $this->connection = $connection; } diff --git a/plugins/cache-redis/Predis/Configuration/ClusterOption.php b/plugins/cache-redis/Predis/Configuration/ClusterOption.php deleted file mode 100644 index 69e36de77..000000000 --- a/plugins/cache-redis/Predis/Configuration/ClusterOption.php +++ /dev/null @@ -1,76 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Configuration; - -use Predis\Connection\Aggregate\ClusterInterface; -use Predis\Connection\Aggregate\PredisCluster; -use Predis\Connection\Aggregate\RedisCluster; - -/** - * Configures an aggregate connection used for clustering - * multiple Redis nodes using various implementations with - * different algorithms or strategies. - * - * @author Daniele Alessandri - */ -class ClusterOption implements OptionInterface -{ - /** - * Creates a new cluster connection from on a known descriptive name. - * - * @param OptionsInterface $options Instance of the client options. - * @param string $id Descriptive identifier of the cluster type (`predis`, `redis-cluster`) - * - * @return ClusterInterface|null - */ - protected function createByDescription(OptionsInterface $options, $id) - { - switch ($id) { - case 'predis': - case 'predis-cluster': - return new PredisCluster(); - - case 'redis': - case 'redis-cluster': - return new RedisCluster($options->connections); - - default: - return; - } - } - - /** - * {@inheritdoc} - */ - public function filter(OptionsInterface $options, $value) - { - if (is_string($value)) { - $value = $this->createByDescription($options, $value); - } - - if (!$value instanceof ClusterInterface) { - throw new \InvalidArgumentException( - "An instance of type 'Predis\Connection\Aggregate\ClusterInterface' was expected." - ); - } - - return $value; - } - - /** - * {@inheritdoc} - */ - public function getDefault(OptionsInterface $options) - { - return new PredisCluster(); - } -} diff --git a/plugins/cache-redis/Predis/Configuration/ConnectionFactoryOption.php b/plugins/cache-redis/Predis/Configuration/ConnectionFactoryOption.php deleted file mode 100644 index ba38df96f..000000000 --- a/plugins/cache-redis/Predis/Configuration/ConnectionFactoryOption.php +++ /dev/null @@ -1,54 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Configuration; - -use Predis\Connection\Factory; -use Predis\Connection\FactoryInterface; - -/** - * Configures a connection factory used by the client to create new connection - * instances for single Redis nodes. - * - * @author Daniele Alessandri - */ -class ConnectionFactoryOption implements OptionInterface -{ - /** - * {@inheritdoc} - */ - public function filter(OptionsInterface $options, $value) - { - if ($value instanceof FactoryInterface) { - return $value; - } elseif (is_array($value)) { - $factory = $this->getDefault($options); - - foreach ($value as $scheme => $initializer) { - $factory->define($scheme, $initializer); - } - - return $factory; - } else { - throw new \InvalidArgumentException( - 'Invalid value provided for the connections option.' - ); - } - } - - /** - * {@inheritdoc} - */ - public function getDefault(OptionsInterface $options) - { - return new Factory(); - } -} diff --git a/plugins/cache-redis/Predis/Configuration/ExceptionsOption.php b/plugins/cache-redis/Predis/Configuration/ExceptionsOption.php deleted file mode 100644 index 337733e4b..000000000 --- a/plugins/cache-redis/Predis/Configuration/ExceptionsOption.php +++ /dev/null @@ -1,37 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Configuration; - -/** - * Configures whether consumers (such as the client) should throw exceptions on - * Redis errors (-ERR responses) or just return instances of error responses. - * - * @author Daniele Alessandri - */ -class ExceptionsOption implements OptionInterface -{ - /** - * {@inheritdoc} - */ - public function filter(OptionsInterface $options, $value) - { - return filter_var($value, FILTER_VALIDATE_BOOLEAN); - } - - /** - * {@inheritdoc} - */ - public function getDefault(OptionsInterface $options) - { - return true; - } -} diff --git a/plugins/cache-redis/Predis/Configuration/OptionInterface.php b/plugins/cache-redis/Predis/Configuration/OptionInterface.php index b31e0c98f..538fc0ba7 100644 --- a/plugins/cache-redis/Predis/Configuration/OptionInterface.php +++ b/plugins/cache-redis/Predis/Configuration/OptionInterface.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,8 +15,6 @@ namespace Predis\Configuration; /** * Defines an handler used by Predis\Configuration\Options to filter, validate * or return default values for a given option. - * - * @author Daniele Alessandri */ interface OptionInterface { diff --git a/plugins/cache-redis/Predis/Configuration/Options.php b/plugins/cache-redis/Predis/Configuration/Options.php index 6f3b331b5..3fff04129 100644 --- a/plugins/cache-redis/Predis/Configuration/Options.php +++ b/plugins/cache-redis/Predis/Configuration/Options.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -12,44 +13,39 @@ namespace Predis\Configuration; /** - * Manages Predis options with filtering, conversion and lazy initialization of - * values using a mini-DI container approach. + * Default client options container for Predis\Client. + * + * Pre-defined options have their specialized handlers that can filter, convert + * an lazily initialize values in a mini-DI container approach. * * {@inheritdoc} - * - * @author Daniele Alessandri */ class Options implements OptionsInterface { + /** @var array */ + protected $handlers = [ + 'aggregate' => Option\Aggregate::class, + 'cluster' => Option\Cluster::class, + 'replication' => Option\Replication::class, + 'connections' => Option\Connections::class, + 'commands' => Option\Commands::class, + 'exceptions' => Option\Exceptions::class, + 'prefix' => Option\Prefix::class, + 'crc16' => Option\CRC16::class, + ]; + + /** @var array */ + protected $options = []; + + /** @var array */ protected $input; - protected $options; - protected $handlers; /** - * @param array $options Array of options with their values + * @param array $options Named array of client options */ - public function __construct(array $options = array()) + public function __construct(array $options = null) { - $this->input = $options; - $this->options = array(); - $this->handlers = $this->getHandlers(); - } - - /** - * Ensures that the default options are initialized. - * - * @return array - */ - protected function getHandlers() - { - return array( - 'cluster' => 'Predis\Configuration\ClusterOption', - 'connections' => 'Predis\Configuration\ConnectionFactoryOption', - 'exceptions' => 'Predis\Configuration\ExceptionsOption', - 'prefix' => 'Predis\Configuration\PrefixOption', - 'profile' => 'Predis\Configuration\ProfileOption', - 'replication' => 'Predis\Configuration\ReplicationOption', - ); + $this->input = $options ?? []; } /** @@ -70,10 +66,10 @@ class Options implements OptionsInterface */ public function defined($option) { - return ( - array_key_exists($option, $this->options) || - array_key_exists($option, $this->input) - ); + return + array_key_exists($option, $this->options) + || array_key_exists($option, $this->input) + ; } /** @@ -82,8 +78,8 @@ class Options implements OptionsInterface public function __isset($option) { return ( - array_key_exists($option, $this->options) || - array_key_exists($option, $this->input) + array_key_exists($option, $this->options) + || array_key_exists($option, $this->input) ) && $this->__get($option) !== null; } @@ -100,14 +96,12 @@ class Options implements OptionsInterface $value = $this->input[$option]; unset($this->input[$option]); - if (is_object($value) && method_exists($value, '__invoke')) { - $value = $value($this, $option); - } - if (isset($this->handlers[$option])) { $handler = $this->handlers[$option]; $handler = new $handler(); $value = $handler->filter($this, $value); + } elseif (is_object($value) && method_exists($value, '__invoke')) { + $value = $value($this); } return $this->options[$option] = $value; diff --git a/plugins/cache-redis/Predis/Configuration/OptionsInterface.php b/plugins/cache-redis/Predis/Configuration/OptionsInterface.php index f81164708..597a0579b 100644 --- a/plugins/cache-redis/Predis/Configuration/OptionsInterface.php +++ b/plugins/cache-redis/Predis/Configuration/OptionsInterface.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,25 +12,23 @@ namespace Predis\Configuration; +use Predis\Command\Processor\ProcessorInterface; + /** - * Interface defining a container for client options. - * - * @property-read mixed aggregate Custom connection aggregator. - * @property-read mixed cluster Aggregate connection for clustering. - * @property-read mixed connections Connection factory. - * @property-read mixed exceptions Toggles exceptions in client for -ERR responses. - * @property-read mixed prefix Key prefixing strategy using the given prefix. - * @property-read mixed profile Server profile. - * @property-read mixed replication Aggregate connection for replication. - * - * @author Daniele Alessandri + * @property callable $aggregate Custom aggregate connection initializer + * @property callable $cluster Aggregate connection initializer for clustering + * @property \Predis\Connection\FactoryInterface $connections Connection factory for creating new connections + * @property bool $exceptions Toggles exceptions in client for -ERR responses + * @property ProcessorInterface $prefix Key prefixing strategy using the supplied string as prefix + * @property \Predis\Command\FactoryInterface $commands Command factory for creating Redis commands + * @property callable $replication Aggregate connection initializer for replication */ interface OptionsInterface { /** * Returns the default value for the given option. * - * @param string $option Name of the option. + * @param string $option Name of the option * * @return mixed|null */ @@ -38,7 +37,7 @@ interface OptionsInterface /** * Checks if the given option has been set by the user upon initialization. * - * @param string $option Name of the option. + * @param string $option Name of the option * * @return bool */ @@ -47,7 +46,7 @@ interface OptionsInterface /** * Checks if the given option has been set and does not evaluate to NULL. * - * @param string $option Name of the option. + * @param string $option Name of the option * * @return bool */ @@ -56,7 +55,7 @@ interface OptionsInterface /** * Returns the value of the given option. * - * @param string $option Name of the option. + * @param string $option Name of the option * * @return mixed|null */ diff --git a/plugins/cache-redis/Predis/Configuration/PrefixOption.php b/plugins/cache-redis/Predis/Configuration/PrefixOption.php deleted file mode 100644 index 5827cdc37..000000000 --- a/plugins/cache-redis/Predis/Configuration/PrefixOption.php +++ /dev/null @@ -1,44 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Configuration; - -use Predis\Command\Processor\KeyPrefixProcessor; -use Predis\Command\Processor\ProcessorInterface; - -/** - * Configures a command processor that apply the specified prefix string to a - * series of Redis commands considered prefixable. - * - * @author Daniele Alessandri - */ -class PrefixOption implements OptionInterface -{ - /** - * {@inheritdoc} - */ - public function filter(OptionsInterface $options, $value) - { - if ($value instanceof ProcessorInterface) { - return $value; - } - - return new KeyPrefixProcessor($value); - } - - /** - * {@inheritdoc} - */ - public function getDefault(OptionsInterface $options) - { - // NOOP - } -} diff --git a/plugins/cache-redis/Predis/Configuration/ProfileOption.php b/plugins/cache-redis/Predis/Configuration/ProfileOption.php deleted file mode 100644 index 864936e0a..000000000 --- a/plugins/cache-redis/Predis/Configuration/ProfileOption.php +++ /dev/null @@ -1,69 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Configuration; - -use Predis\Profile\Factory; -use Predis\Profile\ProfileInterface; -use Predis\Profile\RedisProfile; - -/** - * Configures the server profile to be used by the client to create command - * instances depending on the specified version of the Redis server. - * - * @author Daniele Alessandri - */ -class ProfileOption implements OptionInterface -{ - /** - * Sets the commands processors that need to be applied to the profile. - * - * @param OptionsInterface $options Client options. - * @param ProfileInterface $profile Server profile. - */ - protected function setProcessors(OptionsInterface $options, ProfileInterface $profile) - { - if (isset($options->prefix) && $profile instanceof RedisProfile) { - // NOTE: directly using __get('prefix') is actually a workaround for - // HHVM 2.3.0. It's correct and respects the options interface, it's - // just ugly. We will remove this hack when HHVM will fix re-entrant - // calls to __get() once and for all. - - $profile->setProcessor($options->__get('prefix')); - } - } - - /** - * {@inheritdoc} - */ - public function filter(OptionsInterface $options, $value) - { - if (is_string($value)) { - $value = Factory::get($value); - $this->setProcessors($options, $value); - } elseif (!$value instanceof ProfileInterface) { - throw new \InvalidArgumentException('Invalid value for the profile option.'); - } - - return $value; - } - - /** - * {@inheritdoc} - */ - public function getDefault(OptionsInterface $options) - { - $profile = Factory::getDefault(); - $this->setProcessors($options, $profile); - - return $profile; - } -} diff --git a/plugins/cache-redis/Predis/Configuration/ReplicationOption.php b/plugins/cache-redis/Predis/Configuration/ReplicationOption.php deleted file mode 100644 index fd2c8108d..000000000 --- a/plugins/cache-redis/Predis/Configuration/ReplicationOption.php +++ /dev/null @@ -1,61 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Configuration; - -use Predis\Connection\Aggregate\MasterSlaveReplication; -use Predis\Connection\Aggregate\ReplicationInterface; - -/** - * Configures an aggregate connection used for master/slave replication among - * multiple Redis nodes. - * - * @author Daniele Alessandri - */ -class ReplicationOption implements OptionInterface -{ - /** - * {@inheritdoc} - * - * @todo There's more code than needed due to a bug in filter_var() as - * discussed here https://bugs.php.net/bug.php?id=49510 and different - * behaviours when encountering NULL values on PHP 5.3. - */ - public function filter(OptionsInterface $options, $value) - { - if ($value instanceof ReplicationInterface) { - return $value; - } - - if (is_bool($value) || $value === null) { - return $value ? $this->getDefault($options) : null; - } - - if ( - !is_object($value) && - null !== $asbool = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) - ) { - return $asbool ? $this->getDefault($options) : null; - } - - throw new \InvalidArgumentException( - "An instance of type 'Predis\Connection\Aggregate\ReplicationInterface' was expected." - ); - } - - /** - * {@inheritdoc} - */ - public function getDefault(OptionsInterface $options) - { - return new MasterSlaveReplication(); - } -} diff --git a/plugins/cache-redis/Predis/Connection/AbstractConnection.php b/plugins/cache-redis/Predis/Connection/AbstractConnection.php index 029a337eb..3273f3866 100644 --- a/plugins/cache-redis/Predis/Connection/AbstractConnection.php +++ b/plugins/cache-redis/Predis/Connection/AbstractConnection.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,15 +12,15 @@ namespace Predis\Connection; +use InvalidArgumentException; use Predis\Command\CommandInterface; +use Predis\Command\RawCommand; use Predis\CommunicationException; use Predis\Protocol\ProtocolException; /** * Base class with the common logic used by connection classes to communicate * with Redis. - * - * @author Daniele Alessandri */ abstract class AbstractConnection implements NodeConnectionInterface { @@ -27,7 +28,11 @@ abstract class AbstractConnection implements NodeConnectionInterface private $cachedId; protected $parameters; - protected $initCommands = array(); + + /** + * @var RawCommand[] + */ + protected $initCommands = []; /** * @param ParametersInterface $parameters Initialization parameters for the connection. @@ -51,24 +56,10 @@ abstract class AbstractConnection implements NodeConnectionInterface * * @param ParametersInterface $parameters Initialization parameters for the connection. * - * @throws \InvalidArgumentException - * * @return ParametersInterface + * @throws InvalidArgumentException */ - protected function assertParameters(ParametersInterface $parameters) - { - switch ($parameters->scheme) { - case 'tcp': - case 'redis': - case 'unix': - break; - - default: - throw new \InvalidArgumentException("Invalid scheme: '$parameters->scheme'."); - } - - return $parameters; - } + abstract protected function assertParameters(ParametersInterface $parameters); /** * Creates the underlying resource used to communicate with Redis. @@ -115,6 +106,14 @@ abstract class AbstractConnection implements NodeConnectionInterface $this->initCommands[] = $command; } + /** + * {@inheritdoc} + */ + public function getInitCommands(): array + { + return $this->initCommands; + } + /** * {@inheritdoc} */ @@ -133,39 +132,16 @@ abstract class AbstractConnection implements NodeConnectionInterface return $this->read(); } - /** - * Helper method that returns an exception message augmented with useful - * details from the connection parameters. - * - * @param string $message Error message. - * - * @return string - */ - private function createExceptionMessage($message) - { - $parameters = $this->parameters; - - if ($parameters->scheme === 'unix') { - return "$message [$parameters->scheme:$parameters->path]"; - } - - if (filter_var($parameters->host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { - return "$message [$parameters->scheme://[$parameters->host]:$parameters->port]"; - } - - return "$message [$parameters->scheme://$parameters->host:$parameters->port]"; - } - /** * Helper method to handle connection errors. * * @param string $message Error message. * @param int $code Error code. */ - protected function onConnectionError($message, $code = null) + protected function onConnectionError($message, $code = 0) { CommunicationException::handle( - new ConnectionException($this, static::createExceptionMessage($message), $code) + new ConnectionException($this, "$message [{$this->getParameters()}]", $code) ); } @@ -177,7 +153,7 @@ abstract class AbstractConnection implements NodeConnectionInterface protected function onProtocolError($message) { CommunicationException::handle( - new ProtocolException($this, static::createExceptionMessage($message)) + new ProtocolException($this, "$message [{$this->getParameters()}]") ); } @@ -234,6 +210,6 @@ abstract class AbstractConnection implements NodeConnectionInterface */ public function __sleep() { - return array('parameters', 'initCommands'); + return ['parameters', 'initCommands']; } } diff --git a/plugins/cache-redis/Predis/Connection/Aggregate/ClusterInterface.php b/plugins/cache-redis/Predis/Connection/Aggregate/ClusterInterface.php deleted file mode 100644 index af0f5aab5..000000000 --- a/plugins/cache-redis/Predis/Connection/Aggregate/ClusterInterface.php +++ /dev/null @@ -1,24 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Connection\Aggregate; - -use Predis\Connection\AggregateConnectionInterface; - -/** - * Defines a cluster of Redis servers formed by aggregating multiple connection - * instances to single Redis nodes. - * - * @author Daniele Alessandri - */ -interface ClusterInterface extends AggregateConnectionInterface -{ -} diff --git a/plugins/cache-redis/Predis/Connection/Aggregate/MasterSlaveReplication.php b/plugins/cache-redis/Predis/Connection/Aggregate/MasterSlaveReplication.php deleted file mode 100644 index 3104a753c..000000000 --- a/plugins/cache-redis/Predis/Connection/Aggregate/MasterSlaveReplication.php +++ /dev/null @@ -1,264 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Connection\Aggregate; - -use Predis\Command\CommandInterface; -use Predis\Connection\NodeConnectionInterface; -use Predis\Replication\ReplicationStrategy; - -/** - * Aggregate connection handling replication of Redis nodes configured in a - * single master / multiple slaves setup. - * - * @author Daniele Alessandri - */ -class MasterSlaveReplication implements ReplicationInterface -{ - protected $strategy; - protected $master; - protected $slaves; - protected $current; - - /** - * {@inheritdoc} - */ - public function __construct(ReplicationStrategy $strategy = null) - { - $this->slaves = array(); - $this->strategy = $strategy ?: new ReplicationStrategy(); - } - - /** - * Checks if one master and at least one slave have been defined. - */ - protected function check() - { - if (!isset($this->master) || !$this->slaves) { - throw new \RuntimeException('Replication needs one master and at least one slave.'); - } - } - - /** - * Resets the connection state. - */ - protected function reset() - { - $this->current = null; - } - - /** - * {@inheritdoc} - */ - public function add(NodeConnectionInterface $connection) - { - $alias = $connection->getParameters()->alias; - - if ($alias === 'master') { - $this->master = $connection; - } else { - $this->slaves[$alias ?: count($this->slaves)] = $connection; - } - - $this->reset(); - } - - /** - * {@inheritdoc} - */ - public function remove(NodeConnectionInterface $connection) - { - if ($connection->getParameters()->alias === 'master') { - $this->master = null; - $this->reset(); - - return true; - } else { - if (($id = array_search($connection, $this->slaves, true)) !== false) { - unset($this->slaves[$id]); - $this->reset(); - - return true; - } - } - - return false; - } - - /** - * {@inheritdoc} - */ - public function getConnection(CommandInterface $command) - { - if ($this->current === null) { - $this->check(); - $this->current = $this->strategy->isReadOperation($command) - ? $this->pickSlave() - : $this->master; - - return $this->current; - } - - if ($this->current === $this->master) { - return $this->current; - } - - if (!$this->strategy->isReadOperation($command)) { - $this->current = $this->master; - } - - return $this->current; - } - - /** - * {@inheritdoc} - */ - public function getConnectionById($connectionId) - { - if ($connectionId === 'master') { - return $this->master; - } - - if (isset($this->slaves[$connectionId])) { - return $this->slaves[$connectionId]; - } - - return; - } - - /** - * {@inheritdoc} - */ - public function switchTo($connection) - { - $this->check(); - - if (!$connection instanceof NodeConnectionInterface) { - $connection = $this->getConnectionById($connection); - } - if ($connection !== $this->master && !in_array($connection, $this->slaves, true)) { - throw new \InvalidArgumentException('Invalid connection or connection not found.'); - } - - $this->current = $connection; - } - - /** - * {@inheritdoc} - */ - public function getCurrent() - { - return $this->current; - } - - /** - * {@inheritdoc} - */ - public function getMaster() - { - return $this->master; - } - - /** - * {@inheritdoc} - */ - public function getSlaves() - { - return array_values($this->slaves); - } - - /** - * Returns the underlying replication strategy. - * - * @return ReplicationStrategy - */ - public function getReplicationStrategy() - { - return $this->strategy; - } - - /** - * Returns a random slave. - * - * @return NodeConnectionInterface - */ - protected function pickSlave() - { - return $this->slaves[array_rand($this->slaves)]; - } - - /** - * {@inheritdoc} - */ - public function isConnected() - { - return $this->current ? $this->current->isConnected() : false; - } - - /** - * {@inheritdoc} - */ - public function connect() - { - if ($this->current === null) { - $this->check(); - $this->current = $this->pickSlave(); - } - - $this->current->connect(); - } - - /** - * {@inheritdoc} - */ - public function disconnect() - { - if ($this->master) { - $this->master->disconnect(); - } - - foreach ($this->slaves as $connection) { - $connection->disconnect(); - } - } - - /** - * {@inheritdoc} - */ - public function writeRequest(CommandInterface $command) - { - $this->getConnection($command)->writeRequest($command); - } - - /** - * {@inheritdoc} - */ - public function readResponse(CommandInterface $command) - { - return $this->getConnection($command)->readResponse($command); - } - - /** - * {@inheritdoc} - */ - public function executeCommand(CommandInterface $command) - { - return $this->getConnection($command)->executeCommand($command); - } - - /** - * {@inheritdoc} - */ - public function __sleep() - { - return array('master', 'slaves', 'strategy'); - } -} diff --git a/plugins/cache-redis/Predis/Connection/Aggregate/PredisCluster.php b/plugins/cache-redis/Predis/Connection/Aggregate/PredisCluster.php deleted file mode 100644 index 33f98bf2e..000000000 --- a/plugins/cache-redis/Predis/Connection/Aggregate/PredisCluster.php +++ /dev/null @@ -1,235 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Connection\Aggregate; - -use Predis\Cluster\PredisStrategy; -use Predis\Cluster\StrategyInterface; -use Predis\Command\CommandInterface; -use Predis\Connection\NodeConnectionInterface; -use Predis\NotSupportedException; - -/** - * Abstraction for a cluster of aggregate connections to various Redis servers - * implementing client-side sharding based on pluggable distribution strategies. - * - * @author Daniele Alessandri - * - * @todo Add the ability to remove connections from pool. - */ -class PredisCluster implements ClusterInterface, \IteratorAggregate, \Countable -{ - private $pool; - private $strategy; - private $distributor; - - /** - * @param StrategyInterface $strategy Optional cluster strategy. - */ - public function __construct(StrategyInterface $strategy = null) - { - $this->pool = array(); - $this->strategy = $strategy ?: new PredisStrategy(); - $this->distributor = $this->strategy->getDistributor(); - } - - /** - * {@inheritdoc} - */ - public function isConnected() - { - foreach ($this->pool as $connection) { - if ($connection->isConnected()) { - return true; - } - } - - return false; - } - - /** - * {@inheritdoc} - */ - public function connect() - { - foreach ($this->pool as $connection) { - $connection->connect(); - } - } - - /** - * {@inheritdoc} - */ - public function disconnect() - { - foreach ($this->pool as $connection) { - $connection->disconnect(); - } - } - - /** - * {@inheritdoc} - */ - public function add(NodeConnectionInterface $connection) - { - $parameters = $connection->getParameters(); - - if (isset($parameters->alias)) { - $this->pool[$parameters->alias] = $connection; - } else { - $this->pool[] = $connection; - } - - $weight = isset($parameters->weight) ? $parameters->weight : null; - $this->distributor->add($connection, $weight); - } - - /** - * {@inheritdoc} - */ - public function remove(NodeConnectionInterface $connection) - { - if (($id = array_search($connection, $this->pool, true)) !== false) { - unset($this->pool[$id]); - $this->distributor->remove($connection); - - return true; - } - - return false; - } - - /** - * Removes a connection instance using its alias or index. - * - * @param string $connectionID Alias or index of a connection. - * - * @return bool Returns true if the connection was in the pool. - */ - public function removeById($connectionID) - { - if ($connection = $this->getConnectionById($connectionID)) { - return $this->remove($connection); - } - - return false; - } - - /** - * {@inheritdoc} - */ - public function getConnection(CommandInterface $command) - { - $slot = $this->strategy->getSlot($command); - - if (!isset($slot)) { - throw new NotSupportedException( - "Cannot use '{$command->getId()}' over clusters of connections." - ); - } - - $node = $this->distributor->getBySlot($slot); - - return $node; - } - - /** - * {@inheritdoc} - */ - public function getConnectionById($connectionID) - { - return isset($this->pool[$connectionID]) ? $this->pool[$connectionID] : null; - } - - /** - * Retrieves a connection instance from the cluster using a key. - * - * @param string $key Key string. - * - * @return NodeConnectionInterface - */ - public function getConnectionByKey($key) - { - $hash = $this->strategy->getSlotByKey($key); - $node = $this->distributor->getBySlot($hash); - - return $node; - } - - /** - * Returns the underlying command hash strategy used to hash commands by - * using keys found in their arguments. - * - * @return StrategyInterface - */ - public function getClusterStrategy() - { - return $this->strategy; - } - - /** - * {@inheritdoc} - */ - public function count() - { - return count($this->pool); - } - - /** - * {@inheritdoc} - */ - public function getIterator() - { - return new \ArrayIterator($this->pool); - } - - /** - * {@inheritdoc} - */ - public function writeRequest(CommandInterface $command) - { - $this->getConnection($command)->writeRequest($command); - } - - /** - * {@inheritdoc} - */ - public function readResponse(CommandInterface $command) - { - return $this->getConnection($command)->readResponse($command); - } - - /** - * {@inheritdoc} - */ - public function executeCommand(CommandInterface $command) - { - return $this->getConnection($command)->executeCommand($command); - } - - /** - * Executes the specified Redis command on all the nodes of a cluster. - * - * @param CommandInterface $command A Redis command. - * - * @return array - */ - public function executeCommandOnNodes(CommandInterface $command) - { - $responses = array(); - - foreach ($this->pool as $connection) { - $responses[] = $connection->executeCommand($command); - } - - return $responses; - } -} diff --git a/plugins/cache-redis/Predis/Connection/Aggregate/RedisCluster.php b/plugins/cache-redis/Predis/Connection/Aggregate/RedisCluster.php deleted file mode 100644 index 337c28702..000000000 --- a/plugins/cache-redis/Predis/Connection/Aggregate/RedisCluster.php +++ /dev/null @@ -1,553 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Connection\Aggregate; - -use Predis\Cluster\RedisStrategy as RedisClusterStrategy; -use Predis\Cluster\StrategyInterface; -use Predis\Command\CommandInterface; -use Predis\Command\RawCommand; -use Predis\Connection\FactoryInterface; -use Predis\Connection\NodeConnectionInterface; -use Predis\NotSupportedException; -use Predis\Response\ErrorInterface as ErrorResponseInterface; - -/** - * Abstraction for a Redis-backed cluster of nodes (Redis >= 3.0.0). - * - * This connection backend offers smart support for redis-cluster by handling - * automatic slots map (re)generation upon -MOVED or -ASK responses returned by - * Redis when redirecting a client to a different node. - * - * The cluster can be pre-initialized using only a subset of the actual nodes in - * the cluster, Predis will do the rest by adjusting the slots map and creating - * the missing underlying connection instances on the fly. - * - * It is possible to pre-associate connections to a slots range with the "slots" - * parameter in the form "$first-$last". This can greatly reduce runtime node - * guessing and redirections. - * - * It is also possible to ask for the full and updated slots map directly to one - * of the nodes and optionally enable such a behaviour upon -MOVED redirections. - * Asking for the cluster configuration to Redis is actually done by issuing a - * CLUSTER SLOTS command to a random node in the pool. - * - * @author Daniele Alessandri - */ -class RedisCluster implements ClusterInterface, \IteratorAggregate, \Countable -{ - private $useClusterSlots = true; - private $defaultParameters = array(); - private $pool = array(); - private $slots = array(); - private $slotsMap; - private $strategy; - private $connections; - - /** - * @param FactoryInterface $connections Optional connection factory. - * @param StrategyInterface $strategy Optional cluster strategy. - */ - public function __construct( - FactoryInterface $connections, - StrategyInterface $strategy = null - ) { - $this->connections = $connections; - $this->strategy = $strategy ?: new RedisClusterStrategy(); - } - - /** - * {@inheritdoc} - */ - public function isConnected() - { - foreach ($this->pool as $connection) { - if ($connection->isConnected()) { - return true; - } - } - - return false; - } - - /** - * {@inheritdoc} - */ - public function connect() - { - if ($connection = $this->getRandomConnection()) { - $connection->connect(); - } - } - - /** - * {@inheritdoc} - */ - public function disconnect() - { - foreach ($this->pool as $connection) { - $connection->disconnect(); - } - } - - /** - * {@inheritdoc} - */ - public function add(NodeConnectionInterface $connection) - { - $this->pool[(string) $connection] = $connection; - unset($this->slotsMap); - } - - /** - * {@inheritdoc} - */ - public function remove(NodeConnectionInterface $connection) - { - if (false !== $id = array_search($connection, $this->pool, true)) { - unset( - $this->pool[$id], - $this->slotsMap - ); - - return true; - } - - return false; - } - - /** - * Removes a connection instance by using its identifier. - * - * @param string $connectionID Connection identifier. - * - * @return bool True if the connection was in the pool. - */ - public function removeById($connectionID) - { - if (isset($this->pool[$connectionID])) { - unset( - $this->pool[$connectionID], - $this->slotsMap - ); - - return true; - } - - return false; - } - - /** - * Generates the current slots map by guessing the cluster configuration out - * of the connection parameters of the connections in the pool. - * - * Generation is based on the same algorithm used by Redis to generate the - * cluster, so it is most effective when all of the connections supplied on - * initialization have the "slots" parameter properly set accordingly to the - * current cluster configuration. - */ - public function buildSlotsMap() - { - $this->slotsMap = array(); - - foreach ($this->pool as $connectionID => $connection) { - $parameters = $connection->getParameters(); - - if (!isset($parameters->slots)) { - continue; - } - - $slots = explode('-', $parameters->slots, 2); - $this->setSlots($slots[0], $slots[1], $connectionID); - } - } - - /** - * Generates an updated slots map fetching the cluster configuration using - * the CLUSTER SLOTS command against the specified node or a random one from - * the pool. - * - * @param NodeConnectionInterface $connection Optional connection instance. - * - * @return array - */ - public function askSlotsMap(NodeConnectionInterface $connection = null) - { - if (!$connection && !$connection = $this->getRandomConnection()) { - return array(); - } - - $command = RawCommand::create('CLUSTER', 'SLOTS'); - $response = $connection->executeCommand($command); - - foreach ($response as $slots) { - // We only support master servers for now, so we ignore subsequent - // elements in the $slots array identifying slaves. - list($start, $end, $master) = $slots; - - if ($master[0] === '') { - $this->setSlots($start, $end, (string) $connection); - } else { - $this->setSlots($start, $end, "{$master[0]}:{$master[1]}"); - } - } - - return $this->slotsMap; - } - - /** - * Returns the current slots map for the cluster. - * - * @return array - */ - public function getSlotsMap() - { - if (!isset($this->slotsMap)) { - $this->slotsMap = array(); - } - - return $this->slotsMap; - } - - /** - * Pre-associates a connection to a slots range to avoid runtime guessing. - * - * @param int $first Initial slot of the range. - * @param int $last Last slot of the range. - * @param NodeConnectionInterface|string $connection ID or connection instance. - * - * @throws \OutOfBoundsException - */ - public function setSlots($first, $last, $connection) - { - if ($first < 0x0000 || $first > 0x3FFF || - $last < 0x0000 || $last > 0x3FFF || - $last < $first - ) { - throw new \OutOfBoundsException( - "Invalid slot range for $connection: [$first-$last]." - ); - } - - $slots = array_fill($first, $last - $first + 1, (string) $connection); - $this->slotsMap = $this->getSlotsMap() + $slots; - } - - /** - * Guesses the correct node associated to a given slot using a precalculated - * slots map, falling back to the same logic used by Redis to initialize a - * cluster (best-effort). - * - * @param int $slot Slot index. - * - * @return string Connection ID. - */ - protected function guessNode($slot) - { - if (!isset($this->slotsMap)) { - $this->buildSlotsMap(); - } - - if (isset($this->slotsMap[$slot])) { - return $this->slotsMap[$slot]; - } - - $count = count($this->pool); - $index = min((int) ($slot / (int) (16384 / $count)), $count - 1); - $nodes = array_keys($this->pool); - - return $nodes[$index]; - } - - /** - * Creates a new connection instance from the given connection ID. - * - * @param string $connectionID Identifier for the connection. - * - * @return NodeConnectionInterface - */ - protected function createConnection($connectionID) - { - $separator = strrpos($connectionID, ':'); - - $parameters = array_merge($this->defaultParameters, array( - 'host' => substr($connectionID, 0, $separator), - 'port' => substr($connectionID, $separator + 1), - )); - - $connection = $this->connections->create($parameters); - - return $connection; - } - - /** - * {@inheritdoc} - */ - public function getConnection(CommandInterface $command) - { - $slot = $this->strategy->getSlot($command); - - if (!isset($slot)) { - throw new NotSupportedException( - "Cannot use '{$command->getId()}' with redis-cluster." - ); - } - - if (isset($this->slots[$slot])) { - return $this->slots[$slot]; - } else { - return $this->getConnectionBySlot($slot); - } - } - - /** - * Returns the connection currently associated to a given slot. - * - * @param int $slot Slot index. - * - * @throws \OutOfBoundsException - * - * @return NodeConnectionInterface - */ - public function getConnectionBySlot($slot) - { - if ($slot < 0x0000 || $slot > 0x3FFF) { - throw new \OutOfBoundsException("Invalid slot [$slot]."); - } - - if (isset($this->slots[$slot])) { - return $this->slots[$slot]; - } - - $connectionID = $this->guessNode($slot); - - if (!$connection = $this->getConnectionById($connectionID)) { - $connection = $this->createConnection($connectionID); - $this->pool[$connectionID] = $connection; - } - - return $this->slots[$slot] = $connection; - } - - /** - * {@inheritdoc} - */ - public function getConnectionById($connectionID) - { - if (isset($this->pool[$connectionID])) { - return $this->pool[$connectionID]; - } - } - - /** - * Returns a random connection from the pool. - * - * @return NodeConnectionInterface|null - */ - protected function getRandomConnection() - { - if ($this->pool) { - return $this->pool[array_rand($this->pool)]; - } - } - - /** - * Permanently associates the connection instance to a new slot. - * The connection is added to the connections pool if not yet included. - * - * @param NodeConnectionInterface $connection Connection instance. - * @param int $slot Target slot index. - */ - protected function move(NodeConnectionInterface $connection, $slot) - { - $this->pool[(string) $connection] = $connection; - $this->slots[(int) $slot] = $connection; - } - - /** - * Handles -ERR responses returned by Redis. - * - * @param CommandInterface $command Command that generated the -ERR response. - * @param ErrorResponseInterface $error Redis error response object. - * - * @return mixed - */ - protected function onErrorResponse(CommandInterface $command, ErrorResponseInterface $error) - { - $details = explode(' ', $error->getMessage(), 2); - - switch ($details[0]) { - case 'MOVED': - return $this->onMovedResponse($command, $details[1]); - - case 'ASK': - return $this->onAskResponse($command, $details[1]); - - default: - return $error; - } - } - - /** - * Handles -MOVED responses by executing again the command against the node - * indicated by the Redis response. - * - * @param CommandInterface $command Command that generated the -MOVED response. - * @param string $details Parameters of the -MOVED response. - * - * @return mixed - */ - protected function onMovedResponse(CommandInterface $command, $details) - { - list($slot, $connectionID) = explode(' ', $details, 2); - - if (!$connection = $this->getConnectionById($connectionID)) { - $connection = $this->createConnection($connectionID); - } - - if ($this->useClusterSlots) { - $this->askSlotsMap($connection); - } - - $this->move($connection, $slot); - $response = $this->executeCommand($command); - - return $response; - } - - /** - * Handles -ASK responses by executing again the command against the node - * indicated by the Redis response. - * - * @param CommandInterface $command Command that generated the -ASK response. - * @param string $details Parameters of the -ASK response. - * - * @return mixed - */ - protected function onAskResponse(CommandInterface $command, $details) - { - list($slot, $connectionID) = explode(' ', $details, 2); - - if (!$connection = $this->getConnectionById($connectionID)) { - $connection = $this->createConnection($connectionID); - } - - $connection->executeCommand(RawCommand::create('ASKING')); - $response = $connection->executeCommand($command); - - return $response; - } - - /** - * {@inheritdoc} - */ - public function writeRequest(CommandInterface $command) - { - $this->getConnection($command)->writeRequest($command); - } - - /** - * {@inheritdoc} - */ - public function readResponse(CommandInterface $command) - { - return $this->getConnection($command)->readResponse($command); - } - - /** - * {@inheritdoc} - */ - public function executeCommand(CommandInterface $command) - { - $connection = $this->getConnection($command); - $response = $connection->executeCommand($command); - - if ($response instanceof ErrorResponseInterface) { - return $this->onErrorResponse($command, $response); - } - - return $response; - } - - /** - * {@inheritdoc} - */ - public function count() - { - return count($this->pool); - } - - /** - * {@inheritdoc} - */ - public function getIterator() - { - return new \ArrayIterator(array_values($this->pool)); - } - - /** - * Returns the underlying command hash strategy used to hash commands by - * using keys found in their arguments. - * - * @return StrategyInterface - */ - public function getClusterStrategy() - { - return $this->strategy; - } - - /** - * Returns the underlying connection factory used to create new connection - * instances to Redis nodes indicated by redis-cluster. - * - * @return FactoryInterface - */ - public function getConnectionFactory() - { - return $this->connections; - } - - /** - * Enables automatic fetching of the current slots map from one of the nodes - * using the CLUSTER SLOTS command. This option is disabled by default but - * asking the current slots map to Redis upon -MOVED responses may reduce - * overhead by eliminating the trial-and-error nature of the node guessing - * procedure, mostly when targeting many keys that would end up in a lot of - * redirections. - * - * The slots map can still be manually fetched using the askSlotsMap() - * method whether or not this option is enabled. - * - * @param bool $value Enable or disable the use of CLUSTER SLOTS. - */ - public function useClusterSlots($value) - { - $this->useClusterSlots = (bool) $value; - } - - /** - * Sets a default array of connection parameters to be applied when creating - * new connection instances on the fly when they are not part of the initial - * pool supplied upon cluster initialization. - * - * These parameters are not applied to connections added to the pool using - * the add() method. - * - * @param array $parameters Array of connection parameters. - */ - public function setDefaultParameters(array $parameters) - { - $this->defaultParameters = array_merge( - $this->defaultParameters, - $parameters ?: array() - ); - } -} diff --git a/plugins/cache-redis/Predis/Connection/Aggregate/ReplicationInterface.php b/plugins/cache-redis/Predis/Connection/Aggregate/ReplicationInterface.php deleted file mode 100644 index e09e8265c..000000000 --- a/plugins/cache-redis/Predis/Connection/Aggregate/ReplicationInterface.php +++ /dev/null @@ -1,52 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Connection\Aggregate; - -use Predis\Connection\AggregateConnectionInterface; -use Predis\Connection\NodeConnectionInterface; - -/** - * Defines a group of Redis nodes in a master / slave replication setup. - * - * @author Daniele Alessandri - */ -interface ReplicationInterface extends AggregateConnectionInterface -{ - /** - * Switches the internal connection instance in use. - * - * @param string $connection Alias of a connection - */ - public function switchTo($connection); - - /** - * Returns the connection instance currently in use by the aggregate - * connection. - * - * @return NodeConnectionInterface - */ - public function getCurrent(); - - /** - * Returns the connection instance for the master Redis node. - * - * @return NodeConnectionInterface - */ - public function getMaster(); - - /** - * Returns a list of connection instances to slave nodes. - * - * @return NodeConnectionInterface - */ - public function getSlaves(); -} diff --git a/plugins/cache-redis/Predis/Connection/AggregateConnectionInterface.php b/plugins/cache-redis/Predis/Connection/AggregateConnectionInterface.php index 7eeaede76..8864bba53 100644 --- a/plugins/cache-redis/Predis/Connection/AggregateConnectionInterface.php +++ b/plugins/cache-redis/Predis/Connection/AggregateConnectionInterface.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -16,8 +17,6 @@ use Predis\Command\CommandInterface; /** * Defines a virtual connection composed of multiple connection instances to * single Redis nodes. - * - * @author Daniele Alessandri */ interface AggregateConnectionInterface extends ConnectionInterface { @@ -44,7 +43,7 @@ interface AggregateConnectionInterface extends ConnectionInterface * * @return NodeConnectionInterface */ - public function getConnection(CommandInterface $command); + public function getConnectionByCommand(CommandInterface $command); /** * Returns a connection instance from the aggregate connection by its alias. diff --git a/plugins/cache-redis/Predis/Connection/CompositeConnectionInterface.php b/plugins/cache-redis/Predis/Connection/CompositeConnectionInterface.php index 286e082cc..22b8c5f77 100644 --- a/plugins/cache-redis/Predis/Connection/CompositeConnectionInterface.php +++ b/plugins/cache-redis/Predis/Connection/CompositeConnectionInterface.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,8 +15,6 @@ namespace Predis\Connection; /** * Defines a connection to communicate with a single Redis server that leverages * an external protocol processor to handle pluggable protocol handlers. - * - * @author Daniele Alessandri */ interface CompositeConnectionInterface extends NodeConnectionInterface { @@ -34,7 +33,7 @@ interface CompositeConnectionInterface extends NodeConnectionInterface /** * Reads the given number of bytes from the connection. * - * @param int $length Number of bytes to read from the connection. + * @param int $length Number of bytes to read from the connection. * * @return string */ @@ -43,7 +42,7 @@ interface CompositeConnectionInterface extends NodeConnectionInterface /** * Reads a line from the connection. * - * @param string + * @return string */ public function readLine(); } diff --git a/plugins/cache-redis/Predis/Connection/CompositeStreamConnection.php b/plugins/cache-redis/Predis/Connection/CompositeStreamConnection.php index 7a3534054..ad69cbc12 100644 --- a/plugins/cache-redis/Predis/Connection/CompositeStreamConnection.php +++ b/plugins/cache-redis/Predis/Connection/CompositeStreamConnection.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,6 +12,7 @@ namespace Predis\Connection; +use InvalidArgumentException; use Predis\Command\CommandInterface; use Predis\Protocol\ProtocolProcessorInterface; use Predis\Protocol\Text\ProtocolProcessor as TextProtocolProcessor; @@ -18,8 +20,6 @@ use Predis\Protocol\Text\ProtocolProcessor as TextProtocolProcessor; /** * Connection abstraction to Redis servers based on PHP's stream that uses an * external protocol processor defining the protocol used for the communication. - * - * @author Daniele Alessandri */ class CompositeStreamConnection extends StreamConnection implements CompositeConnectionInterface { @@ -59,7 +59,7 @@ class CompositeStreamConnection extends StreamConnection implements CompositeCon public function readBuffer($length) { if ($length <= 0) { - throw new \InvalidArgumentException('Length parameter must be greater than 0.'); + throw new InvalidArgumentException('Length parameter must be greater than 0.'); } $value = ''; @@ -120,6 +120,6 @@ class CompositeStreamConnection extends StreamConnection implements CompositeCon */ public function __sleep() { - return array_merge(parent::__sleep(), array('protocol')); + return array_merge(parent::__sleep(), ['protocol']); } } diff --git a/plugins/cache-redis/Predis/Connection/ConnectionException.php b/plugins/cache-redis/Predis/Connection/ConnectionException.php index ef2e9d73a..77e7a15a0 100644 --- a/plugins/cache-redis/Predis/Connection/ConnectionException.php +++ b/plugins/cache-redis/Predis/Connection/ConnectionException.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -15,8 +16,6 @@ use Predis\CommunicationException; /** * Exception class that identifies connection-related errors. - * - * @author Daniele Alessandri */ class ConnectionException extends CommunicationException { diff --git a/plugins/cache-redis/Predis/Connection/ConnectionInterface.php b/plugins/cache-redis/Predis/Connection/ConnectionInterface.php index 11ace1b69..fc2014612 100644 --- a/plugins/cache-redis/Predis/Connection/ConnectionInterface.php +++ b/plugins/cache-redis/Predis/Connection/ConnectionInterface.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -16,8 +17,6 @@ use Predis\Command\CommandInterface; /** * Defines a connection object used to communicate with one or multiple * Redis servers. - * - * @author Daniele Alessandri */ interface ConnectionInterface { diff --git a/plugins/cache-redis/Predis/Connection/Factory.php b/plugins/cache-redis/Predis/Connection/Factory.php index c2e93f880..86b18c4a0 100644 --- a/plugins/cache-redis/Predis/Connection/Factory.php +++ b/plugins/cache-redis/Predis/Connection/Factory.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,21 +12,27 @@ namespace Predis\Connection; +use InvalidArgumentException; +use Predis\Client; use Predis\Command\RawCommand; +use ReflectionClass; +use UnexpectedValueException; /** * Standard connection factory for creating connections to Redis nodes. - * - * @author Daniele Alessandri */ class Factory implements FactoryInterface { - protected $schemes = array( + private $defaults = []; + + protected $schemes = [ 'tcp' => 'Predis\Connection\StreamConnection', 'unix' => 'Predis\Connection\StreamConnection', + 'tls' => 'Predis\Connection\StreamConnection', 'redis' => 'Predis\Connection\StreamConnection', + 'rediss' => 'Predis\Connection\StreamConnection', 'http' => 'Predis\Connection\WebdisConnection', - ); + ]; /** * Checks if the provided argument represents a valid connection class @@ -34,9 +41,8 @@ class Factory implements FactoryInterface * * @param mixed $initializer FQN of a connection class or a callable for lazy initialization. * - * @throws \InvalidArgumentException - * * @return mixed + * @throws InvalidArgumentException */ protected function checkInitializer($initializer) { @@ -44,10 +50,10 @@ class Factory implements FactoryInterface return $initializer; } - $class = new \ReflectionClass($initializer); + $class = new ReflectionClass($initializer); if (!$class->isSubclassOf('Predis\Connection\NodeConnectionInterface')) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'A connection initializer must be a valid connection class or a callable object.' ); } @@ -83,7 +89,7 @@ class Factory implements FactoryInterface $scheme = $parameters->scheme; if (!isset($this->schemes[$scheme])) { - throw new \InvalidArgumentException("Unknown connection scheme: '$scheme'."); + throw new InvalidArgumentException("Unknown connection scheme: '$scheme'."); } $initializer = $this->schemes[$scheme]; @@ -96,8 +102,8 @@ class Factory implements FactoryInterface } if (!$connection instanceof NodeConnectionInterface) { - throw new \UnexpectedValueException( - 'Objects returned by connection initializers must implement '. + throw new UnexpectedValueException( + 'Objects returned by connection initializers must implement ' . "'Predis\Connection\NodeConnectionInterface'." ); } @@ -106,13 +112,26 @@ class Factory implements FactoryInterface } /** - * {@inheritdoc} + * Assigns a default set of parameters applied to new connections. + * + * The set of parameters passed to create a new connection have precedence + * over the default values set for the connection factory. + * + * @param array $parameters Set of connection parameters. */ - public function aggregate(AggregateConnectionInterface $connection, array $parameters) + public function setDefaultParameters(array $parameters) { - foreach ($parameters as $node) { - $connection->add($node instanceof NodeConnectionInterface ? $node : $this->create($node)); - } + $this->defaults = $parameters; + } + + /** + * Returns the default set of parameters applied to new connections. + * + * @return array + */ + public function getDefaultParameters() + { + return $this->defaults; } /** @@ -124,7 +143,17 @@ class Factory implements FactoryInterface */ protected function createParameters($parameters) { - return Parameters::create($parameters); + if (is_string($parameters)) { + $parameters = Parameters::parse($parameters); + } else { + $parameters = $parameters ?: []; + } + + if ($this->defaults) { + $parameters += $this->defaults; + } + + return new Parameters($parameters); } /** @@ -136,15 +165,29 @@ class Factory implements FactoryInterface { $parameters = $connection->getParameters(); - if (isset($parameters->password)) { + if (isset($parameters->password) && strlen($parameters->password)) { + $cmdAuthArgs = isset($parameters->username) && strlen($parameters->username) + ? [$parameters->username, $parameters->password] + : [$parameters->password]; + $connection->addConnectCommand( - new RawCommand(array('AUTH', $parameters->password)) + new RawCommand('AUTH', $cmdAuthArgs) ); } - if (isset($parameters->database)) { + if ($parameters->client_info ?? false && !$connection instanceof RelayConnection) { $connection->addConnectCommand( - new RawCommand(array('SELECT', $parameters->database)) + new RawCommand('CLIENT', ['SETINFO', 'LIB-NAME', 'predis']) + ); + + $connection->addConnectCommand( + new RawCommand('CLIENT', ['SETINFO', 'LIB-VER', Client::VERSION]) + ); + } + + if (isset($parameters->database) && strlen($parameters->database)) { + $connection->addConnectCommand( + new RawCommand('SELECT', [$parameters->database]) ); } } diff --git a/plugins/cache-redis/Predis/Connection/FactoryInterface.php b/plugins/cache-redis/Predis/Connection/FactoryInterface.php index 2bae0839e..24dc782a8 100644 --- a/plugins/cache-redis/Predis/Connection/FactoryInterface.php +++ b/plugins/cache-redis/Predis/Connection/FactoryInterface.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,8 +14,6 @@ namespace Predis\Connection; /** * Interface for classes providing a factory of connections to Redis nodes. - * - * @author Daniele Alessandri */ interface FactoryInterface { @@ -41,12 +40,4 @@ interface FactoryInterface * @return NodeConnectionInterface */ public function create($parameters); - - /** - * Aggregates single connections into an aggregate connection instance. - * - * @param AggregateConnectionInterface $aggregate Aggregate connection instance. - * @param array $parameters List of parameters for each connection. - */ - public function aggregate(AggregateConnectionInterface $aggregate, array $parameters); } diff --git a/plugins/cache-redis/Predis/Connection/NodeConnectionInterface.php b/plugins/cache-redis/Predis/Connection/NodeConnectionInterface.php index 665b862c1..713331776 100644 --- a/plugins/cache-redis/Predis/Connection/NodeConnectionInterface.php +++ b/plugins/cache-redis/Predis/Connection/NodeConnectionInterface.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -15,8 +16,6 @@ use Predis\Command\CommandInterface; /** * Defines a connection used to communicate with a single Redis node. - * - * @author Daniele Alessandri */ interface NodeConnectionInterface extends ConnectionInterface { diff --git a/plugins/cache-redis/Predis/Connection/Parameters.php b/plugins/cache-redis/Predis/Connection/Parameters.php index b7d986153..170d7e28e 100644 --- a/plugins/cache-redis/Predis/Connection/Parameters.php +++ b/plugins/cache-redis/Predis/Connection/Parameters.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,40 +12,49 @@ namespace Predis\Connection; +use InvalidArgumentException; + /** * Container for connection parameters used to initialize connections to Redis. * * {@inheritdoc} - * - * @author Daniele Alessandri */ class Parameters implements ParametersInterface { - private $parameters; - - private static $defaults = array( + protected static $defaults = [ 'scheme' => 'tcp', 'host' => '127.0.0.1', 'port' => 6379, - 'timeout' => 5.0, - ); + ]; + + /** + * Set of connection parameters already filtered + * for NULL or 0-length string values. + * + * @var array + */ + protected $parameters; /** * @param array $parameters Named array of connection parameters. */ - public function __construct(array $parameters = array()) + public function __construct(array $parameters = []) { - $this->parameters = $this->filter($parameters) + $this->getDefaults(); + $this->parameters = $this->filter($parameters + static::$defaults); } /** - * Returns some default parameters with their values. + * Filters parameters removing entries with NULL or 0-length string values. + * + * @params array $parameters Array of parameters to be filtered * * @return array */ - protected function getDefaults() + protected function filter(array $parameters) { - return self::$defaults; + return array_filter($parameters, function ($value) { + return $value !== null && $value !== ''; + }); } /** @@ -61,7 +71,7 @@ class Parameters implements ParametersInterface $parameters = static::parse($parameters); } - return new static($parameters ?: array()); + return new static($parameters ?: []); } /** @@ -73,24 +83,24 @@ class Parameters implements ParametersInterface * database number in the "path" part these values override the values of * "password" and "database" if they are present in the "query" part. * - * @link http://www.iana.org/assignments/uri-schemes/prov/redis - * @link http://www.iana.org/assignments/uri-schemes/prov/redis + * @see http://www.iana.org/assignments/uri-schemes/prov/redis + * @see http://www.iana.org/assignments/uri-schemes/prov/rediss * * @param string $uri URI string. * - * @throws \InvalidArgumentException - * * @return array + * @throws InvalidArgumentException */ public static function parse($uri) { - if (stripos($uri, 'unix') === 0) { - // Hack to support URIs for UNIX sockets with minimal effort. - $uri = str_ireplace('unix:///', 'unix://localhost/', $uri); + if (stripos($uri, 'unix://') === 0) { + // parse_url() can parse unix:/path/to/sock so we do not need the + // unix:///path/to/sock hack, we will support it anyway until 2.0. + $uri = str_ireplace('unix://', 'unix:', $uri); } if (!$parsed = parse_url($uri)) { - throw new \InvalidArgumentException("Invalid parameters URI: $uri"); + throw new InvalidArgumentException("Invalid parameters URI: $uri"); } if ( @@ -109,8 +119,17 @@ class Parameters implements ParametersInterface } if (stripos($uri, 'redis') === 0) { + if (isset($parsed['user'])) { + if (strlen($parsed['user'])) { + $parsed['username'] = $parsed['user']; + } + unset($parsed['user']); + } + if (isset($parsed['pass'])) { - $parsed['password'] = $parsed['pass']; + if (strlen($parsed['pass'])) { + $parsed['password'] = $parsed['pass']; + } unset($parsed['pass']); } @@ -129,15 +148,11 @@ class Parameters implements ParametersInterface } /** - * Validates and converts each value of the connection parameters array. - * - * @param array $parameters Connection parameters. - * - * @return array + * {@inheritdoc} */ - protected function filter(array $parameters) + public function toArray() { - return $parameters ?: array(); + return $this->parameters; } /** @@ -161,9 +176,17 @@ class Parameters implements ParametersInterface /** * {@inheritdoc} */ - public function toArray() + public function __toString() { - return $this->parameters; + if ($this->scheme === 'unix') { + return "$this->scheme:$this->path"; + } + + if (filter_var($this->host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { + return "$this->scheme://[$this->host]:$this->port"; + } + + return "$this->scheme://$this->host:$this->port"; } /** @@ -171,6 +194,6 @@ class Parameters implements ParametersInterface */ public function __sleep() { - return array('parameters'); + return ['parameters']; } } diff --git a/plugins/cache-redis/Predis/Connection/ParametersInterface.php b/plugins/cache-redis/Predis/Connection/ParametersInterface.php index fd8a908e6..7893ea117 100644 --- a/plugins/cache-redis/Predis/Connection/ParametersInterface.php +++ b/plugins/cache-redis/Predis/Connection/ParametersInterface.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -18,20 +19,22 @@ namespace Predis\Connection; * each connection backend class (please refer to their specific documentation), * but the most common parameters used through the library are: * - * @property-read string scheme Connection scheme, such as 'tcp' or 'unix'. - * @property-read string host IP address or hostname of Redis. - * @property-read int port TCP port on which Redis is listening to. - * @property-read string path Path of a UNIX domain socket file. - * @property-read string alias Alias for the connection. - * @property-read float timeout Timeout for the connect() operation. - * @property-read float read_write_timeout Timeout for read() and write() operations. - * @property-read bool async_connect Performs the connect() operation asynchronously. - * @property-read bool tcp_nodelay Toggles the Nagle's algorithm for coalescing. - * @property-read bool persistent Leaves the connection open after a GC collection. - * @property-read string password Password to access Redis (see the AUTH command). - * @property-read string database Database index (see the SELECT command). - * - * @author Daniele Alessandri + * @property string $scheme Connection scheme, such as 'tcp' or 'unix'. + * @property string $host IP address or hostname of Redis. + * @property int $port TCP port on which Redis is listening to. + * @property string $path Path of a UNIX domain socket file. + * @property string $alias Alias for the connection. + * @property float $timeout Timeout for the connect() operation. + * @property float $read_write_timeout Timeout for read() and write() operations. + * @property bool $persistent Leaves the connection open after a GC collection. + * @property string $password Password to access Redis (see the AUTH command). + * @property string $database Database index (see the SELECT command). + * @property bool $async_connect Performs the connect() operation asynchronously. + * @property bool $tcp_nodelay Toggles the Nagle's algorithm for coalescing. + * @property bool $client_info Whether to set LIB-NAME and LIB-VER when connecting. + * @property bool $cache (Relay only) Whether to use in-memory caching. + * @property string $serializer (Relay only) Serializer used for data serialization. + * @property string $compression (Relay only) Algorithm used for data compression. */ interface ParametersInterface { @@ -53,6 +56,13 @@ interface ParametersInterface */ public function __get($parameter); + /** + * Returns basic connection parameters as a valid URI string. + * + * @return string + */ + public function __toString(); + /** * Returns an array representation of the connection parameters. * diff --git a/plugins/cache-redis/Predis/Connection/PhpiredisSocketConnection.php b/plugins/cache-redis/Predis/Connection/PhpiredisSocketConnection.php index 6948f035f..6ff1f77be 100644 --- a/plugins/cache-redis/Predis/Connection/PhpiredisSocketConnection.php +++ b/plugins/cache-redis/Predis/Connection/PhpiredisSocketConnection.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,9 +12,12 @@ namespace Predis\Connection; +use Closure; +use InvalidArgumentException; use Predis\Command\CommandInterface; use Predis\NotSupportedException; use Predis\Response\Error as ErrorResponse; +use Predis\Response\ErrorInterface as ErrorResponseInterface; use Predis\Response\Status as StatusResponse; /** @@ -36,12 +40,11 @@ use Predis\Response\Status as StatusResponse; * - host: hostname or IP address of the server. * - port: TCP port of the server. * - path: path of a UNIX domain socket when scheme is 'unix'. - * - timeout: timeout to perform the connection. + * - timeout: timeout to perform the connection (default is 5 seconds). * - read_write_timeout: timeout of read / write operations. * - * @link http://github.com/nrk/phpiredis - * - * @author Daniele Alessandri + * @see http://github.com/nrk/phpiredis + * @deprecated 2.1.2 */ class PhpiredisSocketConnection extends AbstractConnection { @@ -65,9 +68,9 @@ class PhpiredisSocketConnection extends AbstractConnection */ public function __destruct() { - phpiredis_reader_destroy($this->reader); - parent::__destruct(); + + phpiredis_reader_destroy($this->reader); } /** @@ -93,7 +96,15 @@ class PhpiredisSocketConnection extends AbstractConnection */ protected function assertParameters(ParametersInterface $parameters) { - parent::assertParameters($parameters); + switch ($parameters->scheme) { + case 'tcp': + case 'redis': + case 'unix': + break; + + default: + throw new InvalidArgumentException("Invalid scheme: '$parameters->scheme'."); + } if (isset($parameters->persistent)) { throw new NotSupportedException( @@ -132,25 +143,37 @@ class PhpiredisSocketConnection extends AbstractConnection /** * Returns the handler used by the protocol reader for inline responses. * - * @return \Closure + * @return Closure */ - private function getStatusHandler() + protected function getStatusHandler() { - return function ($payload) { - return StatusResponse::get($payload); - }; + static $statusHandler; + + if (!$statusHandler) { + $statusHandler = function ($payload) { + return StatusResponse::get($payload); + }; + } + + return $statusHandler; } /** * Returns the handler used by the protocol reader for error responses. * - * @return \Closure + * @return Closure */ protected function getErrorHandler() { - return function ($payload) { - return new ErrorResponse($payload); - }; + static $errorHandler; + + if (!$errorHandler) { + $errorHandler = function ($errorMessage) { + return new ErrorResponse($errorMessage); + }; + } + + return $errorHandler; } /** @@ -206,9 +229,7 @@ class PhpiredisSocketConnection extends AbstractConnection $protocol = SOL_TCP; } - $socket = @socket_create($domain, SOCK_STREAM, $protocol); - - if (!is_resource($socket)) { + if (false === $socket = @socket_create($domain, SOCK_STREAM, $protocol)) { $this->emitSocketError(); } @@ -241,10 +262,10 @@ class PhpiredisSocketConnection extends AbstractConnection $timeoutSec = floor($rwtimeout); $timeoutUsec = ($rwtimeout - $timeoutSec) * 1000000; - $timeout = array( + $timeout = [ 'sec' => $timeoutSec, 'usec' => $timeoutUsec, - ); + ]; if (!socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, $timeout)) { $this->emitSocketError(); @@ -263,7 +284,7 @@ class PhpiredisSocketConnection extends AbstractConnection * @param string $address IP address (DNS-resolved from hostname) * @param ParametersInterface $parameters Parameters used to initialize the connection. * - * @return string + * @return void */ private function connectWithTimeout($socket, $address, ParametersInterface $parameters) { @@ -280,9 +301,9 @@ class PhpiredisSocketConnection extends AbstractConnection socket_set_block($socket); $null = null; - $selectable = array($socket); + $selectable = [$socket]; - $timeout = (float) $parameters->timeout; + $timeout = (isset($parameters->timeout) ? (float) $parameters->timeout : 5.0); $timeoutSecs = floor($timeout); $timeoutUSecs = ($timeout - $timeoutSecs) * 1000000; @@ -308,7 +329,11 @@ class PhpiredisSocketConnection extends AbstractConnection { if (parent::connect() && $this->initCommands) { foreach ($this->initCommands as $command) { - $this->executeCommand($command); + $response = $this->executeCommand($command); + + if ($response instanceof ErrorResponseInterface) { + $this->onConnectionError("`{$command->getId()}` failed: {$response->getMessage()}", 0); + } } } } @@ -319,7 +344,9 @@ class PhpiredisSocketConnection extends AbstractConnection public function disconnect() { if ($this->isConnected()) { + phpiredis_reader_reset($this->reader); socket_close($this->getResource()); + parent::disconnect(); } } diff --git a/plugins/cache-redis/Predis/Connection/PhpiredisStreamConnection.php b/plugins/cache-redis/Predis/Connection/PhpiredisStreamConnection.php index beb235758..e3dbfd8ad 100644 --- a/plugins/cache-redis/Predis/Connection/PhpiredisStreamConnection.php +++ b/plugins/cache-redis/Predis/Connection/PhpiredisStreamConnection.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,6 +12,8 @@ namespace Predis\Connection; +use Closure; +use InvalidArgumentException; use Predis\Command\CommandInterface; use Predis\NotSupportedException; use Predis\Response\Error as ErrorResponse; @@ -42,9 +45,8 @@ use Predis\Response\Status as StatusResponse; * - tcp_nodelay: enables or disables Nagle's algorithm for coalescing. * - persistent: the connection is left intact after a GC collection. * - * @link https://github.com/nrk/phpiredis - * - * @author Daniele Alessandri + * @see https://github.com/nrk/phpiredis + * @deprecated 2.1.2 */ class PhpiredisStreamConnection extends StreamConnection { @@ -67,9 +69,19 @@ class PhpiredisStreamConnection extends StreamConnection */ public function __destruct() { - phpiredis_reader_destroy($this->reader); - parent::__destruct(); + + phpiredis_reader_destroy($this->reader); + } + + /** + * {@inheritdoc} + */ + public function disconnect() + { + phpiredis_reader_reset($this->reader); + + parent::disconnect(); } /** @@ -87,24 +99,34 @@ class PhpiredisStreamConnection extends StreamConnection /** * {@inheritdoc} */ - protected function tcpStreamInitializer(ParametersInterface $parameters) + protected function assertParameters(ParametersInterface $parameters) + { + switch ($parameters->scheme) { + case 'tcp': + case 'redis': + case 'unix': + break; + + case 'tls': + case 'rediss': + throw new InvalidArgumentException('SSL encryption is not supported by this connection backend.'); + default: + throw new InvalidArgumentException("Invalid scheme: '$parameters->scheme'."); + } + + return $parameters; + } + + /** + * {@inheritdoc} + */ + protected function createStreamSocket(ParametersInterface $parameters, $address, $flags) { - $uri = "tcp://[{$parameters->host}]:{$parameters->port}"; - $flags = STREAM_CLIENT_CONNECT; $socket = null; + $timeout = (isset($parameters->timeout) ? (float) $parameters->timeout : 5.0); + $context = stream_context_create(['socket' => ['tcp_nodelay' => (bool) $parameters->tcp_nodelay]]); - if (isset($parameters->async_connect) && (bool) $parameters->async_connect) { - $flags |= STREAM_CLIENT_ASYNC_CONNECT; - } - - if (isset($parameters->persistent) && (bool) $parameters->persistent) { - $flags |= STREAM_CLIENT_PERSISTENT; - $uri .= strpos($path = $parameters->path, '/') === 0 ? $path : "/$path"; - } - - $resource = @stream_socket_client($uri, $errno, $errstr, (float) $parameters->timeout, $flags); - - if (!$resource) { + if (!$resource = @stream_socket_client($address, $errno, $errstr, $timeout, $flags, $context)) { $this->onConnectionError(trim($errstr), $errno); } @@ -112,10 +134,10 @@ class PhpiredisStreamConnection extends StreamConnection $rwtimeout = (float) $parameters->read_write_timeout; $rwtimeout = $rwtimeout > 0 ? $rwtimeout : -1; - $timeout = array( + $timeout = [ 'sec' => $timeoutSeconds = floor($rwtimeout), 'usec' => ($rwtimeout - $timeoutSeconds) * 1000000, - ); + ]; $socket = $socket ?: socket_import_stream($resource); @socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, $timeout); @@ -158,25 +180,37 @@ class PhpiredisStreamConnection extends StreamConnection /** * Returns the handler used by the protocol reader for inline responses. * - * @return \Closure + * @return Closure */ protected function getStatusHandler() { - return function ($payload) { - return StatusResponse::get($payload); - }; + static $statusHandler; + + if (!$statusHandler) { + $statusHandler = function ($payload) { + return StatusResponse::get($payload); + }; + } + + return $statusHandler; } /** * Returns the handler used by the protocol reader for error responses. * - * @return \Closure + * @return Closure */ protected function getErrorHandler() { - return function ($errorMessage) { - return new ErrorResponse($errorMessage); - }; + static $errorHandler; + + if (!$errorHandler) { + $errorHandler = function ($errorMessage) { + return new ErrorResponse($errorMessage); + }; + } + + return $errorHandler; } /** diff --git a/plugins/cache-redis/Predis/Connection/StreamConnection.php b/plugins/cache-redis/Predis/Connection/StreamConnection.php index ed6540b87..2fe307067 100644 --- a/plugins/cache-redis/Predis/Connection/StreamConnection.php +++ b/plugins/cache-redis/Predis/Connection/StreamConnection.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,25 +12,26 @@ namespace Predis\Connection; +use InvalidArgumentException; use Predis\Command\CommandInterface; use Predis\Response\Error as ErrorResponse; +use Predis\Response\ErrorInterface as ErrorResponseInterface; use Predis\Response\Status as StatusResponse; /** * Standard connection to Redis servers implemented on top of PHP's streams. * The connection parameters supported by this class are:. * - * - scheme: it can be either 'redis', 'tcp' or 'unix'. + * - scheme: it can be either 'redis', 'tcp', 'rediss', 'tls' or 'unix'. * - host: hostname or IP address of the server. * - port: TCP port of the server. * - path: path of a UNIX domain socket when scheme is 'unix'. - * - timeout: timeout to perform the connection. + * - timeout: timeout to perform the connection (default is 5 seconds). * - read_write_timeout: timeout of read / write operations. * - async_connect: performs the connection asynchronously. * - tcp_nodelay: enables or disables Nagle's algorithm for coalescing. * - persistent: the connection is left intact after a GC collection. - * - * @author Daniele Alessandri + * - ssl: context options array (see http://php.net/manual/en/context.ssl.php) */ class StreamConnection extends AbstractConnection { @@ -47,6 +49,26 @@ class StreamConnection extends AbstractConnection $this->disconnect(); } + /** + * {@inheritdoc} + */ + protected function assertParameters(ParametersInterface $parameters) + { + switch ($parameters->scheme) { + case 'tcp': + case 'redis': + case 'unix': + case 'tls': + case 'rediss': + break; + + default: + throw new InvalidArgumentException("Invalid scheme: '$parameters->scheme'."); + } + + return $parameters; + } + /** * {@inheritdoc} */ @@ -60,11 +82,44 @@ class StreamConnection extends AbstractConnection case 'unix': return $this->unixStreamInitializer($this->parameters); + case 'tls': + case 'rediss': + return $this->tlsStreamInitializer($this->parameters); + default: - throw new \InvalidArgumentException("Invalid scheme: '{$this->parameters->scheme}'."); + throw new InvalidArgumentException("Invalid scheme: '{$this->parameters->scheme}'."); } } + /** + * Creates a connected stream socket resource. + * + * @param ParametersInterface $parameters Connection parameters. + * @param string $address Address for stream_socket_client(). + * @param int $flags Flags for stream_socket_client(). + * + * @return resource + */ + protected function createStreamSocket(ParametersInterface $parameters, $address, $flags) + { + $timeout = (isset($parameters->timeout) ? (float) $parameters->timeout : 5.0); + $context = stream_context_create(['socket' => ['tcp_nodelay' => (bool) $parameters->tcp_nodelay]]); + + if (!$resource = @stream_socket_client($address, $errno, $errstr, $timeout, $flags, $context)) { + $this->onConnectionError(trim($errstr), $errno); + } + + if (isset($parameters->read_write_timeout)) { + $rwtimeout = (float) $parameters->read_write_timeout; + $rwtimeout = $rwtimeout > 0 ? $rwtimeout : -1; + $timeoutSeconds = floor($rwtimeout); + $timeoutUSeconds = ($rwtimeout - $timeoutSeconds) * 1000000; + stream_set_timeout($resource, $timeoutSeconds, $timeoutUSeconds); + } + + return $resource; + } + /** * Initializes a TCP stream resource. * @@ -75,42 +130,28 @@ class StreamConnection extends AbstractConnection protected function tcpStreamInitializer(ParametersInterface $parameters) { if (!filter_var($parameters->host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { - $uri = "tcp://$parameters->host:$parameters->port"; + $address = "tcp://$parameters->host:$parameters->port"; } else { - $uri = "tcp://[$parameters->host]:$parameters->port"; + $address = "tcp://[$parameters->host]:$parameters->port"; } $flags = STREAM_CLIENT_CONNECT; - if (isset($parameters->async_connect) && (bool) $parameters->async_connect) { + if (isset($parameters->async_connect) && $parameters->async_connect) { $flags |= STREAM_CLIENT_ASYNC_CONNECT; } - if (isset($parameters->persistent) && (bool) $parameters->persistent) { - $flags |= STREAM_CLIENT_PERSISTENT; - $uri .= strpos($path = $parameters->path, '/') === 0 ? $path : "/$path"; + if (isset($parameters->persistent)) { + if (false !== $persistent = filter_var($parameters->persistent, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)) { + $flags |= STREAM_CLIENT_PERSISTENT; + + if ($persistent === null) { + $address = "{$address}/{$parameters->persistent}"; + } + } } - $resource = @stream_socket_client($uri, $errno, $errstr, (float) $parameters->timeout, $flags); - - if (!$resource) { - $this->onConnectionError(trim($errstr), $errno); - } - - if (isset($parameters->read_write_timeout)) { - $rwtimeout = (float) $parameters->read_write_timeout; - $rwtimeout = $rwtimeout > 0 ? $rwtimeout : -1; - $timeoutSeconds = floor($rwtimeout); - $timeoutUSeconds = ($rwtimeout - $timeoutSeconds) * 1000000; - stream_set_timeout($resource, $timeoutSeconds, $timeoutUSeconds); - } - - if (isset($parameters->tcp_nodelay) && function_exists('socket_import_stream')) { - $socket = socket_import_stream($resource); - socket_set_option($socket, SOL_TCP, TCP_NODELAY, (int) $parameters->tcp_nodelay); - } - - return $resource; + return $this->createStreamSocket($parameters, $address, $flags); } /** @@ -126,25 +167,56 @@ class StreamConnection extends AbstractConnection throw new InvalidArgumentException('Missing UNIX domain socket path.'); } - $uri = "unix://{$parameters->path}"; $flags = STREAM_CLIENT_CONNECT; - if ((bool) $parameters->persistent) { - $flags |= STREAM_CLIENT_PERSISTENT; + if (isset($parameters->persistent)) { + if (false !== $persistent = filter_var($parameters->persistent, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE)) { + $flags |= STREAM_CLIENT_PERSISTENT; + + if ($persistent === null) { + throw new InvalidArgumentException( + 'Persistent connection IDs are not supported when using UNIX domain sockets.' + ); + } + } } - $resource = @stream_socket_client($uri, $errno, $errstr, (float) $parameters->timeout, $flags); + return $this->createStreamSocket($parameters, "unix://{$parameters->path}", $flags); + } - if (!$resource) { - $this->onConnectionError(trim($errstr), $errno); + /** + * Initializes a SSL-encrypted TCP stream resource. + * + * @param ParametersInterface $parameters Initialization parameters for the connection. + * + * @return resource + */ + protected function tlsStreamInitializer(ParametersInterface $parameters) + { + $resource = $this->tcpStreamInitializer($parameters); + $metadata = stream_get_meta_data($resource); + + // Detect if crypto mode is already enabled for this stream (PHP >= 7.0.0). + if (isset($metadata['crypto'])) { + return $resource; } - if (isset($parameters->read_write_timeout)) { - $rwtimeout = (float) $parameters->read_write_timeout; - $rwtimeout = $rwtimeout > 0 ? $rwtimeout : -1; - $timeoutSeconds = floor($rwtimeout); - $timeoutUSeconds = ($rwtimeout - $timeoutSeconds) * 1000000; - stream_set_timeout($resource, $timeoutSeconds, $timeoutUSeconds); + if (isset($parameters->ssl) && is_array($parameters->ssl)) { + $options = $parameters->ssl; + } else { + $options = []; + } + + if (!isset($options['crypto_type'])) { + $options['crypto_type'] = STREAM_CRYPTO_METHOD_TLS_CLIENT; + } + + if (!stream_context_set_option($resource, ['ssl' => $options])) { + $this->onConnectionError('Error while setting SSL context options'); + } + + if (!stream_socket_enable_crypto($resource, true, $options['crypto_type'])) { + $this->onConnectionError('Error while switching to encrypted communication'); } return $resource; @@ -157,7 +229,13 @@ class StreamConnection extends AbstractConnection { if (parent::connect() && $this->initCommands) { foreach ($this->initCommands as $command) { - $this->executeCommand($command); + $response = $this->executeCommand($command); + + if ($response instanceof ErrorResponseInterface && $command->getId() === 'CLIENT') { + // Do nothing on CLIENT SETINFO command failure + } elseif ($response instanceof ErrorResponseInterface) { + $this->onConnectionError("`{$command->getId()}` failed: {$response->getMessage()}", 0); + } } } } @@ -168,7 +246,10 @@ class StreamConnection extends AbstractConnection public function disconnect() { if ($this->isConnected()) { - fclose($this->getResource()); + $resource = $this->getResource(); + if (is_resource($resource)) { + fclose($resource); + } parent::disconnect(); } } @@ -184,7 +265,7 @@ class StreamConnection extends AbstractConnection $socket = $this->getResource(); while (($length = strlen($buffer)) > 0) { - $written = @fwrite($socket, $buffer); + $written = is_resource($socket) ? @fwrite($socket, $buffer) : false; if ($length === $written) { return; @@ -228,7 +309,7 @@ class StreamConnection extends AbstractConnection $bytesLeft = ($size += 2); do { - $chunk = fread($socket, min($bytesLeft, 4096)); + $chunk = is_resource($socket) ? fread($socket, min($bytesLeft, 4096)) : false; if ($chunk === false || $chunk === '') { $this->onConnectionError('Error while reading bytes from the server.'); @@ -247,7 +328,7 @@ class StreamConnection extends AbstractConnection return; } - $multibulk = array(); + $multibulk = []; for ($i = 0; $i < $count; ++$i) { $multibulk[$i] = $this->read(); @@ -256,7 +337,9 @@ class StreamConnection extends AbstractConnection return $multibulk; case ':': - return (int) $payload; + $integer = (int) $payload; + + return $integer == $payload ? $integer : $payload; case '-': return new ErrorResponse($payload); @@ -281,9 +364,8 @@ class StreamConnection extends AbstractConnection $buffer = "*{$reqlen}\r\n\${$cmdlen}\r\n{$commandID}\r\n"; - for ($i = 0, $reqlen--; $i < $reqlen; ++$i) { - $argument = $arguments[$i]; - $arglen = strlen($argument); + foreach ($arguments as $argument) { + $arglen = strlen(strval($argument)); $buffer .= "\${$arglen}\r\n{$argument}\r\n"; } diff --git a/plugins/cache-redis/Predis/Connection/WebdisConnection.php b/plugins/cache-redis/Predis/Connection/WebdisConnection.php index 9cff9d023..bd533783b 100644 --- a/plugins/cache-redis/Predis/Connection/WebdisConnection.php +++ b/plugins/cache-redis/Predis/Connection/WebdisConnection.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,6 +12,8 @@ namespace Predis\Connection; +use Closure; +use InvalidArgumentException; use Predis\Command\CommandInterface; use Predis\NotSupportedException; use Predis\Protocol\ProtocolException; @@ -33,15 +36,14 @@ use Predis\Response\Status as StatusResponse; * - scheme: must be 'http'. * - host: hostname or IP address of the server. * - port: TCP port of the server. - * - timeout: timeout to perform the connection. + * - timeout: timeout to perform the connection (default is 5 seconds). * - user: username for authentication. * - pass: password for authentication. * - * @link http://webd.is - * @link http://github.com/nicolasff/webdis - * @link http://github.com/seppo0010/phpiredis - * - * @author Daniele Alessandri + * @see http://webd.is + * @see http://github.com/nicolasff/webdis + * @see http://github.com/seppo0010/phpiredis + * @deprecated 2.1.2 */ class WebdisConnection implements NodeConnectionInterface { @@ -52,14 +54,14 @@ class WebdisConnection implements NodeConnectionInterface /** * @param ParametersInterface $parameters Initialization parameters for the connection. * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ public function __construct(ParametersInterface $parameters) { $this->assertExtensions(); if ($parameters->scheme !== 'http') { - throw new \InvalidArgumentException("Invalid scheme: '{$parameters->scheme}'."); + throw new InvalidArgumentException("Invalid scheme: '{$parameters->scheme}'."); } $this->parameters = $parameters; @@ -117,19 +119,20 @@ class WebdisConnection implements NodeConnectionInterface private function createCurl() { $parameters = $this->getParameters(); + $timeout = (isset($parameters->timeout) ? (float) $parameters->timeout : 5.0) * 1000; - if (filter_var($host = $parameters->host, FILTER_VALIDATE_IP)) { + if (filter_var($host = $parameters->host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { $host = "[$host]"; } - $options = array( + $options = [ CURLOPT_FAILONERROR => true, - CURLOPT_CONNECTTIMEOUT_MS => $parameters->timeout * 1000, + CURLOPT_CONNECTTIMEOUT_MS => $timeout, CURLOPT_URL => "$parameters->scheme://$host:$parameters->port", CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_POST => true, - CURLOPT_WRITEFUNCTION => array($this, 'feedReader'), - ); + CURLOPT_WRITEFUNCTION => [$this, 'feedReader'], + ]; if (isset($parameters->user, $parameters->pass)) { $options[CURLOPT_USERPWD] = "{$parameters->user}:{$parameters->pass}"; @@ -158,25 +161,37 @@ class WebdisConnection implements NodeConnectionInterface /** * Returns the handler used by the protocol reader for inline responses. * - * @return \Closure + * @return Closure */ protected function getStatusHandler() { - return function ($payload) { - return StatusResponse::get($payload); - }; + static $statusHandler; + + if (!$statusHandler) { + $statusHandler = function ($payload) { + return StatusResponse::get($payload); + }; + } + + return $statusHandler; } /** * Returns the handler used by the protocol reader for error responses. * - * @return \Closure + * @return Closure */ protected function getErrorHandler() { - return function ($payload) { - return new ErrorResponse($payload); - }; + static $errorHandler; + + if (!$errorHandler) { + $errorHandler = function ($errorMessage) { + return new ErrorResponse($errorMessage); + }; + } + + return $errorHandler; } /** @@ -223,9 +238,8 @@ class WebdisConnection implements NodeConnectionInterface * * @param CommandInterface $command Command instance. * - * @throws NotSupportedException - * * @return string + * @throws NotSupportedException */ protected function getCommandId(CommandInterface $command) { @@ -239,7 +253,6 @@ class WebdisConnection implements NodeConnectionInterface case 'DISCARD': case 'MONITOR': throw new NotSupportedException("Command '$commandID' is not allowed by Webdis."); - default: return $commandID; } @@ -279,10 +292,10 @@ class WebdisConnection implements NodeConnectionInterface curl_setopt($resource, CURLOPT_POSTFIELDS, $serializedCommand); if (curl_exec($resource) === false) { - $error = curl_error($resource); + $error = trim(curl_error($resource)); $errno = curl_errno($resource); - throw new ConnectionException($this, trim($error), $errno); + throw new ConnectionException($this, "$error{$this->getParameters()}]", $errno); } if (phpiredis_reader_get_state($this->reader) !== PHPIREDIS_READER_STATE_COMPLETE) { @@ -337,7 +350,7 @@ class WebdisConnection implements NodeConnectionInterface */ public function __sleep() { - return array('parameters'); + return ['parameters']; } /** diff --git a/plugins/cache-redis/Predis/Monitor/Consumer.php b/plugins/cache-redis/Predis/Monitor/Consumer.php index d10bad1a0..9076bf12f 100644 --- a/plugins/cache-redis/Predis/Monitor/Consumer.php +++ b/plugins/cache-redis/Predis/Monitor/Consumer.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,16 +12,16 @@ namespace Predis\Monitor; +use Iterator; use Predis\ClientInterface; -use Predis\Connection\AggregateConnectionInterface; +use Predis\Connection\Cluster\ClusterInterface; use Predis\NotSupportedException; +use ReturnTypeWillChange; /** * Redis MONITOR consumer. - * - * @author Daniele Alessandri */ -class Consumer implements \Iterator +class Consumer implements Iterator { private $client; private $valid; @@ -56,14 +57,14 @@ class Consumer implements \Iterator */ private function assertClient(ClientInterface $client) { - if ($client->getConnection() instanceof AggregateConnectionInterface) { + if ($client->getConnection() instanceof ClusterInterface) { throw new NotSupportedException( - 'Cannot initialize a monitor consumer over aggregate connections.' + 'Cannot initialize a monitor consumer over cluster connections.' ); } - if ($client->getProfile()->supportsCommand('MONITOR') === false) { - throw new NotSupportedException("The current profile does not support 'MONITOR'."); + if (!$client->getCommandFactory()->supports('MONITOR')) { + throw new NotSupportedException("'MONITOR' is not supported by the current command factory."); } } @@ -89,8 +90,9 @@ class Consumer implements \Iterator } /** - * {@inheritdoc} + * @return void */ + #[ReturnTypeWillChange] public function rewind() { // NOOP @@ -99,24 +101,27 @@ class Consumer implements \Iterator /** * Returns the last message payload retrieved from the server. * - * @return Object + * @return object */ + #[ReturnTypeWillChange] public function current() { return $this->getValue(); } /** - * {@inheritdoc} + * @return int|null */ + #[ReturnTypeWillChange] public function key() { return $this->position; } /** - * {@inheritdoc} + * @return void */ + #[ReturnTypeWillChange] public function next() { ++$this->position; @@ -127,6 +132,7 @@ class Consumer implements \Iterator * * @return bool */ + #[ReturnTypeWillChange] public function valid() { return $this->valid; @@ -136,7 +142,7 @@ class Consumer implements \Iterator * Waits for a new message from the server generated by MONITOR and returns * it when available. * - * @return Object + * @return object */ private function getValue() { @@ -160,14 +166,14 @@ class Consumer implements \Iterator }; $event = preg_replace_callback('/ \(db (\d+)\) | \[(\d+) (.*?)\] /', $callback, $event, 1); - @list($timestamp, $command, $arguments) = explode(' ', $event, 3); + @[$timestamp, $command, $arguments] = explode(' ', $event, 3); - return (object) array( + return (object) [ 'timestamp' => (float) $timestamp, 'database' => $database, 'client' => $client, 'command' => substr($command, 1, -1), 'arguments' => $arguments, - ); + ]; } } diff --git a/plugins/cache-redis/Predis/NotSupportedException.php b/plugins/cache-redis/Predis/NotSupportedException.php index be82aba72..037696b68 100644 --- a/plugins/cache-redis/Predis/NotSupportedException.php +++ b/plugins/cache-redis/Predis/NotSupportedException.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,8 +15,6 @@ namespace Predis; /** * Exception class thrown when trying to use features not supported by certain * classes or abstractions of Predis. - * - * @author Daniele Alessandri */ class NotSupportedException extends PredisException { diff --git a/plugins/cache-redis/Predis/Pipeline/Atomic.php b/plugins/cache-redis/Predis/Pipeline/Atomic.php index 1c9c92aa2..09e19ead6 100644 --- a/plugins/cache-redis/Predis/Pipeline/Atomic.php +++ b/plugins/cache-redis/Predis/Pipeline/Atomic.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -18,11 +19,10 @@ use Predis\Connection\NodeConnectionInterface; use Predis\Response\ErrorInterface as ErrorResponseInterface; use Predis\Response\ResponseInterface; use Predis\Response\ServerException; +use SplQueue; /** * Command pipeline wrapped into a MULTI / EXEC transaction. - * - * @author Daniele Alessandri */ class Atomic extends Pipeline { @@ -31,9 +31,9 @@ class Atomic extends Pipeline */ public function __construct(ClientInterface $client) { - if (!$client->getProfile()->supportsCommands(array('multi', 'exec', 'discard'))) { + if (!$client->getCommandFactory()->supports('multi', 'exec', 'discard')) { throw new ClientException( - "The current profile does not support 'MULTI', 'EXEC' and 'DISCARD'." + "'MULTI', 'EXEC' and 'DISCARD' are not supported by the current command factory." ); } @@ -59,10 +59,10 @@ class Atomic extends Pipeline /** * {@inheritdoc} */ - protected function executePipeline(ConnectionInterface $connection, \SplQueue $commands) + protected function executePipeline(ConnectionInterface $connection, SplQueue $commands) { - $profile = $this->getClient()->getProfile(); - $connection->executeCommand($profile->createCommand('multi')); + $commandFactory = $this->getClient()->getCommandFactory(); + $connection->executeCommand($commandFactory->create('multi')); foreach ($commands as $command) { $connection->writeRequest($command); @@ -72,15 +72,14 @@ class Atomic extends Pipeline $response = $connection->readResponse($command); if ($response instanceof ErrorResponseInterface) { - $connection->executeCommand($profile->createCommand('discard')); + $connection->executeCommand($commandFactory->create('discard')); throw new ServerException($response->getMessage()); } } - $executed = $connection->executeCommand($profile->createCommand('exec')); + $executed = $connection->executeCommand($commandFactory->create('exec')); if (!isset($executed)) { - // TODO: should be throwing a more appropriate exception. throw new ClientException( 'The underlying transaction has been aborted by the server.' ); @@ -95,7 +94,7 @@ class Atomic extends Pipeline ); } - $responses = array(); + $responses = []; $sizeOfPipe = count($commands); $exceptions = $this->throwServerExceptions(); diff --git a/plugins/cache-redis/Predis/Pipeline/ConnectionErrorProof.php b/plugins/cache-redis/Predis/Pipeline/ConnectionErrorProof.php index d3bc732e4..8f995cf07 100644 --- a/plugins/cache-redis/Predis/Pipeline/ConnectionErrorProof.php +++ b/plugins/cache-redis/Predis/Pipeline/ConnectionErrorProof.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -12,18 +13,15 @@ namespace Predis\Pipeline; use Predis\CommunicationException; -use Predis\Connection\Aggregate\ClusterInterface; +use Predis\Connection\Cluster\ClusterInterface; use Predis\Connection\ConnectionInterface; use Predis\Connection\NodeConnectionInterface; use Predis\NotSupportedException; +use SplQueue; /** * Command pipeline that does not throw exceptions on connection errors, but * returns the exception instances as the rest of the response elements. - * - * @todo Awful naming! - * - * @author Daniele Alessandri */ class ConnectionErrorProof extends Pipeline { @@ -38,7 +36,7 @@ class ConnectionErrorProof extends Pipeline /** * {@inheritdoc} */ - protected function executePipeline(ConnectionInterface $connection, \SplQueue $commands) + protected function executePipeline(ConnectionInterface $connection, SplQueue $commands) { if ($connection instanceof NodeConnectionInterface) { return $this->executeSingleNode($connection, $commands); @@ -54,9 +52,9 @@ class ConnectionErrorProof extends Pipeline /** * {@inheritdoc} */ - protected function executeSingleNode(NodeConnectionInterface $connection, \SplQueue $commands) + protected function executeSingleNode(NodeConnectionInterface $connection, SplQueue $commands) { - $responses = array(); + $responses = []; $sizeOfPipe = count($commands); foreach ($commands as $command) { @@ -86,14 +84,14 @@ class ConnectionErrorProof extends Pipeline /** * {@inheritdoc} */ - protected function executeCluster(ClusterInterface $connection, \SplQueue $commands) + protected function executeCluster(ClusterInterface $connection, SplQueue $commands) { - $responses = array(); + $responses = []; $sizeOfPipe = count($commands); - $exceptions = array(); + $exceptions = []; foreach ($commands as $command) { - $cmdConnection = $connection->getConnection($command); + $cmdConnection = $connection->getConnectionByCommand($command); if (isset($exceptions[spl_object_hash($cmdConnection)])) { continue; @@ -109,7 +107,7 @@ class ConnectionErrorProof extends Pipeline for ($i = 0; $i < $sizeOfPipe; ++$i) { $command = $commands->dequeue(); - $cmdConnection = $connection->getConnection($command); + $cmdConnection = $connection->getConnectionByCommand($command); $connectionHash = spl_object_hash($cmdConnection); if (isset($exceptions[$connectionHash])) { diff --git a/plugins/cache-redis/Predis/Pipeline/FireAndForget.php b/plugins/cache-redis/Predis/Pipeline/FireAndForget.php index 95a062b64..75ee88eb2 100644 --- a/plugins/cache-redis/Predis/Pipeline/FireAndForget.php +++ b/plugins/cache-redis/Predis/Pipeline/FireAndForget.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -12,18 +13,17 @@ namespace Predis\Pipeline; use Predis\Connection\ConnectionInterface; +use SplQueue; /** * Command pipeline that writes commands to the servers but discards responses. - * - * @author Daniele Alessandri */ class FireAndForget extends Pipeline { /** * {@inheritdoc} */ - protected function executePipeline(ConnectionInterface $connection, \SplQueue $commands) + protected function executePipeline(ConnectionInterface $connection, SplQueue $commands) { while (!$commands->isEmpty()) { $connection->writeRequest($commands->dequeue()); @@ -31,6 +31,6 @@ class FireAndForget extends Pipeline $connection->disconnect(); - return array(); + return []; } } diff --git a/plugins/cache-redis/Predis/Pipeline/Pipeline.php b/plugins/cache-redis/Predis/Pipeline/Pipeline.php index cf9c59e4f..1f67d0b9f 100644 --- a/plugins/cache-redis/Predis/Pipeline/Pipeline.php +++ b/plugins/cache-redis/Predis/Pipeline/Pipeline.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,30 +12,31 @@ namespace Predis\Pipeline; +use Exception; +use InvalidArgumentException; use Predis\ClientContextInterface; use Predis\ClientException; use Predis\ClientInterface; use Predis\Command\CommandInterface; -use Predis\Connection\Aggregate\ReplicationInterface; use Predis\Connection\ConnectionInterface; +use Predis\Connection\Replication\ReplicationInterface; use Predis\Response\ErrorInterface as ErrorResponseInterface; use Predis\Response\ResponseInterface; use Predis\Response\ServerException; +use SplQueue; /** * Implementation of a command pipeline in which write and read operations of * Redis commands are pipelined to alleviate the effects of network round-trips. * * {@inheritdoc} - * - * @author Daniele Alessandri */ class Pipeline implements ClientContextInterface { - private $client; + protected $client; private $pipeline; - private $responses = array(); + private $responses = []; private $running = false; /** @@ -43,7 +45,7 @@ class Pipeline implements ClientContextInterface public function __construct(ClientInterface $client) { $this->client = $client; - $this->pipeline = new \SplQueue(); + $this->pipeline = new SplQueue(); } /** @@ -112,7 +114,7 @@ class Pipeline implements ClientContextInterface $connection = $this->getClient()->getConnection(); if ($connection instanceof ReplicationInterface) { - $connection->switchTo('master'); + $connection->switchToMaster(); } return $connection; @@ -123,17 +125,17 @@ class Pipeline implements ClientContextInterface * from the current connection. * * @param ConnectionInterface $connection Current connection instance. - * @param \SplQueue $commands Queued commands. + * @param SplQueue $commands Queued commands. * * @return array */ - protected function executePipeline(ConnectionInterface $connection, \SplQueue $commands) + protected function executePipeline(ConnectionInterface $connection, SplQueue $commands) { foreach ($commands as $command) { $connection->writeRequest($command); } - $responses = array(); + $responses = []; $exceptions = $this->throwServerExceptions(); while (!$commands->isEmpty()) { @@ -165,7 +167,7 @@ class Pipeline implements ClientContextInterface $responses = $this->executePipeline($this->getConnection(), $this->pipeline); $this->responses = array_merge($this->responses, $responses); } else { - $this->pipeline = new \SplQueue(); + $this->pipeline = new SplQueue(); } return $this; @@ -192,15 +194,14 @@ class Pipeline implements ClientContextInterface * * @param mixed $callable Optional callback for execution. * - * @throws \Exception - * @throws \InvalidArgumentException - * * @return array + * @throws Exception + * @throws InvalidArgumentException */ public function execute($callable = null) { if ($callable && !is_callable($callable)) { - throw new \InvalidArgumentException('The argument must be a callable object.'); + throw new InvalidArgumentException('The argument must be a callable object.'); } $exception = null; @@ -212,7 +213,7 @@ class Pipeline implements ClientContextInterface } $this->flushPipeline(); - } catch (\Exception $exception) { + } catch (Exception $exception) { // NOOP } diff --git a/plugins/cache-redis/Predis/PredisException.php b/plugins/cache-redis/Predis/PredisException.php index 122bde16d..8e124225d 100644 --- a/plugins/cache-redis/Predis/PredisException.php +++ b/plugins/cache-redis/Predis/PredisException.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,11 +12,11 @@ namespace Predis; +use Exception; + /** * Base exception class for Predis-related errors. - * - * @author Daniele Alessandri */ -abstract class PredisException extends \Exception +abstract class PredisException extends Exception { } diff --git a/plugins/cache-redis/Predis/Profile/Factory.php b/plugins/cache-redis/Predis/Profile/Factory.php deleted file mode 100644 index bcee3c2cf..000000000 --- a/plugins/cache-redis/Predis/Profile/Factory.php +++ /dev/null @@ -1,100 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Profile; - -use Predis\ClientException; - -/** - * Factory class for creating profile instances from strings. - * - * @author Daniele Alessandri - */ -final class Factory -{ - private static $profiles = array( - '2.0' => 'Predis\Profile\RedisVersion200', - '2.2' => 'Predis\Profile\RedisVersion220', - '2.4' => 'Predis\Profile\RedisVersion240', - '2.6' => 'Predis\Profile\RedisVersion260', - '2.8' => 'Predis\Profile\RedisVersion280', - '3.0' => 'Predis\Profile\RedisVersion300', - 'dev' => 'Predis\Profile\RedisUnstable', - 'default' => 'Predis\Profile\RedisVersion300', - ); - - /** - * - */ - private function __construct() - { - // NOOP - } - - /** - * Returns the default server profile. - * - * @return ProfileInterface - */ - public static function getDefault() - { - return self::get('default'); - } - - /** - * Returns the development server profile. - * - * @return ProfileInterface - */ - public static function getDevelopment() - { - return self::get('dev'); - } - - /** - * Registers a new server profile. - * - * @param string $alias Profile version or alias. - * @param string $class FQN of a class implementing Predis\Profile\ProfileInterface. - * - * @throws \InvalidArgumentException - */ - public static function define($alias, $class) - { - $reflection = new \ReflectionClass($class); - - if (!$reflection->isSubclassOf('Predis\Profile\ProfileInterface')) { - throw new \InvalidArgumentException("The class '$class' is not a valid profile class."); - } - - self::$profiles[$alias] = $class; - } - - /** - * Returns the specified server profile. - * - * @param string $version Profile version or alias. - * - * @throws ClientException - * - * @return ProfileInterface - */ - public static function get($version) - { - if (!isset(self::$profiles[$version])) { - throw new ClientException("Unknown server profile: '$version'."); - } - - $profile = self::$profiles[$version]; - - return new $profile(); - } -} diff --git a/plugins/cache-redis/Predis/Profile/ProfileInterface.php b/plugins/cache-redis/Predis/Profile/ProfileInterface.php deleted file mode 100644 index abe71aa63..000000000 --- a/plugins/cache-redis/Predis/Profile/ProfileInterface.php +++ /dev/null @@ -1,59 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Profile; - -use Predis\Command\CommandInterface; - -/** - * A profile defines all the features and commands supported by certain versions - * of Redis. Instances of Predis\Client should use a server profile matching the - * version of Redis being used. - * - * @author Daniele Alessandri - */ -interface ProfileInterface -{ - /** - * Returns the profile version corresponding to the Redis version. - * - * @return string - */ - public function getVersion(); - - /** - * Checks if the profile supports the specified command. - * - * @param string $commandID Command ID. - * - * @return bool - */ - public function supportsCommand($commandID); - - /** - * Checks if the profile supports the specified list of commands. - * - * @param array $commandIDs List of command IDs. - * - * @return string - */ - public function supportsCommands(array $commandIDs); - - /** - * Creates a new command instance. - * - * @param string $commandID Command ID. - * @param array $arguments Arguments for the command. - * - * @return CommandInterface - */ - public function createCommand($commandID, array $arguments = array()); -} diff --git a/plugins/cache-redis/Predis/Profile/RedisProfile.php b/plugins/cache-redis/Predis/Profile/RedisProfile.php deleted file mode 100644 index 3ef316886..000000000 --- a/plugins/cache-redis/Predis/Profile/RedisProfile.php +++ /dev/null @@ -1,146 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Profile; - -use Predis\ClientException; -use Predis\Command\Processor\ProcessorInterface; - -/** - * Base class implementing common functionalities for Redis server profiles. - * - * @author Daniele Alessandri - */ -abstract class RedisProfile implements ProfileInterface -{ - private $commands; - private $processor; - - /** - * - */ - public function __construct() - { - $this->commands = $this->getSupportedCommands(); - } - - /** - * Returns a map of all the commands supported by the profile and their - * actual PHP classes. - * - * @return array - */ - abstract protected function getSupportedCommands(); - - /** - * {@inheritdoc} - */ - public function supportsCommand($commandID) - { - return isset($this->commands[strtoupper($commandID)]); - } - - /** - * {@inheritdoc} - */ - public function supportsCommands(array $commandIDs) - { - foreach ($commandIDs as $commandID) { - if (!$this->supportsCommand($commandID)) { - return false; - } - } - - return true; - } - - /** - * Returns the fully-qualified name of a class representing the specified - * command ID registered in the current server profile. - * - * @param string $commandID Command ID. - * - * @return string|null - */ - public function getCommandClass($commandID) - { - if (isset($this->commands[$commandID = strtoupper($commandID)])) { - return $this->commands[$commandID]; - } - } - - /** - * {@inheritdoc} - */ - public function createCommand($commandID, array $arguments = array()) - { - $commandID = strtoupper($commandID); - - if (!isset($this->commands[$commandID])) { - throw new ClientException("Command '$commandID' is not a registered Redis command."); - } - - $commandClass = $this->commands[$commandID]; - $command = new $commandClass(); - $command->setArguments($arguments); - - if (isset($this->processor)) { - $this->processor->process($command); - } - - return $command; - } - - /** - * Defines a new command in the server profile. - * - * @param string $commandID Command ID. - * @param string $class Fully-qualified name of a Predis\Command\CommandInterface. - * - * @throws \InvalidArgumentException - */ - public function defineCommand($commandID, $class) - { - $reflection = new \ReflectionClass($class); - - if (!$reflection->isSubclassOf('Predis\Command\CommandInterface')) { - throw new \InvalidArgumentException("The class '$class' is not a valid command class."); - } - - $this->commands[strtoupper($commandID)] = $class; - } - - /** - * {@inheritdoc} - */ - public function setProcessor(ProcessorInterface $processor = null) - { - $this->processor = $processor; - } - - /** - * {@inheritdoc} - */ - public function getProcessor() - { - return $this->processor; - } - - /** - * Returns the version of server profile as its string representation. - * - * @return string - */ - public function __toString() - { - return $this->getVersion(); - } -} diff --git a/plugins/cache-redis/Predis/Profile/RedisUnstable.php b/plugins/cache-redis/Predis/Profile/RedisUnstable.php deleted file mode 100644 index cf6174feb..000000000 --- a/plugins/cache-redis/Predis/Profile/RedisUnstable.php +++ /dev/null @@ -1,41 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Profile; - -/** - * Server profile for the current unstable version of Redis. - * - * @author Daniele Alessandri - */ -class RedisUnstable extends RedisVersion300 -{ - /** - * {@inheritdoc} - */ - public function getVersion() - { - return '3.2'; - } - - /** - * {@inheritdoc} - */ - public function getSupportedCommands() - { - return array_merge(parent::getSupportedCommands(), array( - /* ---------------- Redis 3.2 ---------------- */ - - /* commands operating on hashes */ - 'HSTRLEN' => 'Predis\Command\HashStringLength', - )); - } -} diff --git a/plugins/cache-redis/Predis/Profile/RedisVersion200.php b/plugins/cache-redis/Predis/Profile/RedisVersion200.php deleted file mode 100644 index 234d53c00..000000000 --- a/plugins/cache-redis/Predis/Profile/RedisVersion200.php +++ /dev/null @@ -1,173 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Profile; - -/** - * Server profile for Redis 2.0. - * - * @author Daniele Alessandri - */ -class RedisVersion200 extends RedisProfile -{ - /** - * {@inheritdoc} - */ - public function getVersion() - { - return '2.0'; - } - - /** - * {@inheritdoc} - */ - public function getSupportedCommands() - { - return array( - /* ---------------- Redis 1.2 ---------------- */ - - /* commands operating on the key space */ - 'EXISTS' => 'Predis\Command\KeyExists', - 'DEL' => 'Predis\Command\KeyDelete', - 'TYPE' => 'Predis\Command\KeyType', - 'KEYS' => 'Predis\Command\KeyKeys', - 'RANDOMKEY' => 'Predis\Command\KeyRandom', - 'RENAME' => 'Predis\Command\KeyRename', - 'RENAMENX' => 'Predis\Command\KeyRenamePreserve', - 'EXPIRE' => 'Predis\Command\KeyExpire', - 'EXPIREAT' => 'Predis\Command\KeyExpireAt', - 'TTL' => 'Predis\Command\KeyTimeToLive', - 'MOVE' => 'Predis\Command\KeyMove', - 'SORT' => 'Predis\Command\KeySort', - - /* commands operating on string values */ - 'SET' => 'Predis\Command\StringSet', - 'SETNX' => 'Predis\Command\StringSetPreserve', - 'MSET' => 'Predis\Command\StringSetMultiple', - 'MSETNX' => 'Predis\Command\StringSetMultiplePreserve', - 'GET' => 'Predis\Command\StringGet', - 'MGET' => 'Predis\Command\StringGetMultiple', - 'GETSET' => 'Predis\Command\StringGetSet', - 'INCR' => 'Predis\Command\StringIncrement', - 'INCRBY' => 'Predis\Command\StringIncrementBy', - 'DECR' => 'Predis\Command\StringDecrement', - 'DECRBY' => 'Predis\Command\StringDecrementBy', - - /* commands operating on lists */ - 'RPUSH' => 'Predis\Command\ListPushTail', - 'LPUSH' => 'Predis\Command\ListPushHead', - 'LLEN' => 'Predis\Command\ListLength', - 'LRANGE' => 'Predis\Command\ListRange', - 'LTRIM' => 'Predis\Command\ListTrim', - 'LINDEX' => 'Predis\Command\ListIndex', - 'LSET' => 'Predis\Command\ListSet', - 'LREM' => 'Predis\Command\ListRemove', - 'LPOP' => 'Predis\Command\ListPopFirst', - 'RPOP' => 'Predis\Command\ListPopLast', - 'RPOPLPUSH' => 'Predis\Command\ListPopLastPushHead', - - /* commands operating on sets */ - 'SADD' => 'Predis\Command\SetAdd', - 'SREM' => 'Predis\Command\SetRemove', - 'SPOP' => 'Predis\Command\SetPop', - 'SMOVE' => 'Predis\Command\SetMove', - 'SCARD' => 'Predis\Command\SetCardinality', - 'SISMEMBER' => 'Predis\Command\SetIsMember', - 'SINTER' => 'Predis\Command\SetIntersection', - 'SINTERSTORE' => 'Predis\Command\SetIntersectionStore', - 'SUNION' => 'Predis\Command\SetUnion', - 'SUNIONSTORE' => 'Predis\Command\SetUnionStore', - 'SDIFF' => 'Predis\Command\SetDifference', - 'SDIFFSTORE' => 'Predis\Command\SetDifferenceStore', - 'SMEMBERS' => 'Predis\Command\SetMembers', - 'SRANDMEMBER' => 'Predis\Command\SetRandomMember', - - /* commands operating on sorted sets */ - 'ZADD' => 'Predis\Command\ZSetAdd', - 'ZINCRBY' => 'Predis\Command\ZSetIncrementBy', - 'ZREM' => 'Predis\Command\ZSetRemove', - 'ZRANGE' => 'Predis\Command\ZSetRange', - 'ZREVRANGE' => 'Predis\Command\ZSetReverseRange', - 'ZRANGEBYSCORE' => 'Predis\Command\ZSetRangeByScore', - 'ZCARD' => 'Predis\Command\ZSetCardinality', - 'ZSCORE' => 'Predis\Command\ZSetScore', - 'ZREMRANGEBYSCORE' => 'Predis\Command\ZSetRemoveRangeByScore', - - /* connection related commands */ - 'PING' => 'Predis\Command\ConnectionPing', - 'AUTH' => 'Predis\Command\ConnectionAuth', - 'SELECT' => 'Predis\Command\ConnectionSelect', - 'ECHO' => 'Predis\Command\ConnectionEcho', - 'QUIT' => 'Predis\Command\ConnectionQuit', - - /* remote server control commands */ - 'INFO' => 'Predis\Command\ServerInfo', - 'SLAVEOF' => 'Predis\Command\ServerSlaveOf', - 'MONITOR' => 'Predis\Command\ServerMonitor', - 'DBSIZE' => 'Predis\Command\ServerDatabaseSize', - 'FLUSHDB' => 'Predis\Command\ServerFlushDatabase', - 'FLUSHALL' => 'Predis\Command\ServerFlushAll', - 'SAVE' => 'Predis\Command\ServerSave', - 'BGSAVE' => 'Predis\Command\ServerBackgroundSave', - 'LASTSAVE' => 'Predis\Command\ServerLastSave', - 'SHUTDOWN' => 'Predis\Command\ServerShutdown', - 'BGREWRITEAOF' => 'Predis\Command\ServerBackgroundRewriteAOF', - - /* ---------------- Redis 2.0 ---------------- */ - - /* commands operating on string values */ - 'SETEX' => 'Predis\Command\StringSetExpire', - 'APPEND' => 'Predis\Command\StringAppend', - 'SUBSTR' => 'Predis\Command\StringSubstr', - - /* commands operating on lists */ - 'BLPOP' => 'Predis\Command\ListPopFirstBlocking', - 'BRPOP' => 'Predis\Command\ListPopLastBlocking', - - /* commands operating on sorted sets */ - 'ZUNIONSTORE' => 'Predis\Command\ZSetUnionStore', - 'ZINTERSTORE' => 'Predis\Command\ZSetIntersectionStore', - 'ZCOUNT' => 'Predis\Command\ZSetCount', - 'ZRANK' => 'Predis\Command\ZSetRank', - 'ZREVRANK' => 'Predis\Command\ZSetReverseRank', - 'ZREMRANGEBYRANK' => 'Predis\Command\ZSetRemoveRangeByRank', - - /* commands operating on hashes */ - 'HSET' => 'Predis\Command\HashSet', - 'HSETNX' => 'Predis\Command\HashSetPreserve', - 'HMSET' => 'Predis\Command\HashSetMultiple', - 'HINCRBY' => 'Predis\Command\HashIncrementBy', - 'HGET' => 'Predis\Command\HashGet', - 'HMGET' => 'Predis\Command\HashGetMultiple', - 'HDEL' => 'Predis\Command\HashDelete', - 'HEXISTS' => 'Predis\Command\HashExists', - 'HLEN' => 'Predis\Command\HashLength', - 'HKEYS' => 'Predis\Command\HashKeys', - 'HVALS' => 'Predis\Command\HashValues', - 'HGETALL' => 'Predis\Command\HashGetAll', - - /* transactions */ - 'MULTI' => 'Predis\Command\TransactionMulti', - 'EXEC' => 'Predis\Command\TransactionExec', - 'DISCARD' => 'Predis\Command\TransactionDiscard', - - /* publish - subscribe */ - 'SUBSCRIBE' => 'Predis\Command\PubSubSubscribe', - 'UNSUBSCRIBE' => 'Predis\Command\PubSubUnsubscribe', - 'PSUBSCRIBE' => 'Predis\Command\PubSubSubscribeByPattern', - 'PUNSUBSCRIBE' => 'Predis\Command\PubSubUnsubscribeByPattern', - 'PUBLISH' => 'Predis\Command\PubSubPublish', - - /* remote server control commands */ - 'CONFIG' => 'Predis\Command\ServerConfig', - ); - } -} diff --git a/plugins/cache-redis/Predis/Profile/RedisVersion220.php b/plugins/cache-redis/Predis/Profile/RedisVersion220.php deleted file mode 100644 index 899014e28..000000000 --- a/plugins/cache-redis/Predis/Profile/RedisVersion220.php +++ /dev/null @@ -1,202 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Profile; - -/** - * Server profile for Redis 2.2. - * - * @author Daniele Alessandri - */ -class RedisVersion220 extends RedisProfile -{ - /** - * {@inheritdoc} - */ - public function getVersion() - { - return '2.2'; - } - - /** - * {@inheritdoc} - */ - public function getSupportedCommands() - { - return array( - /* ---------------- Redis 1.2 ---------------- */ - - /* commands operating on the key space */ - 'EXISTS' => 'Predis\Command\KeyExists', - 'DEL' => 'Predis\Command\KeyDelete', - 'TYPE' => 'Predis\Command\KeyType', - 'KEYS' => 'Predis\Command\KeyKeys', - 'RANDOMKEY' => 'Predis\Command\KeyRandom', - 'RENAME' => 'Predis\Command\KeyRename', - 'RENAMENX' => 'Predis\Command\KeyRenamePreserve', - 'EXPIRE' => 'Predis\Command\KeyExpire', - 'EXPIREAT' => 'Predis\Command\KeyExpireAt', - 'TTL' => 'Predis\Command\KeyTimeToLive', - 'MOVE' => 'Predis\Command\KeyMove', - 'SORT' => 'Predis\Command\KeySort', - - /* commands operating on string values */ - 'SET' => 'Predis\Command\StringSet', - 'SETNX' => 'Predis\Command\StringSetPreserve', - 'MSET' => 'Predis\Command\StringSetMultiple', - 'MSETNX' => 'Predis\Command\StringSetMultiplePreserve', - 'GET' => 'Predis\Command\StringGet', - 'MGET' => 'Predis\Command\StringGetMultiple', - 'GETSET' => 'Predis\Command\StringGetSet', - 'INCR' => 'Predis\Command\StringIncrement', - 'INCRBY' => 'Predis\Command\StringIncrementBy', - 'DECR' => 'Predis\Command\StringDecrement', - 'DECRBY' => 'Predis\Command\StringDecrementBy', - - /* commands operating on lists */ - 'RPUSH' => 'Predis\Command\ListPushTail', - 'LPUSH' => 'Predis\Command\ListPushHead', - 'LLEN' => 'Predis\Command\ListLength', - 'LRANGE' => 'Predis\Command\ListRange', - 'LTRIM' => 'Predis\Command\ListTrim', - 'LINDEX' => 'Predis\Command\ListIndex', - 'LSET' => 'Predis\Command\ListSet', - 'LREM' => 'Predis\Command\ListRemove', - 'LPOP' => 'Predis\Command\ListPopFirst', - 'RPOP' => 'Predis\Command\ListPopLast', - 'RPOPLPUSH' => 'Predis\Command\ListPopLastPushHead', - - /* commands operating on sets */ - 'SADD' => 'Predis\Command\SetAdd', - 'SREM' => 'Predis\Command\SetRemove', - 'SPOP' => 'Predis\Command\SetPop', - 'SMOVE' => 'Predis\Command\SetMove', - 'SCARD' => 'Predis\Command\SetCardinality', - 'SISMEMBER' => 'Predis\Command\SetIsMember', - 'SINTER' => 'Predis\Command\SetIntersection', - 'SINTERSTORE' => 'Predis\Command\SetIntersectionStore', - 'SUNION' => 'Predis\Command\SetUnion', - 'SUNIONSTORE' => 'Predis\Command\SetUnionStore', - 'SDIFF' => 'Predis\Command\SetDifference', - 'SDIFFSTORE' => 'Predis\Command\SetDifferenceStore', - 'SMEMBERS' => 'Predis\Command\SetMembers', - 'SRANDMEMBER' => 'Predis\Command\SetRandomMember', - - /* commands operating on sorted sets */ - 'ZADD' => 'Predis\Command\ZSetAdd', - 'ZINCRBY' => 'Predis\Command\ZSetIncrementBy', - 'ZREM' => 'Predis\Command\ZSetRemove', - 'ZRANGE' => 'Predis\Command\ZSetRange', - 'ZREVRANGE' => 'Predis\Command\ZSetReverseRange', - 'ZRANGEBYSCORE' => 'Predis\Command\ZSetRangeByScore', - 'ZCARD' => 'Predis\Command\ZSetCardinality', - 'ZSCORE' => 'Predis\Command\ZSetScore', - 'ZREMRANGEBYSCORE' => 'Predis\Command\ZSetRemoveRangeByScore', - - /* connection related commands */ - 'PING' => 'Predis\Command\ConnectionPing', - 'AUTH' => 'Predis\Command\ConnectionAuth', - 'SELECT' => 'Predis\Command\ConnectionSelect', - 'ECHO' => 'Predis\Command\ConnectionEcho', - 'QUIT' => 'Predis\Command\ConnectionQuit', - - /* remote server control commands */ - 'INFO' => 'Predis\Command\ServerInfo', - 'SLAVEOF' => 'Predis\Command\ServerSlaveOf', - 'MONITOR' => 'Predis\Command\ServerMonitor', - 'DBSIZE' => 'Predis\Command\ServerDatabaseSize', - 'FLUSHDB' => 'Predis\Command\ServerFlushDatabase', - 'FLUSHALL' => 'Predis\Command\ServerFlushAll', - 'SAVE' => 'Predis\Command\ServerSave', - 'BGSAVE' => 'Predis\Command\ServerBackgroundSave', - 'LASTSAVE' => 'Predis\Command\ServerLastSave', - 'SHUTDOWN' => 'Predis\Command\ServerShutdown', - 'BGREWRITEAOF' => 'Predis\Command\ServerBackgroundRewriteAOF', - - /* ---------------- Redis 2.0 ---------------- */ - - /* commands operating on string values */ - 'SETEX' => 'Predis\Command\StringSetExpire', - 'APPEND' => 'Predis\Command\StringAppend', - 'SUBSTR' => 'Predis\Command\StringSubstr', - - /* commands operating on lists */ - 'BLPOP' => 'Predis\Command\ListPopFirstBlocking', - 'BRPOP' => 'Predis\Command\ListPopLastBlocking', - - /* commands operating on sorted sets */ - 'ZUNIONSTORE' => 'Predis\Command\ZSetUnionStore', - 'ZINTERSTORE' => 'Predis\Command\ZSetIntersectionStore', - 'ZCOUNT' => 'Predis\Command\ZSetCount', - 'ZRANK' => 'Predis\Command\ZSetRank', - 'ZREVRANK' => 'Predis\Command\ZSetReverseRank', - 'ZREMRANGEBYRANK' => 'Predis\Command\ZSetRemoveRangeByRank', - - /* commands operating on hashes */ - 'HSET' => 'Predis\Command\HashSet', - 'HSETNX' => 'Predis\Command\HashSetPreserve', - 'HMSET' => 'Predis\Command\HashSetMultiple', - 'HINCRBY' => 'Predis\Command\HashIncrementBy', - 'HGET' => 'Predis\Command\HashGet', - 'HMGET' => 'Predis\Command\HashGetMultiple', - 'HDEL' => 'Predis\Command\HashDelete', - 'HEXISTS' => 'Predis\Command\HashExists', - 'HLEN' => 'Predis\Command\HashLength', - 'HKEYS' => 'Predis\Command\HashKeys', - 'HVALS' => 'Predis\Command\HashValues', - 'HGETALL' => 'Predis\Command\HashGetAll', - - /* transactions */ - 'MULTI' => 'Predis\Command\TransactionMulti', - 'EXEC' => 'Predis\Command\TransactionExec', - 'DISCARD' => 'Predis\Command\TransactionDiscard', - - /* publish - subscribe */ - 'SUBSCRIBE' => 'Predis\Command\PubSubSubscribe', - 'UNSUBSCRIBE' => 'Predis\Command\PubSubUnsubscribe', - 'PSUBSCRIBE' => 'Predis\Command\PubSubSubscribeByPattern', - 'PUNSUBSCRIBE' => 'Predis\Command\PubSubUnsubscribeByPattern', - 'PUBLISH' => 'Predis\Command\PubSubPublish', - - /* remote server control commands */ - 'CONFIG' => 'Predis\Command\ServerConfig', - - /* ---------------- Redis 2.2 ---------------- */ - - /* commands operating on the key space */ - 'PERSIST' => 'Predis\Command\KeyPersist', - - /* commands operating on string values */ - 'STRLEN' => 'Predis\Command\StringStrlen', - 'SETRANGE' => 'Predis\Command\StringSetRange', - 'GETRANGE' => 'Predis\Command\StringGetRange', - 'SETBIT' => 'Predis\Command\StringSetBit', - 'GETBIT' => 'Predis\Command\StringGetBit', - - /* commands operating on lists */ - 'RPUSHX' => 'Predis\Command\ListPushTailX', - 'LPUSHX' => 'Predis\Command\ListPushHeadX', - 'LINSERT' => 'Predis\Command\ListInsert', - 'BRPOPLPUSH' => 'Predis\Command\ListPopLastPushHeadBlocking', - - /* commands operating on sorted sets */ - 'ZREVRANGEBYSCORE' => 'Predis\Command\ZSetReverseRangeByScore', - - /* transactions */ - 'WATCH' => 'Predis\Command\TransactionWatch', - 'UNWATCH' => 'Predis\Command\TransactionUnwatch', - - /* remote server control commands */ - 'OBJECT' => 'Predis\Command\ServerObject', - 'SLOWLOG' => 'Predis\Command\ServerSlowlog', - ); - } -} diff --git a/plugins/cache-redis/Predis/Profile/RedisVersion240.php b/plugins/cache-redis/Predis/Profile/RedisVersion240.php deleted file mode 100644 index 0856c37c4..000000000 --- a/plugins/cache-redis/Predis/Profile/RedisVersion240.php +++ /dev/null @@ -1,207 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Profile; - -/** - * Server profile for Redis 2.4. - * - * @author Daniele Alessandri - */ -class RedisVersion240 extends RedisProfile -{ - /** - * {@inheritdoc} - */ - public function getVersion() - { - return '2.4'; - } - - /** - * {@inheritdoc} - */ - public function getSupportedCommands() - { - return array( - /* ---------------- Redis 1.2 ---------------- */ - - /* commands operating on the key space */ - 'EXISTS' => 'Predis\Command\KeyExists', - 'DEL' => 'Predis\Command\KeyDelete', - 'TYPE' => 'Predis\Command\KeyType', - 'KEYS' => 'Predis\Command\KeyKeys', - 'RANDOMKEY' => 'Predis\Command\KeyRandom', - 'RENAME' => 'Predis\Command\KeyRename', - 'RENAMENX' => 'Predis\Command\KeyRenamePreserve', - 'EXPIRE' => 'Predis\Command\KeyExpire', - 'EXPIREAT' => 'Predis\Command\KeyExpireAt', - 'TTL' => 'Predis\Command\KeyTimeToLive', - 'MOVE' => 'Predis\Command\KeyMove', - 'SORT' => 'Predis\Command\KeySort', - - /* commands operating on string values */ - 'SET' => 'Predis\Command\StringSet', - 'SETNX' => 'Predis\Command\StringSetPreserve', - 'MSET' => 'Predis\Command\StringSetMultiple', - 'MSETNX' => 'Predis\Command\StringSetMultiplePreserve', - 'GET' => 'Predis\Command\StringGet', - 'MGET' => 'Predis\Command\StringGetMultiple', - 'GETSET' => 'Predis\Command\StringGetSet', - 'INCR' => 'Predis\Command\StringIncrement', - 'INCRBY' => 'Predis\Command\StringIncrementBy', - 'DECR' => 'Predis\Command\StringDecrement', - 'DECRBY' => 'Predis\Command\StringDecrementBy', - - /* commands operating on lists */ - 'RPUSH' => 'Predis\Command\ListPushTail', - 'LPUSH' => 'Predis\Command\ListPushHead', - 'LLEN' => 'Predis\Command\ListLength', - 'LRANGE' => 'Predis\Command\ListRange', - 'LTRIM' => 'Predis\Command\ListTrim', - 'LINDEX' => 'Predis\Command\ListIndex', - 'LSET' => 'Predis\Command\ListSet', - 'LREM' => 'Predis\Command\ListRemove', - 'LPOP' => 'Predis\Command\ListPopFirst', - 'RPOP' => 'Predis\Command\ListPopLast', - 'RPOPLPUSH' => 'Predis\Command\ListPopLastPushHead', - - /* commands operating on sets */ - 'SADD' => 'Predis\Command\SetAdd', - 'SREM' => 'Predis\Command\SetRemove', - 'SPOP' => 'Predis\Command\SetPop', - 'SMOVE' => 'Predis\Command\SetMove', - 'SCARD' => 'Predis\Command\SetCardinality', - 'SISMEMBER' => 'Predis\Command\SetIsMember', - 'SINTER' => 'Predis\Command\SetIntersection', - 'SINTERSTORE' => 'Predis\Command\SetIntersectionStore', - 'SUNION' => 'Predis\Command\SetUnion', - 'SUNIONSTORE' => 'Predis\Command\SetUnionStore', - 'SDIFF' => 'Predis\Command\SetDifference', - 'SDIFFSTORE' => 'Predis\Command\SetDifferenceStore', - 'SMEMBERS' => 'Predis\Command\SetMembers', - 'SRANDMEMBER' => 'Predis\Command\SetRandomMember', - - /* commands operating on sorted sets */ - 'ZADD' => 'Predis\Command\ZSetAdd', - 'ZINCRBY' => 'Predis\Command\ZSetIncrementBy', - 'ZREM' => 'Predis\Command\ZSetRemove', - 'ZRANGE' => 'Predis\Command\ZSetRange', - 'ZREVRANGE' => 'Predis\Command\ZSetReverseRange', - 'ZRANGEBYSCORE' => 'Predis\Command\ZSetRangeByScore', - 'ZCARD' => 'Predis\Command\ZSetCardinality', - 'ZSCORE' => 'Predis\Command\ZSetScore', - 'ZREMRANGEBYSCORE' => 'Predis\Command\ZSetRemoveRangeByScore', - - /* connection related commands */ - 'PING' => 'Predis\Command\ConnectionPing', - 'AUTH' => 'Predis\Command\ConnectionAuth', - 'SELECT' => 'Predis\Command\ConnectionSelect', - 'ECHO' => 'Predis\Command\ConnectionEcho', - 'QUIT' => 'Predis\Command\ConnectionQuit', - - /* remote server control commands */ - 'INFO' => 'Predis\Command\ServerInfo', - 'SLAVEOF' => 'Predis\Command\ServerSlaveOf', - 'MONITOR' => 'Predis\Command\ServerMonitor', - 'DBSIZE' => 'Predis\Command\ServerDatabaseSize', - 'FLUSHDB' => 'Predis\Command\ServerFlushDatabase', - 'FLUSHALL' => 'Predis\Command\ServerFlushAll', - 'SAVE' => 'Predis\Command\ServerSave', - 'BGSAVE' => 'Predis\Command\ServerBackgroundSave', - 'LASTSAVE' => 'Predis\Command\ServerLastSave', - 'SHUTDOWN' => 'Predis\Command\ServerShutdown', - 'BGREWRITEAOF' => 'Predis\Command\ServerBackgroundRewriteAOF', - - /* ---------------- Redis 2.0 ---------------- */ - - /* commands operating on string values */ - 'SETEX' => 'Predis\Command\StringSetExpire', - 'APPEND' => 'Predis\Command\StringAppend', - 'SUBSTR' => 'Predis\Command\StringSubstr', - - /* commands operating on lists */ - 'BLPOP' => 'Predis\Command\ListPopFirstBlocking', - 'BRPOP' => 'Predis\Command\ListPopLastBlocking', - - /* commands operating on sorted sets */ - 'ZUNIONSTORE' => 'Predis\Command\ZSetUnionStore', - 'ZINTERSTORE' => 'Predis\Command\ZSetIntersectionStore', - 'ZCOUNT' => 'Predis\Command\ZSetCount', - 'ZRANK' => 'Predis\Command\ZSetRank', - 'ZREVRANK' => 'Predis\Command\ZSetReverseRank', - 'ZREMRANGEBYRANK' => 'Predis\Command\ZSetRemoveRangeByRank', - - /* commands operating on hashes */ - 'HSET' => 'Predis\Command\HashSet', - 'HSETNX' => 'Predis\Command\HashSetPreserve', - 'HMSET' => 'Predis\Command\HashSetMultiple', - 'HINCRBY' => 'Predis\Command\HashIncrementBy', - 'HGET' => 'Predis\Command\HashGet', - 'HMGET' => 'Predis\Command\HashGetMultiple', - 'HDEL' => 'Predis\Command\HashDelete', - 'HEXISTS' => 'Predis\Command\HashExists', - 'HLEN' => 'Predis\Command\HashLength', - 'HKEYS' => 'Predis\Command\HashKeys', - 'HVALS' => 'Predis\Command\HashValues', - 'HGETALL' => 'Predis\Command\HashGetAll', - - /* transactions */ - 'MULTI' => 'Predis\Command\TransactionMulti', - 'EXEC' => 'Predis\Command\TransactionExec', - 'DISCARD' => 'Predis\Command\TransactionDiscard', - - /* publish - subscribe */ - 'SUBSCRIBE' => 'Predis\Command\PubSubSubscribe', - 'UNSUBSCRIBE' => 'Predis\Command\PubSubUnsubscribe', - 'PSUBSCRIBE' => 'Predis\Command\PubSubSubscribeByPattern', - 'PUNSUBSCRIBE' => 'Predis\Command\PubSubUnsubscribeByPattern', - 'PUBLISH' => 'Predis\Command\PubSubPublish', - - /* remote server control commands */ - 'CONFIG' => 'Predis\Command\ServerConfig', - - /* ---------------- Redis 2.2 ---------------- */ - - /* commands operating on the key space */ - 'PERSIST' => 'Predis\Command\KeyPersist', - - /* commands operating on string values */ - 'STRLEN' => 'Predis\Command\StringStrlen', - 'SETRANGE' => 'Predis\Command\StringSetRange', - 'GETRANGE' => 'Predis\Command\StringGetRange', - 'SETBIT' => 'Predis\Command\StringSetBit', - 'GETBIT' => 'Predis\Command\StringGetBit', - - /* commands operating on lists */ - 'RPUSHX' => 'Predis\Command\ListPushTailX', - 'LPUSHX' => 'Predis\Command\ListPushHeadX', - 'LINSERT' => 'Predis\Command\ListInsert', - 'BRPOPLPUSH' => 'Predis\Command\ListPopLastPushHeadBlocking', - - /* commands operating on sorted sets */ - 'ZREVRANGEBYSCORE' => 'Predis\Command\ZSetReverseRangeByScore', - - /* transactions */ - 'WATCH' => 'Predis\Command\TransactionWatch', - 'UNWATCH' => 'Predis\Command\TransactionUnwatch', - - /* remote server control commands */ - 'OBJECT' => 'Predis\Command\ServerObject', - 'SLOWLOG' => 'Predis\Command\ServerSlowlog', - - /* ---------------- Redis 2.4 ---------------- */ - - /* remote server control commands */ - 'CLIENT' => 'Predis\Command\ServerClient', - ); - } -} diff --git a/plugins/cache-redis/Predis/Profile/RedisVersion260.php b/plugins/cache-redis/Predis/Profile/RedisVersion260.php deleted file mode 100644 index ba5084aa0..000000000 --- a/plugins/cache-redis/Predis/Profile/RedisVersion260.php +++ /dev/null @@ -1,235 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Profile; - -/** - * Server profile for Redis 2.6. - * - * @author Daniele Alessandri - */ -class RedisVersion260 extends RedisProfile -{ - /** - * {@inheritdoc} - */ - public function getVersion() - { - return '2.6'; - } - - /** - * {@inheritdoc} - */ - public function getSupportedCommands() - { - return array( - /* ---------------- Redis 1.2 ---------------- */ - - /* commands operating on the key space */ - 'EXISTS' => 'Predis\Command\KeyExists', - 'DEL' => 'Predis\Command\KeyDelete', - 'TYPE' => 'Predis\Command\KeyType', - 'KEYS' => 'Predis\Command\KeyKeys', - 'RANDOMKEY' => 'Predis\Command\KeyRandom', - 'RENAME' => 'Predis\Command\KeyRename', - 'RENAMENX' => 'Predis\Command\KeyRenamePreserve', - 'EXPIRE' => 'Predis\Command\KeyExpire', - 'EXPIREAT' => 'Predis\Command\KeyExpireAt', - 'TTL' => 'Predis\Command\KeyTimeToLive', - 'MOVE' => 'Predis\Command\KeyMove', - 'SORT' => 'Predis\Command\KeySort', - 'DUMP' => 'Predis\Command\KeyDump', - 'RESTORE' => 'Predis\Command\KeyRestore', - - /* commands operating on string values */ - 'SET' => 'Predis\Command\StringSet', - 'SETNX' => 'Predis\Command\StringSetPreserve', - 'MSET' => 'Predis\Command\StringSetMultiple', - 'MSETNX' => 'Predis\Command\StringSetMultiplePreserve', - 'GET' => 'Predis\Command\StringGet', - 'MGET' => 'Predis\Command\StringGetMultiple', - 'GETSET' => 'Predis\Command\StringGetSet', - 'INCR' => 'Predis\Command\StringIncrement', - 'INCRBY' => 'Predis\Command\StringIncrementBy', - 'DECR' => 'Predis\Command\StringDecrement', - 'DECRBY' => 'Predis\Command\StringDecrementBy', - - /* commands operating on lists */ - 'RPUSH' => 'Predis\Command\ListPushTail', - 'LPUSH' => 'Predis\Command\ListPushHead', - 'LLEN' => 'Predis\Command\ListLength', - 'LRANGE' => 'Predis\Command\ListRange', - 'LTRIM' => 'Predis\Command\ListTrim', - 'LINDEX' => 'Predis\Command\ListIndex', - 'LSET' => 'Predis\Command\ListSet', - 'LREM' => 'Predis\Command\ListRemove', - 'LPOP' => 'Predis\Command\ListPopFirst', - 'RPOP' => 'Predis\Command\ListPopLast', - 'RPOPLPUSH' => 'Predis\Command\ListPopLastPushHead', - - /* commands operating on sets */ - 'SADD' => 'Predis\Command\SetAdd', - 'SREM' => 'Predis\Command\SetRemove', - 'SPOP' => 'Predis\Command\SetPop', - 'SMOVE' => 'Predis\Command\SetMove', - 'SCARD' => 'Predis\Command\SetCardinality', - 'SISMEMBER' => 'Predis\Command\SetIsMember', - 'SINTER' => 'Predis\Command\SetIntersection', - 'SINTERSTORE' => 'Predis\Command\SetIntersectionStore', - 'SUNION' => 'Predis\Command\SetUnion', - 'SUNIONSTORE' => 'Predis\Command\SetUnionStore', - 'SDIFF' => 'Predis\Command\SetDifference', - 'SDIFFSTORE' => 'Predis\Command\SetDifferenceStore', - 'SMEMBERS' => 'Predis\Command\SetMembers', - 'SRANDMEMBER' => 'Predis\Command\SetRandomMember', - - /* commands operating on sorted sets */ - 'ZADD' => 'Predis\Command\ZSetAdd', - 'ZINCRBY' => 'Predis\Command\ZSetIncrementBy', - 'ZREM' => 'Predis\Command\ZSetRemove', - 'ZRANGE' => 'Predis\Command\ZSetRange', - 'ZREVRANGE' => 'Predis\Command\ZSetReverseRange', - 'ZRANGEBYSCORE' => 'Predis\Command\ZSetRangeByScore', - 'ZCARD' => 'Predis\Command\ZSetCardinality', - 'ZSCORE' => 'Predis\Command\ZSetScore', - 'ZREMRANGEBYSCORE' => 'Predis\Command\ZSetRemoveRangeByScore', - - /* connection related commands */ - 'PING' => 'Predis\Command\ConnectionPing', - 'AUTH' => 'Predis\Command\ConnectionAuth', - 'SELECT' => 'Predis\Command\ConnectionSelect', - 'ECHO' => 'Predis\Command\ConnectionEcho', - 'QUIT' => 'Predis\Command\ConnectionQuit', - - /* remote server control commands */ - 'INFO' => 'Predis\Command\ServerInfoV26x', - 'SLAVEOF' => 'Predis\Command\ServerSlaveOf', - 'MONITOR' => 'Predis\Command\ServerMonitor', - 'DBSIZE' => 'Predis\Command\ServerDatabaseSize', - 'FLUSHDB' => 'Predis\Command\ServerFlushDatabase', - 'FLUSHALL' => 'Predis\Command\ServerFlushAll', - 'SAVE' => 'Predis\Command\ServerSave', - 'BGSAVE' => 'Predis\Command\ServerBackgroundSave', - 'LASTSAVE' => 'Predis\Command\ServerLastSave', - 'SHUTDOWN' => 'Predis\Command\ServerShutdown', - 'BGREWRITEAOF' => 'Predis\Command\ServerBackgroundRewriteAOF', - - /* ---------------- Redis 2.0 ---------------- */ - - /* commands operating on string values */ - 'SETEX' => 'Predis\Command\StringSetExpire', - 'APPEND' => 'Predis\Command\StringAppend', - 'SUBSTR' => 'Predis\Command\StringSubstr', - - /* commands operating on lists */ - 'BLPOP' => 'Predis\Command\ListPopFirstBlocking', - 'BRPOP' => 'Predis\Command\ListPopLastBlocking', - - /* commands operating on sorted sets */ - 'ZUNIONSTORE' => 'Predis\Command\ZSetUnionStore', - 'ZINTERSTORE' => 'Predis\Command\ZSetIntersectionStore', - 'ZCOUNT' => 'Predis\Command\ZSetCount', - 'ZRANK' => 'Predis\Command\ZSetRank', - 'ZREVRANK' => 'Predis\Command\ZSetReverseRank', - 'ZREMRANGEBYRANK' => 'Predis\Command\ZSetRemoveRangeByRank', - - /* commands operating on hashes */ - 'HSET' => 'Predis\Command\HashSet', - 'HSETNX' => 'Predis\Command\HashSetPreserve', - 'HMSET' => 'Predis\Command\HashSetMultiple', - 'HINCRBY' => 'Predis\Command\HashIncrementBy', - 'HGET' => 'Predis\Command\HashGet', - 'HMGET' => 'Predis\Command\HashGetMultiple', - 'HDEL' => 'Predis\Command\HashDelete', - 'HEXISTS' => 'Predis\Command\HashExists', - 'HLEN' => 'Predis\Command\HashLength', - 'HKEYS' => 'Predis\Command\HashKeys', - 'HVALS' => 'Predis\Command\HashValues', - 'HGETALL' => 'Predis\Command\HashGetAll', - - /* transactions */ - 'MULTI' => 'Predis\Command\TransactionMulti', - 'EXEC' => 'Predis\Command\TransactionExec', - 'DISCARD' => 'Predis\Command\TransactionDiscard', - - /* publish - subscribe */ - 'SUBSCRIBE' => 'Predis\Command\PubSubSubscribe', - 'UNSUBSCRIBE' => 'Predis\Command\PubSubUnsubscribe', - 'PSUBSCRIBE' => 'Predis\Command\PubSubSubscribeByPattern', - 'PUNSUBSCRIBE' => 'Predis\Command\PubSubUnsubscribeByPattern', - 'PUBLISH' => 'Predis\Command\PubSubPublish', - - /* remote server control commands */ - 'CONFIG' => 'Predis\Command\ServerConfig', - - /* ---------------- Redis 2.2 ---------------- */ - - /* commands operating on the key space */ - 'PERSIST' => 'Predis\Command\KeyPersist', - - /* commands operating on string values */ - 'STRLEN' => 'Predis\Command\StringStrlen', - 'SETRANGE' => 'Predis\Command\StringSetRange', - 'GETRANGE' => 'Predis\Command\StringGetRange', - 'SETBIT' => 'Predis\Command\StringSetBit', - 'GETBIT' => 'Predis\Command\StringGetBit', - - /* commands operating on lists */ - 'RPUSHX' => 'Predis\Command\ListPushTailX', - 'LPUSHX' => 'Predis\Command\ListPushHeadX', - 'LINSERT' => 'Predis\Command\ListInsert', - 'BRPOPLPUSH' => 'Predis\Command\ListPopLastPushHeadBlocking', - - /* commands operating on sorted sets */ - 'ZREVRANGEBYSCORE' => 'Predis\Command\ZSetReverseRangeByScore', - - /* transactions */ - 'WATCH' => 'Predis\Command\TransactionWatch', - 'UNWATCH' => 'Predis\Command\TransactionUnwatch', - - /* remote server control commands */ - 'OBJECT' => 'Predis\Command\ServerObject', - 'SLOWLOG' => 'Predis\Command\ServerSlowlog', - - /* ---------------- Redis 2.4 ---------------- */ - - /* remote server control commands */ - 'CLIENT' => 'Predis\Command\ServerClient', - - /* ---------------- Redis 2.6 ---------------- */ - - /* commands operating on the key space */ - 'PTTL' => 'Predis\Command\KeyPreciseTimeToLive', - 'PEXPIRE' => 'Predis\Command\KeyPreciseExpire', - 'PEXPIREAT' => 'Predis\Command\KeyPreciseExpireAt', - 'MIGRATE' => 'Predis\Command\KeyMigrate', - - /* commands operating on string values */ - 'PSETEX' => 'Predis\Command\StringPreciseSetExpire', - 'INCRBYFLOAT' => 'Predis\Command\StringIncrementByFloat', - 'BITOP' => 'Predis\Command\StringBitOp', - 'BITCOUNT' => 'Predis\Command\StringBitCount', - - /* commands operating on hashes */ - 'HINCRBYFLOAT' => 'Predis\Command\HashIncrementByFloat', - - /* scripting */ - 'EVAL' => 'Predis\Command\ServerEval', - 'EVALSHA' => 'Predis\Command\ServerEvalSHA', - 'SCRIPT' => 'Predis\Command\ServerScript', - - /* remote server control commands */ - 'TIME' => 'Predis\Command\ServerTime', - 'SENTINEL' => 'Predis\Command\ServerSentinel', - ); - } -} diff --git a/plugins/cache-redis/Predis/Profile/RedisVersion280.php b/plugins/cache-redis/Predis/Profile/RedisVersion280.php deleted file mode 100644 index ea17e6829..000000000 --- a/plugins/cache-redis/Predis/Profile/RedisVersion280.php +++ /dev/null @@ -1,267 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Profile; - -/** - * Server profile for Redis 2.8. - * - * @author Daniele Alessandri - */ -class RedisVersion280 extends RedisProfile -{ - /** - * {@inheritdoc} - */ - public function getVersion() - { - return '2.8'; - } - - /** - * {@inheritdoc} - */ - public function getSupportedCommands() - { - return array( - /* ---------------- Redis 1.2 ---------------- */ - - /* commands operating on the key space */ - 'EXISTS' => 'Predis\Command\KeyExists', - 'DEL' => 'Predis\Command\KeyDelete', - 'TYPE' => 'Predis\Command\KeyType', - 'KEYS' => 'Predis\Command\KeyKeys', - 'RANDOMKEY' => 'Predis\Command\KeyRandom', - 'RENAME' => 'Predis\Command\KeyRename', - 'RENAMENX' => 'Predis\Command\KeyRenamePreserve', - 'EXPIRE' => 'Predis\Command\KeyExpire', - 'EXPIREAT' => 'Predis\Command\KeyExpireAt', - 'TTL' => 'Predis\Command\KeyTimeToLive', - 'MOVE' => 'Predis\Command\KeyMove', - 'SORT' => 'Predis\Command\KeySort', - 'DUMP' => 'Predis\Command\KeyDump', - 'RESTORE' => 'Predis\Command\KeyRestore', - - /* commands operating on string values */ - 'SET' => 'Predis\Command\StringSet', - 'SETNX' => 'Predis\Command\StringSetPreserve', - 'MSET' => 'Predis\Command\StringSetMultiple', - 'MSETNX' => 'Predis\Command\StringSetMultiplePreserve', - 'GET' => 'Predis\Command\StringGet', - 'MGET' => 'Predis\Command\StringGetMultiple', - 'GETSET' => 'Predis\Command\StringGetSet', - 'INCR' => 'Predis\Command\StringIncrement', - 'INCRBY' => 'Predis\Command\StringIncrementBy', - 'DECR' => 'Predis\Command\StringDecrement', - 'DECRBY' => 'Predis\Command\StringDecrementBy', - - /* commands operating on lists */ - 'RPUSH' => 'Predis\Command\ListPushTail', - 'LPUSH' => 'Predis\Command\ListPushHead', - 'LLEN' => 'Predis\Command\ListLength', - 'LRANGE' => 'Predis\Command\ListRange', - 'LTRIM' => 'Predis\Command\ListTrim', - 'LINDEX' => 'Predis\Command\ListIndex', - 'LSET' => 'Predis\Command\ListSet', - 'LREM' => 'Predis\Command\ListRemove', - 'LPOP' => 'Predis\Command\ListPopFirst', - 'RPOP' => 'Predis\Command\ListPopLast', - 'RPOPLPUSH' => 'Predis\Command\ListPopLastPushHead', - - /* commands operating on sets */ - 'SADD' => 'Predis\Command\SetAdd', - 'SREM' => 'Predis\Command\SetRemove', - 'SPOP' => 'Predis\Command\SetPop', - 'SMOVE' => 'Predis\Command\SetMove', - 'SCARD' => 'Predis\Command\SetCardinality', - 'SISMEMBER' => 'Predis\Command\SetIsMember', - 'SINTER' => 'Predis\Command\SetIntersection', - 'SINTERSTORE' => 'Predis\Command\SetIntersectionStore', - 'SUNION' => 'Predis\Command\SetUnion', - 'SUNIONSTORE' => 'Predis\Command\SetUnionStore', - 'SDIFF' => 'Predis\Command\SetDifference', - 'SDIFFSTORE' => 'Predis\Command\SetDifferenceStore', - 'SMEMBERS' => 'Predis\Command\SetMembers', - 'SRANDMEMBER' => 'Predis\Command\SetRandomMember', - - /* commands operating on sorted sets */ - 'ZADD' => 'Predis\Command\ZSetAdd', - 'ZINCRBY' => 'Predis\Command\ZSetIncrementBy', - 'ZREM' => 'Predis\Command\ZSetRemove', - 'ZRANGE' => 'Predis\Command\ZSetRange', - 'ZREVRANGE' => 'Predis\Command\ZSetReverseRange', - 'ZRANGEBYSCORE' => 'Predis\Command\ZSetRangeByScore', - 'ZCARD' => 'Predis\Command\ZSetCardinality', - 'ZSCORE' => 'Predis\Command\ZSetScore', - 'ZREMRANGEBYSCORE' => 'Predis\Command\ZSetRemoveRangeByScore', - - /* connection related commands */ - 'PING' => 'Predis\Command\ConnectionPing', - 'AUTH' => 'Predis\Command\ConnectionAuth', - 'SELECT' => 'Predis\Command\ConnectionSelect', - 'ECHO' => 'Predis\Command\ConnectionEcho', - 'QUIT' => 'Predis\Command\ConnectionQuit', - - /* remote server control commands */ - 'INFO' => 'Predis\Command\ServerInfoV26x', - 'SLAVEOF' => 'Predis\Command\ServerSlaveOf', - 'MONITOR' => 'Predis\Command\ServerMonitor', - 'DBSIZE' => 'Predis\Command\ServerDatabaseSize', - 'FLUSHDB' => 'Predis\Command\ServerFlushDatabase', - 'FLUSHALL' => 'Predis\Command\ServerFlushAll', - 'SAVE' => 'Predis\Command\ServerSave', - 'BGSAVE' => 'Predis\Command\ServerBackgroundSave', - 'LASTSAVE' => 'Predis\Command\ServerLastSave', - 'SHUTDOWN' => 'Predis\Command\ServerShutdown', - 'BGREWRITEAOF' => 'Predis\Command\ServerBackgroundRewriteAOF', - - /* ---------------- Redis 2.0 ---------------- */ - - /* commands operating on string values */ - 'SETEX' => 'Predis\Command\StringSetExpire', - 'APPEND' => 'Predis\Command\StringAppend', - 'SUBSTR' => 'Predis\Command\StringSubstr', - - /* commands operating on lists */ - 'BLPOP' => 'Predis\Command\ListPopFirstBlocking', - 'BRPOP' => 'Predis\Command\ListPopLastBlocking', - - /* commands operating on sorted sets */ - 'ZUNIONSTORE' => 'Predis\Command\ZSetUnionStore', - 'ZINTERSTORE' => 'Predis\Command\ZSetIntersectionStore', - 'ZCOUNT' => 'Predis\Command\ZSetCount', - 'ZRANK' => 'Predis\Command\ZSetRank', - 'ZREVRANK' => 'Predis\Command\ZSetReverseRank', - 'ZREMRANGEBYRANK' => 'Predis\Command\ZSetRemoveRangeByRank', - - /* commands operating on hashes */ - 'HSET' => 'Predis\Command\HashSet', - 'HSETNX' => 'Predis\Command\HashSetPreserve', - 'HMSET' => 'Predis\Command\HashSetMultiple', - 'HINCRBY' => 'Predis\Command\HashIncrementBy', - 'HGET' => 'Predis\Command\HashGet', - 'HMGET' => 'Predis\Command\HashGetMultiple', - 'HDEL' => 'Predis\Command\HashDelete', - 'HEXISTS' => 'Predis\Command\HashExists', - 'HLEN' => 'Predis\Command\HashLength', - 'HKEYS' => 'Predis\Command\HashKeys', - 'HVALS' => 'Predis\Command\HashValues', - 'HGETALL' => 'Predis\Command\HashGetAll', - - /* transactions */ - 'MULTI' => 'Predis\Command\TransactionMulti', - 'EXEC' => 'Predis\Command\TransactionExec', - 'DISCARD' => 'Predis\Command\TransactionDiscard', - - /* publish - subscribe */ - 'SUBSCRIBE' => 'Predis\Command\PubSubSubscribe', - 'UNSUBSCRIBE' => 'Predis\Command\PubSubUnsubscribe', - 'PSUBSCRIBE' => 'Predis\Command\PubSubSubscribeByPattern', - 'PUNSUBSCRIBE' => 'Predis\Command\PubSubUnsubscribeByPattern', - 'PUBLISH' => 'Predis\Command\PubSubPublish', - - /* remote server control commands */ - 'CONFIG' => 'Predis\Command\ServerConfig', - - /* ---------------- Redis 2.2 ---------------- */ - - /* commands operating on the key space */ - 'PERSIST' => 'Predis\Command\KeyPersist', - - /* commands operating on string values */ - 'STRLEN' => 'Predis\Command\StringStrlen', - 'SETRANGE' => 'Predis\Command\StringSetRange', - 'GETRANGE' => 'Predis\Command\StringGetRange', - 'SETBIT' => 'Predis\Command\StringSetBit', - 'GETBIT' => 'Predis\Command\StringGetBit', - - /* commands operating on lists */ - 'RPUSHX' => 'Predis\Command\ListPushTailX', - 'LPUSHX' => 'Predis\Command\ListPushHeadX', - 'LINSERT' => 'Predis\Command\ListInsert', - 'BRPOPLPUSH' => 'Predis\Command\ListPopLastPushHeadBlocking', - - /* commands operating on sorted sets */ - 'ZREVRANGEBYSCORE' => 'Predis\Command\ZSetReverseRangeByScore', - - /* transactions */ - 'WATCH' => 'Predis\Command\TransactionWatch', - 'UNWATCH' => 'Predis\Command\TransactionUnwatch', - - /* remote server control commands */ - 'OBJECT' => 'Predis\Command\ServerObject', - 'SLOWLOG' => 'Predis\Command\ServerSlowlog', - - /* ---------------- Redis 2.4 ---------------- */ - - /* remote server control commands */ - 'CLIENT' => 'Predis\Command\ServerClient', - - /* ---------------- Redis 2.6 ---------------- */ - - /* commands operating on the key space */ - 'PTTL' => 'Predis\Command\KeyPreciseTimeToLive', - 'PEXPIRE' => 'Predis\Command\KeyPreciseExpire', - 'PEXPIREAT' => 'Predis\Command\KeyPreciseExpireAt', - 'MIGRATE' => 'Predis\Command\KeyMigrate', - - /* commands operating on string values */ - 'PSETEX' => 'Predis\Command\StringPreciseSetExpire', - 'INCRBYFLOAT' => 'Predis\Command\StringIncrementByFloat', - 'BITOP' => 'Predis\Command\StringBitOp', - 'BITCOUNT' => 'Predis\Command\StringBitCount', - - /* commands operating on hashes */ - 'HINCRBYFLOAT' => 'Predis\Command\HashIncrementByFloat', - - /* scripting */ - 'EVAL' => 'Predis\Command\ServerEval', - 'EVALSHA' => 'Predis\Command\ServerEvalSHA', - 'SCRIPT' => 'Predis\Command\ServerScript', - - /* remote server control commands */ - 'TIME' => 'Predis\Command\ServerTime', - 'SENTINEL' => 'Predis\Command\ServerSentinel', - - /* ---------------- Redis 2.8 ---------------- */ - - /* commands operating on the key space */ - 'SCAN' => 'Predis\Command\KeyScan', - - /* commands operating on string values */ - 'BITPOS' => 'Predis\Command\StringBitPos', - - /* commands operating on sets */ - 'SSCAN' => 'Predis\Command\SetScan', - - /* commands operating on sorted sets */ - 'ZSCAN' => 'Predis\Command\ZSetScan', - 'ZLEXCOUNT' => 'Predis\Command\ZSetLexCount', - 'ZRANGEBYLEX' => 'Predis\Command\ZSetRangeByLex', - 'ZREMRANGEBYLEX' => 'Predis\Command\ZSetRemoveRangeByLex', - 'ZREVRANGEBYLEX' => 'Predis\Command\ZSetReverseRangeByLex', - - /* commands operating on hashes */ - 'HSCAN' => 'Predis\Command\HashScan', - - /* publish - subscribe */ - 'PUBSUB' => 'Predis\Command\PubSubPubsub', - - /* commands operating on HyperLogLog */ - 'PFADD' => 'Predis\Command\HyperLogLogAdd', - 'PFCOUNT' => 'Predis\Command\HyperLogLogCount', - 'PFMERGE' => 'Predis\Command\HyperLogLogMerge', - - /* remote server control commands */ - 'COMMAND' => 'Predis\Command\ServerCommand', - ); - } -} diff --git a/plugins/cache-redis/Predis/Profile/RedisVersion300.php b/plugins/cache-redis/Predis/Profile/RedisVersion300.php deleted file mode 100644 index 8a2fac8b7..000000000 --- a/plugins/cache-redis/Predis/Profile/RedisVersion300.php +++ /dev/null @@ -1,270 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Profile; - -/** - * Server profile for Redis 3.0. - * - * @author Daniele Alessandri - */ -class RedisVersion300 extends RedisProfile -{ - /** - * {@inheritdoc} - */ - public function getVersion() - { - return '3.0'; - } - - /** - * {@inheritdoc} - */ - public function getSupportedCommands() - { - return array( - /* ---------------- Redis 1.2 ---------------- */ - - /* commands operating on the key space */ - 'EXISTS' => 'Predis\Command\KeyExists', - 'DEL' => 'Predis\Command\KeyDelete', - 'TYPE' => 'Predis\Command\KeyType', - 'KEYS' => 'Predis\Command\KeyKeys', - 'RANDOMKEY' => 'Predis\Command\KeyRandom', - 'RENAME' => 'Predis\Command\KeyRename', - 'RENAMENX' => 'Predis\Command\KeyRenamePreserve', - 'EXPIRE' => 'Predis\Command\KeyExpire', - 'EXPIREAT' => 'Predis\Command\KeyExpireAt', - 'TTL' => 'Predis\Command\KeyTimeToLive', - 'MOVE' => 'Predis\Command\KeyMove', - 'SORT' => 'Predis\Command\KeySort', - 'DUMP' => 'Predis\Command\KeyDump', - 'RESTORE' => 'Predis\Command\KeyRestore', - - /* commands operating on string values */ - 'SET' => 'Predis\Command\StringSet', - 'SETNX' => 'Predis\Command\StringSetPreserve', - 'MSET' => 'Predis\Command\StringSetMultiple', - 'MSETNX' => 'Predis\Command\StringSetMultiplePreserve', - 'GET' => 'Predis\Command\StringGet', - 'MGET' => 'Predis\Command\StringGetMultiple', - 'GETSET' => 'Predis\Command\StringGetSet', - 'INCR' => 'Predis\Command\StringIncrement', - 'INCRBY' => 'Predis\Command\StringIncrementBy', - 'DECR' => 'Predis\Command\StringDecrement', - 'DECRBY' => 'Predis\Command\StringDecrementBy', - - /* commands operating on lists */ - 'RPUSH' => 'Predis\Command\ListPushTail', - 'LPUSH' => 'Predis\Command\ListPushHead', - 'LLEN' => 'Predis\Command\ListLength', - 'LRANGE' => 'Predis\Command\ListRange', - 'LTRIM' => 'Predis\Command\ListTrim', - 'LINDEX' => 'Predis\Command\ListIndex', - 'LSET' => 'Predis\Command\ListSet', - 'LREM' => 'Predis\Command\ListRemove', - 'LPOP' => 'Predis\Command\ListPopFirst', - 'RPOP' => 'Predis\Command\ListPopLast', - 'RPOPLPUSH' => 'Predis\Command\ListPopLastPushHead', - - /* commands operating on sets */ - 'SADD' => 'Predis\Command\SetAdd', - 'SREM' => 'Predis\Command\SetRemove', - 'SPOP' => 'Predis\Command\SetPop', - 'SMOVE' => 'Predis\Command\SetMove', - 'SCARD' => 'Predis\Command\SetCardinality', - 'SISMEMBER' => 'Predis\Command\SetIsMember', - 'SINTER' => 'Predis\Command\SetIntersection', - 'SINTERSTORE' => 'Predis\Command\SetIntersectionStore', - 'SUNION' => 'Predis\Command\SetUnion', - 'SUNIONSTORE' => 'Predis\Command\SetUnionStore', - 'SDIFF' => 'Predis\Command\SetDifference', - 'SDIFFSTORE' => 'Predis\Command\SetDifferenceStore', - 'SMEMBERS' => 'Predis\Command\SetMembers', - 'SRANDMEMBER' => 'Predis\Command\SetRandomMember', - - /* commands operating on sorted sets */ - 'ZADD' => 'Predis\Command\ZSetAdd', - 'ZINCRBY' => 'Predis\Command\ZSetIncrementBy', - 'ZREM' => 'Predis\Command\ZSetRemove', - 'ZRANGE' => 'Predis\Command\ZSetRange', - 'ZREVRANGE' => 'Predis\Command\ZSetReverseRange', - 'ZRANGEBYSCORE' => 'Predis\Command\ZSetRangeByScore', - 'ZCARD' => 'Predis\Command\ZSetCardinality', - 'ZSCORE' => 'Predis\Command\ZSetScore', - 'ZREMRANGEBYSCORE' => 'Predis\Command\ZSetRemoveRangeByScore', - - /* connection related commands */ - 'PING' => 'Predis\Command\ConnectionPing', - 'AUTH' => 'Predis\Command\ConnectionAuth', - 'SELECT' => 'Predis\Command\ConnectionSelect', - 'ECHO' => 'Predis\Command\ConnectionEcho', - 'QUIT' => 'Predis\Command\ConnectionQuit', - - /* remote server control commands */ - 'INFO' => 'Predis\Command\ServerInfoV26x', - 'SLAVEOF' => 'Predis\Command\ServerSlaveOf', - 'MONITOR' => 'Predis\Command\ServerMonitor', - 'DBSIZE' => 'Predis\Command\ServerDatabaseSize', - 'FLUSHDB' => 'Predis\Command\ServerFlushDatabase', - 'FLUSHALL' => 'Predis\Command\ServerFlushAll', - 'SAVE' => 'Predis\Command\ServerSave', - 'BGSAVE' => 'Predis\Command\ServerBackgroundSave', - 'LASTSAVE' => 'Predis\Command\ServerLastSave', - 'SHUTDOWN' => 'Predis\Command\ServerShutdown', - 'BGREWRITEAOF' => 'Predis\Command\ServerBackgroundRewriteAOF', - - /* ---------------- Redis 2.0 ---------------- */ - - /* commands operating on string values */ - 'SETEX' => 'Predis\Command\StringSetExpire', - 'APPEND' => 'Predis\Command\StringAppend', - 'SUBSTR' => 'Predis\Command\StringSubstr', - - /* commands operating on lists */ - 'BLPOP' => 'Predis\Command\ListPopFirstBlocking', - 'BRPOP' => 'Predis\Command\ListPopLastBlocking', - - /* commands operating on sorted sets */ - 'ZUNIONSTORE' => 'Predis\Command\ZSetUnionStore', - 'ZINTERSTORE' => 'Predis\Command\ZSetIntersectionStore', - 'ZCOUNT' => 'Predis\Command\ZSetCount', - 'ZRANK' => 'Predis\Command\ZSetRank', - 'ZREVRANK' => 'Predis\Command\ZSetReverseRank', - 'ZREMRANGEBYRANK' => 'Predis\Command\ZSetRemoveRangeByRank', - - /* commands operating on hashes */ - 'HSET' => 'Predis\Command\HashSet', - 'HSETNX' => 'Predis\Command\HashSetPreserve', - 'HMSET' => 'Predis\Command\HashSetMultiple', - 'HINCRBY' => 'Predis\Command\HashIncrementBy', - 'HGET' => 'Predis\Command\HashGet', - 'HMGET' => 'Predis\Command\HashGetMultiple', - 'HDEL' => 'Predis\Command\HashDelete', - 'HEXISTS' => 'Predis\Command\HashExists', - 'HLEN' => 'Predis\Command\HashLength', - 'HKEYS' => 'Predis\Command\HashKeys', - 'HVALS' => 'Predis\Command\HashValues', - 'HGETALL' => 'Predis\Command\HashGetAll', - - /* transactions */ - 'MULTI' => 'Predis\Command\TransactionMulti', - 'EXEC' => 'Predis\Command\TransactionExec', - 'DISCARD' => 'Predis\Command\TransactionDiscard', - - /* publish - subscribe */ - 'SUBSCRIBE' => 'Predis\Command\PubSubSubscribe', - 'UNSUBSCRIBE' => 'Predis\Command\PubSubUnsubscribe', - 'PSUBSCRIBE' => 'Predis\Command\PubSubSubscribeByPattern', - 'PUNSUBSCRIBE' => 'Predis\Command\PubSubUnsubscribeByPattern', - 'PUBLISH' => 'Predis\Command\PubSubPublish', - - /* remote server control commands */ - 'CONFIG' => 'Predis\Command\ServerConfig', - - /* ---------------- Redis 2.2 ---------------- */ - - /* commands operating on the key space */ - 'PERSIST' => 'Predis\Command\KeyPersist', - - /* commands operating on string values */ - 'STRLEN' => 'Predis\Command\StringStrlen', - 'SETRANGE' => 'Predis\Command\StringSetRange', - 'GETRANGE' => 'Predis\Command\StringGetRange', - 'SETBIT' => 'Predis\Command\StringSetBit', - 'GETBIT' => 'Predis\Command\StringGetBit', - - /* commands operating on lists */ - 'RPUSHX' => 'Predis\Command\ListPushTailX', - 'LPUSHX' => 'Predis\Command\ListPushHeadX', - 'LINSERT' => 'Predis\Command\ListInsert', - 'BRPOPLPUSH' => 'Predis\Command\ListPopLastPushHeadBlocking', - - /* commands operating on sorted sets */ - 'ZREVRANGEBYSCORE' => 'Predis\Command\ZSetReverseRangeByScore', - - /* transactions */ - 'WATCH' => 'Predis\Command\TransactionWatch', - 'UNWATCH' => 'Predis\Command\TransactionUnwatch', - - /* remote server control commands */ - 'OBJECT' => 'Predis\Command\ServerObject', - 'SLOWLOG' => 'Predis\Command\ServerSlowlog', - - /* ---------------- Redis 2.4 ---------------- */ - - /* remote server control commands */ - 'CLIENT' => 'Predis\Command\ServerClient', - - /* ---------------- Redis 2.6 ---------------- */ - - /* commands operating on the key space */ - 'PTTL' => 'Predis\Command\KeyPreciseTimeToLive', - 'PEXPIRE' => 'Predis\Command\KeyPreciseExpire', - 'PEXPIREAT' => 'Predis\Command\KeyPreciseExpireAt', - 'MIGRATE' => 'Predis\Command\KeyMigrate', - - /* commands operating on string values */ - 'PSETEX' => 'Predis\Command\StringPreciseSetExpire', - 'INCRBYFLOAT' => 'Predis\Command\StringIncrementByFloat', - 'BITOP' => 'Predis\Command\StringBitOp', - 'BITCOUNT' => 'Predis\Command\StringBitCount', - - /* commands operating on hashes */ - 'HINCRBYFLOAT' => 'Predis\Command\HashIncrementByFloat', - - /* scripting */ - 'EVAL' => 'Predis\Command\ServerEval', - 'EVALSHA' => 'Predis\Command\ServerEvalSHA', - 'SCRIPT' => 'Predis\Command\ServerScript', - - /* remote server control commands */ - 'TIME' => 'Predis\Command\ServerTime', - 'SENTINEL' => 'Predis\Command\ServerSentinel', - - /* ---------------- Redis 2.8 ---------------- */ - - /* commands operating on the key space */ - 'SCAN' => 'Predis\Command\KeyScan', - - /* commands operating on string values */ - 'BITPOS' => 'Predis\Command\StringBitPos', - - /* commands operating on sets */ - 'SSCAN' => 'Predis\Command\SetScan', - - /* commands operating on sorted sets */ - 'ZSCAN' => 'Predis\Command\ZSetScan', - 'ZLEXCOUNT' => 'Predis\Command\ZSetLexCount', - 'ZRANGEBYLEX' => 'Predis\Command\ZSetRangeByLex', - 'ZREMRANGEBYLEX' => 'Predis\Command\ZSetRemoveRangeByLex', - 'ZREVRANGEBYLEX' => 'Predis\Command\ZSetReverseRangeByLex', - - /* commands operating on hashes */ - 'HSCAN' => 'Predis\Command\HashScan', - - /* publish - subscribe */ - 'PUBSUB' => 'Predis\Command\PubSubPubsub', - - /* commands operating on HyperLogLog */ - 'PFADD' => 'Predis\Command\HyperLogLogAdd', - 'PFCOUNT' => 'Predis\Command\HyperLogLogCount', - 'PFMERGE' => 'Predis\Command\HyperLogLogMerge', - - /* remote server control commands */ - 'COMMAND' => 'Predis\Command\ServerCommand', - - /* ---------------- Redis 3.0 ---------------- */ - - ); - } -} diff --git a/plugins/cache-redis/Predis/Protocol/ProtocolException.php b/plugins/cache-redis/Predis/Protocol/ProtocolException.php index 6fe5d6d3a..b6ab078a0 100644 --- a/plugins/cache-redis/Predis/Protocol/ProtocolException.php +++ b/plugins/cache-redis/Predis/Protocol/ProtocolException.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,10 +15,8 @@ namespace Predis\Protocol; use Predis\CommunicationException; /** - * Exception used to indentify errors encountered while parsing the Redis wire + * Exception used to identify errors encountered while parsing the Redis wire * protocol. - * - * @author Daniele Alessandri */ class ProtocolException extends CommunicationException { diff --git a/plugins/cache-redis/Predis/Protocol/ProtocolProcessorInterface.php b/plugins/cache-redis/Predis/Protocol/ProtocolProcessorInterface.php index b34ea1814..c36a9bb32 100644 --- a/plugins/cache-redis/Predis/Protocol/ProtocolProcessorInterface.php +++ b/plugins/cache-redis/Predis/Protocol/ProtocolProcessorInterface.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -17,8 +18,6 @@ use Predis\Connection\CompositeConnectionInterface; /** * Defines a pluggable protocol processor capable of serializing commands and * deserializing responses into PHP objects directly from a connection. - * - * @author Daniele Alessandri */ interface ProtocolProcessorInterface { diff --git a/plugins/cache-redis/Predis/Protocol/RequestSerializerInterface.php b/plugins/cache-redis/Predis/Protocol/RequestSerializerInterface.php index eef72a640..ba2a14f43 100644 --- a/plugins/cache-redis/Predis/Protocol/RequestSerializerInterface.php +++ b/plugins/cache-redis/Predis/Protocol/RequestSerializerInterface.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -15,8 +16,6 @@ use Predis\Command\CommandInterface; /** * Defines a pluggable serializer for Redis commands. - * - * @author Daniele Alessandri */ interface RequestSerializerInterface { diff --git a/plugins/cache-redis/Predis/Protocol/ResponseReaderInterface.php b/plugins/cache-redis/Predis/Protocol/ResponseReaderInterface.php index 86a7bdcce..ce9c09395 100644 --- a/plugins/cache-redis/Predis/Protocol/ResponseReaderInterface.php +++ b/plugins/cache-redis/Predis/Protocol/ResponseReaderInterface.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -16,8 +17,6 @@ use Predis\Connection\CompositeConnectionInterface; /** * Defines a pluggable reader capable of parsing responses returned by Redis and * deserializing them to PHP objects. - * - * @author Daniele Alessandri */ interface ResponseReaderInterface { diff --git a/plugins/cache-redis/Predis/Protocol/Text/CompositeProtocolProcessor.php b/plugins/cache-redis/Predis/Protocol/Text/CompositeProtocolProcessor.php index ea85ed303..3f7df02e5 100644 --- a/plugins/cache-redis/Predis/Protocol/Text/CompositeProtocolProcessor.php +++ b/plugins/cache-redis/Predis/Protocol/Text/CompositeProtocolProcessor.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -21,9 +22,7 @@ use Predis\Protocol\ResponseReaderInterface; * Composite protocol processor for the standard Redis wire protocol using * pluggable handlers to serialize requests and deserialize responses. * - * @link http://redis.io/topics/protocol - * - * @author Daniele Alessandri + * @see http://redis.io/topics/protocol */ class CompositeProtocolProcessor implements ProtocolProcessorInterface { diff --git a/plugins/cache-redis/Predis/Protocol/Text/Handler/BulkResponse.php b/plugins/cache-redis/Predis/Protocol/Text/Handler/BulkResponse.php index 5b0bf3c2d..961c01188 100644 --- a/plugins/cache-redis/Predis/Protocol/Text/Handler/BulkResponse.php +++ b/plugins/cache-redis/Predis/Protocol/Text/Handler/BulkResponse.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -19,9 +20,7 @@ use Predis\Protocol\ProtocolException; * Handler for the bulk response type in the standard Redis wire protocol. * It translates the payload to a string or a NULL. * - * @link http://redis.io/topics/protocol - * - * @author Daniele Alessandri + * @see http://redis.io/topics/protocol */ class BulkResponse implements ResponseHandlerInterface { @@ -34,7 +33,7 @@ class BulkResponse implements ResponseHandlerInterface if ("$length" !== $payload) { CommunicationException::handle(new ProtocolException( - $connection, "Cannot parse '$payload' as a valid length for a bulk response." + $connection, "Cannot parse '$payload' as a valid length for a bulk response [{$connection->getParameters()}]" )); } @@ -47,7 +46,7 @@ class BulkResponse implements ResponseHandlerInterface } CommunicationException::handle(new ProtocolException( - $connection, "Value '$payload' is not a valid length for a bulk response." + $connection, "Value '$payload' is not a valid length for a bulk response [{$connection->getParameters()}]" )); return; diff --git a/plugins/cache-redis/Predis/Protocol/Text/Handler/ErrorResponse.php b/plugins/cache-redis/Predis/Protocol/Text/Handler/ErrorResponse.php index 3e18b7b9e..aa400a47b 100644 --- a/plugins/cache-redis/Predis/Protocol/Text/Handler/ErrorResponse.php +++ b/plugins/cache-redis/Predis/Protocol/Text/Handler/ErrorResponse.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -18,9 +19,7 @@ use Predis\Response\Error; * Handler for the error response type in the standard Redis wire protocol. * It translates the payload to a complex response object for Predis. * - * @link http://redis.io/topics/protocol - * - * @author Daniele Alessandri + * @see http://redis.io/topics/protocol */ class ErrorResponse implements ResponseHandlerInterface { diff --git a/plugins/cache-redis/Predis/Protocol/Text/Handler/IntegerResponse.php b/plugins/cache-redis/Predis/Protocol/Text/Handler/IntegerResponse.php index 4639d7792..cb58a3d42 100644 --- a/plugins/cache-redis/Predis/Protocol/Text/Handler/IntegerResponse.php +++ b/plugins/cache-redis/Predis/Protocol/Text/Handler/IntegerResponse.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -19,9 +20,7 @@ use Predis\Protocol\ProtocolException; * Handler for the integer response type in the standard Redis wire protocol. * It translates the payload an integer or NULL. * - * @link http://redis.io/topics/protocol - * - * @author Daniele Alessandri + * @see http://redis.io/topics/protocol */ class IntegerResponse implements ResponseHandlerInterface { @@ -31,12 +30,14 @@ class IntegerResponse implements ResponseHandlerInterface public function handle(CompositeConnectionInterface $connection, $payload) { if (is_numeric($payload)) { - return (int) $payload; + $integer = (int) $payload; + + return $integer == $payload ? $integer : $payload; } if ($payload !== 'nil') { CommunicationException::handle(new ProtocolException( - $connection, "Cannot parse '$payload' as a valid numeric response." + $connection, "Cannot parse '$payload' as a valid numeric response [{$connection->getParameters()}]" )); } diff --git a/plugins/cache-redis/Predis/Protocol/Text/Handler/MultiBulkResponse.php b/plugins/cache-redis/Predis/Protocol/Text/Handler/MultiBulkResponse.php index 820b9b4a6..d9c51425d 100644 --- a/plugins/cache-redis/Predis/Protocol/Text/Handler/MultiBulkResponse.php +++ b/plugins/cache-redis/Predis/Protocol/Text/Handler/MultiBulkResponse.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -19,9 +20,7 @@ use Predis\Protocol\ProtocolException; * Handler for the multibulk response type in the standard Redis wire protocol. * It returns multibulk responses as PHP arrays. * - * @link http://redis.io/topics/protocol - * - * @author Daniele Alessandri + * @see http://redis.io/topics/protocol */ class MultiBulkResponse implements ResponseHandlerInterface { @@ -34,7 +33,7 @@ class MultiBulkResponse implements ResponseHandlerInterface if ("$length" !== $payload) { CommunicationException::handle(new ProtocolException( - $connection, "Cannot parse '$payload' as a valid length of a multi-bulk response." + $connection, "Cannot parse '$payload' as a valid length of a multi-bulk response [{$connection->getParameters()}]" )); } @@ -42,10 +41,10 @@ class MultiBulkResponse implements ResponseHandlerInterface return; } - $list = array(); + $list = []; if ($length > 0) { - $handlersCache = array(); + $handlersCache = []; $reader = $connection->getProtocol()->getResponseReader(); for ($i = 0; $i < $length; ++$i) { diff --git a/plugins/cache-redis/Predis/Protocol/Text/Handler/ResponseHandlerInterface.php b/plugins/cache-redis/Predis/Protocol/Text/Handler/ResponseHandlerInterface.php index ca08a9c53..b1c90665a 100644 --- a/plugins/cache-redis/Predis/Protocol/Text/Handler/ResponseHandlerInterface.php +++ b/plugins/cache-redis/Predis/Protocol/Text/Handler/ResponseHandlerInterface.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -15,8 +16,6 @@ use Predis\Connection\CompositeConnectionInterface; /** * Defines a pluggable handler used to parse a particular type of response. - * - * @author Daniele Alessandri */ interface ResponseHandlerInterface { diff --git a/plugins/cache-redis/Predis/Protocol/Text/Handler/StatusResponse.php b/plugins/cache-redis/Predis/Protocol/Text/Handler/StatusResponse.php index 7bde5558f..efc13656a 100644 --- a/plugins/cache-redis/Predis/Protocol/Text/Handler/StatusResponse.php +++ b/plugins/cache-redis/Predis/Protocol/Text/Handler/StatusResponse.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -19,9 +20,7 @@ use Predis\Response\Status; * translates certain classes of status response to PHP objects or just returns * the payload as a string. * - * @link http://redis.io/topics/protocol - * - * @author Daniele Alessandri + * @see http://redis.io/topics/protocol */ class StatusResponse implements ResponseHandlerInterface { diff --git a/plugins/cache-redis/Predis/Protocol/Text/Handler/StreamableMultiBulkResponse.php b/plugins/cache-redis/Predis/Protocol/Text/Handler/StreamableMultiBulkResponse.php index 7cdb736af..7738e9dbe 100644 --- a/plugins/cache-redis/Predis/Protocol/Text/Handler/StreamableMultiBulkResponse.php +++ b/plugins/cache-redis/Predis/Protocol/Text/Handler/StreamableMultiBulkResponse.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -23,9 +24,7 @@ use Predis\Response\Iterator\MultiBulk as MultiBulkIterator; * Streamable multibulk responses are not globally supported by the abstractions * built-in into Predis, such as transactions or pipelines. Use them with care! * - * @link http://redis.io/topics/protocol - * - * @author Daniele Alessandri + * @see http://redis.io/topics/protocol */ class StreamableMultiBulkResponse implements ResponseHandlerInterface { @@ -38,7 +37,7 @@ class StreamableMultiBulkResponse implements ResponseHandlerInterface if ("$length" != $payload) { CommunicationException::handle(new ProtocolException( - $connection, "Cannot parse '$payload' as a valid length for a multi-bulk response." + $connection, "Cannot parse '$payload' as a valid length for a multi-bulk response [{$connection->getParameters()}]" )); } diff --git a/plugins/cache-redis/Predis/Protocol/Text/ProtocolProcessor.php b/plugins/cache-redis/Predis/Protocol/Text/ProtocolProcessor.php index f04c3ed5b..02e0c5d58 100644 --- a/plugins/cache-redis/Predis/Protocol/Text/ProtocolProcessor.php +++ b/plugins/cache-redis/Predis/Protocol/Text/ProtocolProcessor.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -23,18 +24,13 @@ use Predis\Response\Status as StatusResponse; /** * Protocol processor for the standard Redis wire protocol. * - * @link http://redis.io/topics/protocol - * - * @author Daniele Alessandri + * @see http://redis.io/topics/protocol */ class ProtocolProcessor implements ProtocolProcessorInterface { protected $mbiterable; protected $serializer; - /** - * - */ public function __construct() { $this->mbiterable = false; @@ -81,7 +77,7 @@ class ProtocolProcessor implements ProtocolProcessorInterface return new MultiBulkIterator($connection, $count); } - $multibulk = array(); + $multibulk = []; for ($i = 0; $i < $count; ++$i) { $multibulk[$i] = $this->read($connection); @@ -90,14 +86,16 @@ class ProtocolProcessor implements ProtocolProcessorInterface return $multibulk; case ':': - return (int) $payload; + $integer = (int) $payload; + + return $integer == $payload ? $integer : $payload; case '-': return new ErrorResponse($payload); default: CommunicationException::handle(new ProtocolException( - $connection, "Unknown response prefix: '$prefix'." + $connection, "Unknown response prefix: '$prefix' [{$connection->getParameters()}]" )); return; diff --git a/plugins/cache-redis/Predis/Protocol/Text/RequestSerializer.php b/plugins/cache-redis/Predis/Protocol/Text/RequestSerializer.php index c8cbbfbcd..853bae03a 100644 --- a/plugins/cache-redis/Predis/Protocol/Text/RequestSerializer.php +++ b/plugins/cache-redis/Predis/Protocol/Text/RequestSerializer.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -17,9 +18,7 @@ use Predis\Protocol\RequestSerializerInterface; /** * Request serializer for the standard Redis wire protocol. * - * @link http://redis.io/topics/protocol - * - * @author Daniele Alessandri + * @see http://redis.io/topics/protocol */ class RequestSerializer implements RequestSerializerInterface { @@ -36,8 +35,7 @@ class RequestSerializer implements RequestSerializerInterface $buffer = "*{$reqlen}\r\n\${$cmdlen}\r\n{$commandID}\r\n"; - for ($i = 0, $reqlen--; $i < $reqlen; ++$i) { - $argument = $arguments[$i]; + foreach ($arguments as $argument) { $arglen = strlen($argument); $buffer .= "\${$arglen}\r\n{$argument}\r\n"; } diff --git a/plugins/cache-redis/Predis/Protocol/Text/ResponseReader.php b/plugins/cache-redis/Predis/Protocol/Text/ResponseReader.php index d96218dfa..f49c96d26 100644 --- a/plugins/cache-redis/Predis/Protocol/Text/ResponseReader.php +++ b/plugins/cache-redis/Predis/Protocol/Text/ResponseReader.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -19,17 +20,12 @@ use Predis\Protocol\ResponseReaderInterface; /** * Response reader for the standard Redis wire protocol. * - * @link http://redis.io/topics/protocol - * - * @author Daniele Alessandri + * @see http://redis.io/topics/protocol */ class ResponseReader implements ResponseReaderInterface { protected $handlers; - /** - * - */ public function __construct() { $this->handlers = $this->getDefaultHandlers(); @@ -42,13 +38,13 @@ class ResponseReader implements ResponseReaderInterface */ protected function getDefaultHandlers() { - return array( + return [ '+' => new Handler\StatusResponse(), '-' => new Handler\ErrorResponse(), ':' => new Handler\IntegerResponse(), '$' => new Handler\BulkResponse(), '*' => new Handler\MultiBulkResponse(), - ); + ]; } /** @@ -86,18 +82,16 @@ class ResponseReader implements ResponseReaderInterface $header = $connection->readLine(); if ($header === '') { - $this->onProtocolError($connection, 'Unexpected empty reponse header.'); + $this->onProtocolError($connection, 'Unexpected empty response header'); } $prefix = $header[0]; if (!isset($this->handlers[$prefix])) { - $this->onProtocolError($connection, "Unknown response prefix: '$prefix'."); + $this->onProtocolError($connection, "Unknown response prefix: '$prefix'"); } - $payload = $this->handlers[$prefix]->handle($connection, substr($header, 1)); - - return $payload; + return $this->handlers[$prefix]->handle($connection, substr($header, 1)); } /** @@ -110,7 +104,7 @@ class ResponseReader implements ResponseReaderInterface protected function onProtocolError(CompositeConnectionInterface $connection, $message) { CommunicationException::handle( - new ProtocolException($connection, $message) + new ProtocolException($connection, "$message [{$connection->getParameters()}]") ); } } diff --git a/plugins/cache-redis/Predis/PubSub/AbstractConsumer.php b/plugins/cache-redis/Predis/PubSub/AbstractConsumer.php index d7423f1e3..c9ea2d658 100644 --- a/plugins/cache-redis/Predis/PubSub/AbstractConsumer.php +++ b/plugins/cache-redis/Predis/PubSub/AbstractConsumer.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,27 +12,28 @@ namespace Predis\PubSub; +use Iterator; +use ReturnTypeWillChange; + /** * Base implementation of a PUB/SUB consumer abstraction based on PHP iterators. - * - * @author Daniele Alessandri */ -abstract class AbstractConsumer implements \Iterator +abstract class AbstractConsumer implements Iterator { - const SUBSCRIBE = 'subscribe'; - const UNSUBSCRIBE = 'unsubscribe'; - const PSUBSCRIBE = 'psubscribe'; - const PUNSUBSCRIBE = 'punsubscribe'; - const MESSAGE = 'message'; - const PMESSAGE = 'pmessage'; - const PONG = 'pong'; + public const SUBSCRIBE = 'subscribe'; + public const UNSUBSCRIBE = 'unsubscribe'; + public const PSUBSCRIBE = 'psubscribe'; + public const PUNSUBSCRIBE = 'punsubscribe'; + public const MESSAGE = 'message'; + public const PMESSAGE = 'pmessage'; + public const PONG = 'pong'; - const STATUS_VALID = 1; // 0b0001 - const STATUS_SUBSCRIBED = 2; // 0b0010 - const STATUS_PSUBSCRIBED = 4; // 0b0100 + public const STATUS_VALID = 1; // 0b0001 + public const STATUS_SUBSCRIBED = 2; // 0b0010 + public const STATUS_PSUBSCRIBED = 4; // 0b0100 - private $position = null; - private $statusFlags = self::STATUS_VALID; + protected $position; + protected $statusFlags = self::STATUS_VALID; /** * Automatically stops the consumer when the garbage collector kicks in. @@ -56,9 +58,9 @@ abstract class AbstractConsumer implements \Iterator /** * Subscribes to the specified channels. * - * @param mixed $channel,... One or more channel names. + * @param string ...$channel One or more channel names. */ - public function subscribe($channel /*, ... */) + public function subscribe($channel /* , ... */) { $this->writeRequest(self::SUBSCRIBE, func_get_args()); $this->statusFlags |= self::STATUS_SUBSCRIBED; @@ -67,9 +69,9 @@ abstract class AbstractConsumer implements \Iterator /** * Unsubscribes from the specified channels. * - * @param string ... One or more channel names. + * @param string ...$channel One or more channel names. */ - public function unsubscribe(/* ... */) + public function unsubscribe(...$channel) { $this->writeRequest(self::UNSUBSCRIBE, func_get_args()); } @@ -77,9 +79,9 @@ abstract class AbstractConsumer implements \Iterator /** * Subscribes to the specified channels using a pattern. * - * @param mixed $pattern,... One or more channel name patterns. + * @param string ...$pattern One or more channel name patterns. */ - public function psubscribe($pattern /* ... */) + public function psubscribe(...$pattern) { $this->writeRequest(self::PSUBSCRIBE, func_get_args()); $this->statusFlags |= self::STATUS_PSUBSCRIBED; @@ -88,9 +90,9 @@ abstract class AbstractConsumer implements \Iterator /** * Unsubscribes from the specified channels using a pattern. * - * @param string ... One or more channel name patterns. + * @param string ...$pattern One or more channel name patterns. */ - public function punsubscribe(/* ... */) + public function punsubscribe(...$pattern) { $this->writeRequest(self::PUNSUBSCRIBE, func_get_args()); } @@ -103,7 +105,7 @@ abstract class AbstractConsumer implements \Iterator */ public function ping($payload = null) { - $this->writeRequest('PING', array($payload)); + $this->writeRequest('PING', [$payload]); } /** @@ -149,8 +151,9 @@ abstract class AbstractConsumer implements \Iterator abstract protected function writeRequest($method, $arguments); /** - * {@inheritdoc} + * @return void */ + #[ReturnTypeWillChange] public function rewind() { // NOOP @@ -162,22 +165,25 @@ abstract class AbstractConsumer implements \Iterator * * @return array */ + #[ReturnTypeWillChange] public function current() { return $this->getValue(); } /** - * {@inheritdoc} + * @return int|null */ + #[ReturnTypeWillChange] public function key() { return $this->position; } /** - * {@inheritdoc} + * @return int|null */ + #[ReturnTypeWillChange] public function next() { if ($this->valid()) { @@ -192,6 +198,7 @@ abstract class AbstractConsumer implements \Iterator * * @return bool */ + #[ReturnTypeWillChange] public function valid() { $isValid = $this->isFlagSet(self::STATUS_VALID); diff --git a/plugins/cache-redis/Predis/PubSub/Consumer.php b/plugins/cache-redis/Predis/PubSub/Consumer.php index 5f2d8a8bc..b52673232 100644 --- a/plugins/cache-redis/Predis/PubSub/Consumer.php +++ b/plugins/cache-redis/Predis/PubSub/Consumer.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,18 +15,16 @@ namespace Predis\PubSub; use Predis\ClientException; use Predis\ClientInterface; use Predis\Command\Command; -use Predis\Connection\AggregateConnectionInterface; +use Predis\Connection\Cluster\ClusterInterface; use Predis\NotSupportedException; /** - * PUB/SUB consumer abstraction. - * - * @author Daniele Alessandri + * PUB/SUB consumer. */ class Consumer extends AbstractConsumer { - private $client; - private $options; + protected $client; + protected $options; /** * @param ClientInterface $client Client instance used by the consumer. @@ -35,7 +34,7 @@ class Consumer extends AbstractConsumer { $this->checkCapabilities($client); - $this->options = $options ?: array(); + $this->options = $options ?: []; $this->client = $client; $this->genericSubscribeInit('subscribe'); @@ -60,19 +59,19 @@ class Consumer extends AbstractConsumer * * @throws NotSupportedException */ - private function checkCapabilities(ClientInterface $client) + protected function checkCapabilities(ClientInterface $client) { - if ($client->getConnection() instanceof AggregateConnectionInterface) { + if ($client->getConnection() instanceof ClusterInterface) { throw new NotSupportedException( - 'Cannot initialize a PUB/SUB consumer over aggregate connections.' + 'Cannot initialize a PUB/SUB consumer over cluster connections.' ); } - $commands = array('publish', 'subscribe', 'unsubscribe', 'psubscribe', 'punsubscribe'); + $commands = ['publish', 'subscribe', 'unsubscribe', 'psubscribe', 'punsubscribe']; - if ($client->getProfile()->supportsCommands($commands) === false) { + if (!$client->getCommandFactory()->supports(...$commands)) { throw new NotSupportedException( - 'The current profile does not support PUB/SUB related commands.' + 'PUB/SUB commands are not supported by the current command factory.' ); } } @@ -82,7 +81,7 @@ class Consumer extends AbstractConsumer * * @param string $subscribeAction Type of subscription. */ - private function genericSubscribeInit($subscribeAction) + protected function genericSubscribeInit($subscribeAction) { if (isset($this->options[$subscribeAction])) { $this->$subscribeAction($this->options[$subscribeAction]); @@ -129,25 +128,25 @@ class Consumer extends AbstractConsumer // no break case self::MESSAGE: - return (object) array( + return (object) [ 'kind' => $response[0], 'channel' => $response[1], 'payload' => $response[2], - ); + ]; case self::PMESSAGE: - return (object) array( + return (object) [ 'kind' => $response[0], 'pattern' => $response[1], 'channel' => $response[2], 'payload' => $response[3], - ); + ]; case self::PONG: - return (object) array( + return (object) [ 'kind' => $response[0], 'payload' => $response[1], - ); + ]; default: throw new ClientException( diff --git a/plugins/cache-redis/Predis/PubSub/DispatcherLoop.php b/plugins/cache-redis/Predis/PubSub/DispatcherLoop.php index 0d4a08ef7..b6f79cd3d 100644 --- a/plugins/cache-redis/Predis/PubSub/DispatcherLoop.php +++ b/plugins/cache-redis/Predis/PubSub/DispatcherLoop.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,11 +12,11 @@ namespace Predis\PubSub; +use InvalidArgumentException; + /** * Method-dispatcher loop built around the client-side abstraction of a Redis * PUB / SUB context. - * - * @author Daniele Alessandri */ class DispatcherLoop { @@ -30,7 +31,7 @@ class DispatcherLoop */ public function __construct(Consumer $pubsub) { - $this->callbacks = array(); + $this->callbacks = []; $this->pubsub = $pubsub; } @@ -39,12 +40,12 @@ class DispatcherLoop * * @param mixed $callable A callback. * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ protected function assertCallback($callable) { if (!is_callable($callable)) { - throw new \InvalidArgumentException('The given argument must be a callable object.'); + throw new InvalidArgumentException('The given argument must be a callable object.'); } } @@ -91,11 +92,11 @@ class DispatcherLoop * Binds a callback to a channel. * * @param string $channel Channel name. - * @param Callable $callback A callback. + * @param callable $callback A callback. */ public function attachCallback($channel, $callback) { - $callbackName = $this->getPrefixKeys().$channel; + $callbackName = $this->getPrefixKeys() . $channel; $this->assertCallback($callback); $this->callbacks[$callbackName] = $callback; @@ -109,7 +110,7 @@ class DispatcherLoop */ public function detachCallback($channel) { - $callbackName = $this->getPrefixKeys().$channel; + $callbackName = $this->getPrefixKeys() . $channel; if (isset($this->callbacks[$callbackName])) { unset($this->callbacks[$callbackName]); @@ -128,7 +129,7 @@ class DispatcherLoop if ($kind !== Consumer::MESSAGE && $kind !== Consumer::PMESSAGE) { if (isset($this->subscriptionCallback)) { $callback = $this->subscriptionCallback; - call_user_func($callback, $message); + call_user_func($callback, $message, $this); } continue; @@ -136,10 +137,10 @@ class DispatcherLoop if (isset($this->callbacks[$message->channel])) { $callback = $this->callbacks[$message->channel]; - call_user_func($callback, $message->payload); + call_user_func($callback, $message->payload, $this); } elseif (isset($this->defaultCallback)) { $callback = $this->defaultCallback; - call_user_func($callback, $message); + call_user_func($callback, $message, $this); } } } diff --git a/plugins/cache-redis/Predis/Replication/ReplicationStrategy.php b/plugins/cache-redis/Predis/Replication/ReplicationStrategy.php index 0b7694054..f2c1bf56a 100644 --- a/plugins/cache-redis/Predis/Replication/ReplicationStrategy.php +++ b/plugins/cache-redis/Predis/Replication/ReplicationStrategy.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -16,23 +17,19 @@ use Predis\NotSupportedException; /** * Defines a strategy for master/slave replication. - * - * @author Daniele Alessandri */ class ReplicationStrategy { protected $disallowed; protected $readonly; protected $readonlySHA1; + protected $loadBalancing = true; - /** - * - */ public function __construct() { $this->disallowed = $this->getDisallowedOperations(); $this->readonly = $this->getReadOnlyOperations(); - $this->readonlySHA1 = array(); + $this->readonlySHA1 = []; } /** @@ -41,12 +38,15 @@ class ReplicationStrategy * * @param CommandInterface $command Command instance. * - * @throws NotSupportedException - * * @return bool + * @throws NotSupportedException */ public function isReadOperation(CommandInterface $command) { + if (!$this->loadBalancing) { + return false; + } + if (isset($this->disallowed[$id = $command->getId()])) { throw new NotSupportedException( "The command '$id' is not allowed in replication mode." @@ -62,7 +62,8 @@ class ReplicationStrategy } if (($eval = $id === 'EVAL') || $id === 'EVALSHA') { - $sha1 = $eval ? sha1($command->getArgument(0)) : $command->getArgument(0); + $argument = $command->getArgument(0); + $sha1 = $eval ? sha1(strval($argument)) : $argument; if (isset($this->readonlySHA1[$sha1])) { if (true === $readonly = $this->readonlySHA1[$sha1]) { @@ -90,18 +91,54 @@ class ReplicationStrategy } /** - * Checks if a SORT command is a readable operation by parsing the arguments - * array of the specified commad instance. + * Checks if BITFIELD performs a read-only operation by looking for certain + * SET and INCRYBY modifiers in the arguments array of the command. * * @param CommandInterface $command Command instance. * * @return bool */ - protected function isSortReadOnly(CommandInterface $command) + protected function isBitfieldReadOnly(CommandInterface $command) { $arguments = $command->getArguments(); + $argc = count($arguments); - return ($c = count($arguments)) === 1 ? true : $arguments[$c - 2] !== 'STORE'; + if ($argc >= 2) { + for ($i = 1; $i < $argc; ++$i) { + $argument = strtoupper($arguments[$i]); + if ($argument === 'SET' || $argument === 'INCRBY') { + return false; + } + } + } + + return true; + } + + /** + * Checks if a GEORADIUS command is a readable operation by parsing the + * arguments array of the specified command instance. + * + * @param CommandInterface $command Command instance. + * + * @return bool + */ + protected function isGeoradiusReadOnly(CommandInterface $command) + { + $arguments = $command->getArguments(); + $argc = count($arguments); + $startIndex = $command->getId() === 'GEORADIUS' ? 5 : 4; + + if ($argc > $startIndex) { + for ($i = $startIndex; $i < $argc; ++$i) { + $argument = strtoupper($arguments[$i]); + if ($argument === 'STORE' || $argument === 'STOREDIST') { + return false; + } + } + } + + return true; } /** @@ -153,7 +190,7 @@ class ReplicationStrategy */ protected function getDisallowedOperations() { - return array( + return [ 'SHUTDOWN' => true, 'INFO' => true, 'DBSIZE' => true, @@ -165,7 +202,7 @@ class ReplicationStrategy 'BGSAVE' => true, 'BGREWRITEAOF' => true, 'SLOWLOG' => true, - ); + ]; } /** @@ -175,7 +212,7 @@ class ReplicationStrategy */ protected function getReadOnlyOperations() { - return array( + return [ 'EXISTS' => true, 'TYPE' => true, 'KEYS' => true, @@ -231,7 +268,25 @@ class ReplicationStrategy 'BITPOS' => true, 'TIME' => true, 'PFCOUNT' => true, - 'SORT' => array($this, 'isSortReadOnly'), - ); + 'BITFIELD' => [$this, 'isBitfieldReadOnly'], + 'GEOHASH' => true, + 'GEOPOS' => true, + 'GEODIST' => true, + 'GEORADIUS' => [$this, 'isGeoradiusReadOnly'], + 'GEORADIUSBYMEMBER' => [$this, 'isGeoradiusReadOnly'], + ]; + } + + /** + * Disables reads to slaves when using + * a replication topology. + * + * @return self + */ + public function disableLoadBalancing(): self + { + $this->loadBalancing = false; + + return $this; } } diff --git a/plugins/cache-redis/Predis/Response/Error.php b/plugins/cache-redis/Predis/Response/Error.php index 3933857e2..3a1c50343 100644 --- a/plugins/cache-redis/Predis/Response/Error.php +++ b/plugins/cache-redis/Predis/Response/Error.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,8 +15,6 @@ namespace Predis\Response; /** * Represents an error returned by Redis (-ERR responses) during the execution * of a command on the server. - * - * @author Daniele Alessandri */ class Error implements ErrorInterface { @@ -42,7 +41,7 @@ class Error implements ErrorInterface */ public function getErrorType() { - list($errorType) = explode(' ', $this->getMessage(), 2); + [$errorType] = explode(' ', $this->getMessage(), 2); return $errorType; } diff --git a/plugins/cache-redis/Predis/Response/ErrorInterface.php b/plugins/cache-redis/Predis/Response/ErrorInterface.php index a4a4a02f7..ac3bb16e8 100644 --- a/plugins/cache-redis/Predis/Response/ErrorInterface.php +++ b/plugins/cache-redis/Predis/Response/ErrorInterface.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -14,8 +15,6 @@ namespace Predis\Response; /** * Represents an error returned by Redis (responses identified by "-" in the * Redis protocol) during the execution of an operation on the server. - * - * @author Daniele Alessandri */ interface ErrorInterface extends ResponseInterface { diff --git a/plugins/cache-redis/Predis/Response/Iterator/MultiBulk.php b/plugins/cache-redis/Predis/Response/Iterator/MultiBulk.php index b1d29241c..09f4c08e5 100644 --- a/plugins/cache-redis/Predis/Response/Iterator/MultiBulk.php +++ b/plugins/cache-redis/Predis/Response/Iterator/MultiBulk.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -15,8 +16,6 @@ use Predis\Connection\NodeConnectionInterface; /** * Streamable multibulk response. - * - * @author Daniele Alessandri */ class MultiBulk extends MultiBulkIterator { diff --git a/plugins/cache-redis/Predis/Response/Iterator/MultiBulkIterator.php b/plugins/cache-redis/Predis/Response/Iterator/MultiBulkIterator.php index 5d328869b..cbc613859 100644 --- a/plugins/cache-redis/Predis/Response/Iterator/MultiBulkIterator.php +++ b/plugins/cache-redis/Predis/Response/Iterator/MultiBulkIterator.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,7 +12,10 @@ namespace Predis\Response\Iterator; +use Countable; +use Iterator; use Predis\Response\ResponseInterface; +use ReturnTypeWillChange; /** * Iterator that abstracts the access to multibulk responses allowing them to be @@ -22,42 +26,44 @@ use Predis\Response\ResponseInterface; * * Always make sure that the whole iteration is consumed (or dropped) to prevent * protocol desynchronization issues. - * - * @author Daniele Alessandri */ -abstract class MultiBulkIterator implements \Iterator, \Countable, ResponseInterface +abstract class MultiBulkIterator implements Iterator, Countable, ResponseInterface { protected $current; protected $position; protected $size; /** - * {@inheritdoc} + * @return void */ + #[ReturnTypeWillChange] public function rewind() { // NOOP } /** - * {@inheritdoc} + * @return mixed */ + #[ReturnTypeWillChange] public function current() { return $this->current; } /** - * {@inheritdoc} + * @return int|null */ + #[ReturnTypeWillChange] public function key() { return $this->position; } /** - * {@inheritdoc} + * @return void */ + #[ReturnTypeWillChange] public function next() { if (++$this->position < $this->size) { @@ -66,8 +72,9 @@ abstract class MultiBulkIterator implements \Iterator, \Countable, ResponseInter } /** - * {@inheritdoc} + * @return bool */ + #[ReturnTypeWillChange] public function valid() { return $this->position < $this->size; @@ -82,6 +89,7 @@ abstract class MultiBulkIterator implements \Iterator, \Countable, ResponseInter * * @return int */ + #[ReturnTypeWillChange] public function count() { return $this->size; diff --git a/plugins/cache-redis/Predis/Response/Iterator/MultiBulkTuple.php b/plugins/cache-redis/Predis/Response/Iterator/MultiBulkTuple.php index 2b6f593c4..4761f0ec2 100644 --- a/plugins/cache-redis/Predis/Response/Iterator/MultiBulkTuple.php +++ b/plugins/cache-redis/Predis/Response/Iterator/MultiBulkTuple.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,16 +12,19 @@ namespace Predis\Response\Iterator; +use InvalidArgumentException; +use OuterIterator; +use ReturnTypeWillChange; +use UnexpectedValueException; + /** * Outer iterator consuming streamable multibulk responses by yielding tuples of * keys and values. * * This wrapper is useful for responses to commands such as `HGETALL` that can - * be iterater as $key => $value pairs. - * - * @author Daniele Alessandri + * be iterator as $key => $value pairs. */ -class MultiBulkTuple extends MultiBulk implements \OuterIterator +class MultiBulkTuple extends MultiBulk implements OuterIterator { private $iterator; @@ -42,25 +46,26 @@ class MultiBulkTuple extends MultiBulk implements \OuterIterator * * @param MultiBulk $iterator Inner multibulk response iterator. * - * @throws \InvalidArgumentException - * @throws \UnexpectedValueException + * @throws InvalidArgumentException + * @throws UnexpectedValueException */ protected function checkPreconditions(MultiBulk $iterator) { if ($iterator->getPosition() !== 0) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Cannot initialize a tuple iterator using an already initiated iterator.' ); } if (($size = count($iterator)) % 2 !== 0) { - throw new \UnexpectedValueException('Invalid response size for a tuple iterator.'); + throw new UnexpectedValueException('Invalid response size for a tuple iterator.'); } } /** - * {@inheritdoc} + * @return MultiBulk */ + #[ReturnTypeWillChange] public function getInnerIterator() { return $this->iterator; @@ -85,6 +90,6 @@ class MultiBulkTuple extends MultiBulk implements \OuterIterator $v = $this->iterator->current(); $this->iterator->next(); - return array($k, $v); + return [$k, $v]; } } diff --git a/plugins/cache-redis/Predis/Response/ResponseInterface.php b/plugins/cache-redis/Predis/Response/ResponseInterface.php index 0af135745..d2f682806 100644 --- a/plugins/cache-redis/Predis/Response/ResponseInterface.php +++ b/plugins/cache-redis/Predis/Response/ResponseInterface.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,8 +14,6 @@ namespace Predis\Response; /** * Represents a complex response object from Redis. - * - * @author Daniele Alessandri */ interface ResponseInterface { diff --git a/plugins/cache-redis/Predis/Response/ServerException.php b/plugins/cache-redis/Predis/Response/ServerException.php index 407dc5b76..305fe4091 100644 --- a/plugins/cache-redis/Predis/Response/ServerException.php +++ b/plugins/cache-redis/Predis/Response/ServerException.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -15,8 +16,6 @@ use Predis\PredisException; /** * Exception class that identifies server-side Redis errors. - * - * @author Daniele Alessandri */ class ServerException extends PredisException implements ErrorInterface { @@ -27,7 +26,7 @@ class ServerException extends PredisException implements ErrorInterface */ public function getErrorType() { - list($errorType) = explode(' ', $this->getMessage(), 2); + [$errorType] = explode(' ', $this->getMessage(), 2); return $errorType; } diff --git a/plugins/cache-redis/Predis/Response/Status.php b/plugins/cache-redis/Predis/Response/Status.php index 729bb6635..80cab9300 100644 --- a/plugins/cache-redis/Predis/Response/Status.php +++ b/plugins/cache-redis/Predis/Response/Status.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,8 +14,6 @@ namespace Predis\Response; /** * Represents a status response returned by Redis. - * - * @author Daniele Alessandri */ class Status implements ResponseInterface { @@ -59,7 +58,7 @@ class Status implements ResponseInterface * * @param string $payload Status response payload. * - * @return string + * @return self */ public static function get($payload) { diff --git a/plugins/cache-redis/Predis/Session/Handler.php b/plugins/cache-redis/Predis/Session/Handler.php index d7509c7af..68c87378d 100644 --- a/plugins/cache-redis/Predis/Session/Handler.php +++ b/plugins/cache-redis/Predis/Session/Handler.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -12,6 +13,8 @@ namespace Predis\Session; use Predis\ClientInterface; +use ReturnTypeWillChange; +use SessionHandlerInterface; /** * Session handler class that relies on Predis\Client to store PHP's sessions @@ -20,10 +23,8 @@ use Predis\ClientInterface; * This class is mostly intended for PHP 5.4 but it can be used under PHP 5.3 * provided that a polyfill for `SessionHandlerInterface` is defined by either * you or an external package such as `symfony/http-foundation`. - * - * @author Daniele Alessandri */ -class Handler implements \SessionHandlerInterface +class Handler implements SessionHandlerInterface { protected $client; protected $ttl; @@ -32,7 +33,7 @@ class Handler implements \SessionHandlerInterface * @param ClientInterface $client Fully initialized client instance. * @param array $options Session handler options. */ - public function __construct(ClientInterface $client, array $options = array()) + public function __construct(ClientInterface $client, array $options = []) { $this->client = $client; @@ -52,8 +53,11 @@ class Handler implements \SessionHandlerInterface } /** - * {@inheritdoc} + * @param string $save_path + * @param string $session_id + * @return bool */ + #[ReturnTypeWillChange] public function open($save_path, $session_id) { // NOOP @@ -61,8 +65,9 @@ class Handler implements \SessionHandlerInterface } /** - * {@inheritdoc} + * @return bool */ + #[ReturnTypeWillChange] public function close() { // NOOP @@ -70,8 +75,10 @@ class Handler implements \SessionHandlerInterface } /** - * {@inheritdoc} + * @param int $maxlifetime + * @return bool */ + #[ReturnTypeWillChange] public function gc($maxlifetime) { // NOOP @@ -79,8 +86,10 @@ class Handler implements \SessionHandlerInterface } /** - * {@inheritdoc} + * @param string $session_id + * @return string */ + #[ReturnTypeWillChange] public function read($session_id) { if ($data = $this->client->get($session_id)) { @@ -89,9 +98,13 @@ class Handler implements \SessionHandlerInterface return ''; } + /** - * {@inheritdoc} + * @param string $session_id + * @param string $session_data + * @return bool */ + #[ReturnTypeWillChange] public function write($session_id, $session_data) { $this->client->setex($session_id, $this->ttl, $session_data); @@ -100,8 +113,10 @@ class Handler implements \SessionHandlerInterface } /** - * {@inheritdoc} + * @param string $session_id + * @return bool */ + #[ReturnTypeWillChange] public function destroy($session_id) { $this->client->del($session_id); diff --git a/plugins/cache-redis/Predis/Transaction/AbortedMultiExecException.php b/plugins/cache-redis/Predis/Transaction/AbortedMultiExecException.php index b36f38aac..75fc0bb07 100644 --- a/plugins/cache-redis/Predis/Transaction/AbortedMultiExecException.php +++ b/plugins/cache-redis/Predis/Transaction/AbortedMultiExecException.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -15,8 +16,6 @@ use Predis\PredisException; /** * Exception class that identifies a MULTI / EXEC transaction aborted by Redis. - * - * @author Daniele Alessandri */ class AbortedMultiExecException extends PredisException { @@ -27,9 +26,10 @@ class AbortedMultiExecException extends PredisException * @param string $message Error message. * @param int $code Error code. */ - public function __construct(MultiExec $transaction, $message, $code = null) + public function __construct(MultiExec $transaction, $message, $code = 0) { - parent::__construct($message, $code); + parent::__construct($message, is_null($code) ? 0 : $code); + $this->transaction = $transaction; } diff --git a/plugins/cache-redis/Predis/Transaction/MultiExec.php b/plugins/cache-redis/Predis/Transaction/MultiExec.php index 0cf1962da..32ac1e123 100644 --- a/plugins/cache-redis/Predis/Transaction/MultiExec.php +++ b/plugins/cache-redis/Predis/Transaction/MultiExec.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -11,24 +12,29 @@ namespace Predis\Transaction; +use Exception; +use InvalidArgumentException; use Predis\ClientContextInterface; use Predis\ClientException; use Predis\ClientInterface; use Predis\Command\CommandInterface; use Predis\CommunicationException; -use Predis\Connection\AggregateConnectionInterface; +use Predis\Connection\Cluster\ClusterInterface; +use Predis\Connection\RelayConnection; use Predis\NotSupportedException; use Predis\Protocol\ProtocolException; +use Predis\Response\Error; use Predis\Response\ErrorInterface as ErrorResponseInterface; use Predis\Response\ServerException; use Predis\Response\Status as StatusResponse; +use Relay\Exception as RelayException; +use Relay\Relay; +use SplQueue; /** * Client-side abstraction of a Redis transaction based on MULTI / EXEC. * * {@inheritdoc} - * - * @author Daniele Alessandri */ class MultiExec implements ClientContextInterface { @@ -38,7 +44,7 @@ class MultiExec implements ClientContextInterface protected $commands; protected $exceptions = true; protected $attempts = 0; - protected $watchKeys = array(); + protected $watchKeys = []; protected $modeCAS = false; /** @@ -52,7 +58,7 @@ class MultiExec implements ClientContextInterface $this->client = $client; $this->state = new MultiExecState(); - $this->configure($client, $options ?: array()); + $this->configure($client, $options ?: []); $this->reset(); } @@ -66,15 +72,15 @@ class MultiExec implements ClientContextInterface */ private function assertClient(ClientInterface $client) { - if ($client->getConnection() instanceof AggregateConnectionInterface) { + if ($client->getConnection() instanceof ClusterInterface) { throw new NotSupportedException( - 'Cannot initialize a MULTI/EXEC transaction over aggregate connections.' + 'Cannot initialize a MULTI/EXEC transaction over cluster connections.' ); } - if (!$client->getProfile()->supportsCommands(array('MULTI', 'EXEC', 'DISCARD'))) { + if (!$client->getCommandFactory()->supports('MULTI', 'EXEC', 'DISCARD')) { throw new NotSupportedException( - 'The current profile does not support MULTI, EXEC and DISCARD.' + 'MULTI, EXEC and DISCARD are not supported by the current command factory.' ); } } @@ -112,7 +118,7 @@ class MultiExec implements ClientContextInterface protected function reset() { $this->state->reset(); - $this->commands = new \SplQueue(); + $this->commands = new SplQueue(); } /** @@ -168,15 +174,30 @@ class MultiExec implements ClientContextInterface * @param string $commandID Command ID. * @param array $arguments Arguments for the command. * - * @throws ServerException - * * @return mixed + * @throws ServerException */ - protected function call($commandID, array $arguments = array()) + protected function call($commandID, array $arguments = []) { - $response = $this->client->executeCommand( - $this->client->createCommand($commandID, $arguments) - ); + try { + $response = $this->client->executeCommand( + $this->client->createCommand($commandID, $arguments) + ); + } catch (ServerException $exception) { + if (!$this->client->getConnection() instanceof RelayConnection) { + throw $exception; + } + + if (strcasecmp($commandID, 'EXEC') != 0) { + throw $exception; + } + + if (!strpos($exception->getMessage(), 'RELAY_ERR_REDIS')) { + throw $exception; + } + + return null; + } if ($response instanceof ErrorResponseInterface) { throw new ServerException($response->getMessage()); @@ -190,10 +211,9 @@ class MultiExec implements ClientContextInterface * * @param CommandInterface $command Command instance. * + * @return $this|mixed * @throws AbortedMultiExecException * @throws CommunicationException - * - * @return $this|mixed */ public function executeCommand(CommandInterface $command) { @@ -207,6 +227,8 @@ class MultiExec implements ClientContextInterface if ($response instanceof StatusResponse && $response == 'QUEUED') { $this->commands->enqueue($command); + } elseif ($response instanceof Relay) { + $this->commands->enqueue($command); } elseif ($response instanceof ErrorResponseInterface) { throw new AbortedMultiExecException($this, $response->getMessage()); } else { @@ -221,22 +243,21 @@ class MultiExec implements ClientContextInterface * * @param string|array $keys One or more keys. * + * @return mixed * @throws NotSupportedException * @throws ClientException - * - * @return mixed */ public function watch($keys) { - if (!$this->client->getProfile()->supportsCommand('WATCH')) { - throw new NotSupportedException('WATCH is not supported by the current profile.'); + if (!$this->client->getCommandFactory()->supports('WATCH')) { + throw new NotSupportedException('WATCH is not supported by the current command factory.'); } if ($this->state->isWatchAllowed()) { throw new ClientException('Sending WATCH after MULTI is not allowed.'); } - $response = $this->call('WATCH', is_array($keys) ? $keys : array($keys)); + $response = $this->call('WATCH', is_array($keys) ? $keys : [$keys]); $this->state->flag(MultiExecState::WATCH); return $response; @@ -262,20 +283,19 @@ class MultiExec implements ClientContextInterface /** * Executes UNWATCH. * - * @throws NotSupportedException - * * @return MultiExec + * @throws NotSupportedException */ public function unwatch() { - if (!$this->client->getProfile()->supportsCommand('UNWATCH')) { + if (!$this->client->getCommandFactory()->supports('UNWATCH')) { throw new NotSupportedException( - 'UNWATCH is not supported by the current profile.' + 'UNWATCH is not supported by the current command factory.' ); } $this->state->unflag(MultiExecState::WATCH); - $this->__call('UNWATCH', array()); + $this->__call('UNWATCH', []); return $this; } @@ -313,7 +333,7 @@ class MultiExec implements ClientContextInterface * * @param mixed $callable Callback for execution. * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @throws ClientException */ private function checkBeforeExecution($callable) @@ -326,7 +346,7 @@ class MultiExec implements ClientContextInterface if ($callable) { if (!is_callable($callable)) { - throw new \InvalidArgumentException('The argument must be a callable object.'); + throw new InvalidArgumentException('The argument must be a callable object.'); } if (!$this->commands->isEmpty()) { @@ -350,11 +370,10 @@ class MultiExec implements ClientContextInterface * * @param mixed $callable Optional callback for execution. * + * @return array * @throws CommunicationException * @throws AbortedMultiExecException * @throws ServerException - * - * @return array */ public function execute($callable = null) { @@ -378,7 +397,9 @@ class MultiExec implements ClientContextInterface $execResponse = $this->call('EXEC'); - if ($execResponse === null) { + // The additional `false` check is needed for Relay, + // let's hope it won't break anything + if ($execResponse === null || $execResponse === false) { if ($attempts === 0) { throw new AbortedMultiExecException( $this, 'The current transaction has been aborted by the server.' @@ -393,7 +414,7 @@ class MultiExec implements ClientContextInterface break; } while ($attempts-- > 0); - $response = array(); + $response = []; $commands = $this->commands; $size = count($execResponse); @@ -404,10 +425,20 @@ class MultiExec implements ClientContextInterface for ($i = 0; $i < $size; ++$i) { $cmdResponse = $execResponse[$i]; - if ($cmdResponse instanceof ErrorResponseInterface && $this->exceptions) { + if ($this->exceptions && $cmdResponse instanceof ErrorResponseInterface) { throw new ServerException($cmdResponse->getMessage()); } + if ($cmdResponse instanceof RelayException) { + if ($this->exceptions) { + throw new ServerException($cmdResponse->getMessage(), $cmdResponse->getCode(), $cmdResponse); + } + + $commands->dequeue(); + $response[$i] = new Error($cmdResponse->getMessage()); + continue; + } + $response[$i] = $commands->dequeue()->parseResponse($cmdResponse); } @@ -433,7 +464,7 @@ class MultiExec implements ClientContextInterface // NOOP } catch (ServerException $exception) { // NOOP - } catch (\Exception $exception) { + } catch (Exception $exception) { $this->discard(); } diff --git a/plugins/cache-redis/Predis/Transaction/MultiExecState.php b/plugins/cache-redis/Predis/Transaction/MultiExecState.php index a0a828529..c9be15c87 100644 --- a/plugins/cache-redis/Predis/Transaction/MultiExecState.php +++ b/plugins/cache-redis/Predis/Transaction/MultiExecState.php @@ -3,7 +3,8 @@ /* * This file is part of the Predis package. * - * (c) Daniele Alessandri + * (c) 2009-2020 Daniele Alessandri + * (c) 2021-2023 Till Krüss * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -13,22 +14,17 @@ namespace Predis\Transaction; /** * Utility class used to track the state of a MULTI / EXEC transaction. - * - * @author Daniele Alessandri */ class MultiExecState { - const INITIALIZED = 1; // 0b00001 - const INSIDEBLOCK = 2; // 0b00010 - const DISCARDED = 4; // 0b00100 - const CAS = 8; // 0b01000 - const WATCH = 16; // 0b10000 + public const INITIALIZED = 1; // 0b00001 + public const INSIDEBLOCK = 2; // 0b00010 + public const DISCARDED = 4; // 0b00100 + public const CAS = 8; // 0b01000 + public const WATCH = 16; // 0b10000 private $flags; - /** - * - */ public function __construct() { $this->flags = 0;