From 6ceadb06e210c3602e895770b0fa01792abf75bc Mon Sep 17 00:00:00 2001 From: Auke Terpstra Date: Wed, 4 Oct 2017 14:25:17 +0200 Subject: [PATCH 1/3] Revert the array constant, use the private static array again. This does not break the PHP 5.4 and 5.5 compatibility --- Cluster.php | 113 ++++++++++++++++++++++++++-------------------------- 1 file changed, 56 insertions(+), 57 deletions(-) diff --git a/Cluster.php b/Cluster.php index 827e1eb..970ef49 100644 --- a/Cluster.php +++ b/Cluster.php @@ -276,65 +276,64 @@ public function hash($key) return $this->ring[$server]; } - const readOnlyCommands = array( - 'DBSIZE' => true, - 'INFO' => true, - 'MONITOR' => true, - 'EXISTS' => true, - 'TYPE' => true, - 'KEYS' => true, - 'SCAN' => true, - 'RANDOMKEY' => true, - 'TTL' => true, - 'GET' => true, - 'MGET' => true, - 'SUBSTR' => true, - 'STRLEN' => true, - 'GETRANGE' => true, - 'GETBIT' => true, - 'LLEN' => true, - 'LRANGE' => true, - 'LINDEX' => true, - 'SCARD' => true, - 'SISMEMBER' => true, - 'SINTER' => true, - 'SUNION' => true, - 'SDIFF' => true, - 'SMEMBERS' => true, - 'SSCAN' => true, - 'SRANDMEMBER' => true, - 'ZRANGE' => true, - 'ZREVRANGE' => true, - 'ZRANGEBYSCORE' => true, - 'ZREVRANGEBYSCORE' => true, - 'ZCARD' => true, - 'ZSCORE' => true, - 'ZCOUNT' => true, - 'ZRANK' => true, - 'ZREVRANK' => true, - 'ZSCAN' => true, - 'HGET' => true, - 'HMGET' => true, - 'HEXISTS' => true, - 'HLEN' => true, - 'HKEYS' => true, - 'HVALS' => true, - 'HGETALL' => true, - 'HSCAN' => true, - 'PING' => true, - 'AUTH' => true, - 'SELECT' => true, - 'ECHO' => true, - 'QUIT' => true, - 'OBJECT' => true, - 'BITCOUNT' => true, - 'TIME' => true, - 'SORT' => true, - ); - public function isReadOnlyCommand($command) { - return array_key_exists(strtoupper($command), static::readOnlyCommands); + $readOnlyCommands = array( + 'DBSIZE', + 'INFO', + 'MONITOR', + 'EXISTS', + 'TYPE', + 'KEYS', + 'SCAN', + 'RANDOMKEY', + 'TTL', + 'GET', + 'MGET', + 'SUBSTR', + 'STRLEN', + 'GETRANGE', + 'GETBIT', + 'LLEN', + 'LRANGE', + 'LINDEX', + 'SCARD', + 'SISMEMBER', + 'SINTER', + 'SUNION', + 'SDIFF', + 'SMEMBERS', + 'SSCAN', + 'SRANDMEMBER', + 'ZRANGE', + 'ZREVRANGE', + 'ZRANGEBYSCORE', + 'ZREVRANGEBYSCORE', + 'ZCARD', + 'ZSCORE', + 'ZCOUNT', + 'ZRANK', + 'ZREVRANK', + 'ZSCAN', + 'HGET', + 'HMGET', + 'HEXISTS', + 'HLEN', + 'HKEYS', + 'HVALS', + 'HGETALL', + 'HSCAN', + 'PING', + 'AUTH', + 'SELECT', + 'ECHO', + 'QUIT', + 'OBJECT', + 'BITCOUNT', + 'TIME', + 'SORT' + ); + return in_array(strtoupper($command),$readOnlyCommands); } } From 9fac39590ba0f509b3b1ab7daab637afaa9f5cbf Mon Sep 17 00:00:00 2001 From: Auke Terpstra Date: Thu, 5 Oct 2017 08:06:38 +0200 Subject: [PATCH 2/3] Use array_key_exists() insteadof in_array() --- Cluster.php | 108 ++++++++++++++++++++++++++-------------------------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/Cluster.php b/Cluster.php index 970ef49..cf0ebe0 100644 --- a/Cluster.php +++ b/Cluster.php @@ -279,61 +279,61 @@ public function hash($key) public function isReadOnlyCommand($command) { $readOnlyCommands = array( - 'DBSIZE', - 'INFO', - 'MONITOR', - 'EXISTS', - 'TYPE', - 'KEYS', - 'SCAN', - 'RANDOMKEY', - 'TTL', - 'GET', - 'MGET', - 'SUBSTR', - 'STRLEN', - 'GETRANGE', - 'GETBIT', - 'LLEN', - 'LRANGE', - 'LINDEX', - 'SCARD', - 'SISMEMBER', - 'SINTER', - 'SUNION', - 'SDIFF', - 'SMEMBERS', - 'SSCAN', - 'SRANDMEMBER', - 'ZRANGE', - 'ZREVRANGE', - 'ZRANGEBYSCORE', - 'ZREVRANGEBYSCORE', - 'ZCARD', - 'ZSCORE', - 'ZCOUNT', - 'ZRANK', - 'ZREVRANK', - 'ZSCAN', - 'HGET', - 'HMGET', - 'HEXISTS', - 'HLEN', - 'HKEYS', - 'HVALS', - 'HGETALL', - 'HSCAN', - 'PING', - 'AUTH', - 'SELECT', - 'ECHO', - 'QUIT', - 'OBJECT', - 'BITCOUNT', - 'TIME', - 'SORT' + 'DBSIZE' => true, + 'INFO' => true, + 'MONITOR' => true, + 'EXISTS' => true, + 'TYPE' => true, + 'KEYS' => true, + 'SCAN' => true, + 'RANDOMKEY' => true, + 'TTL' => true, + 'GET' => true, + 'MGET' => true, + 'SUBSTR' => true, + 'STRLEN' => true, + 'GETRANGE' => true, + 'GETBIT' => true, + 'LLEN' => true, + 'LRANGE' => true, + 'LINDEX' => true, + 'SCARD' => true, + 'SISMEMBER' => true, + 'SINTER' => true, + 'SUNION' => true, + 'SDIFF' => true, + 'SMEMBERS' => true, + 'SSCAN' => true, + 'SRANDMEMBER' => true, + 'ZRANGE' => true, + 'ZREVRANGE' => true, + 'ZRANGEBYSCORE' => true, + 'ZREVRANGEBYSCORE' => true, + 'ZCARD' => true, + 'ZSCORE' => true, + 'ZCOUNT' => true, + 'ZRANK' => true, + 'ZREVRANK' => true, + 'ZSCAN' => true, + 'HGET' => true, + 'HMGET' => true, + 'HEXISTS' => true, + 'HLEN' => true, + 'HKEYS' => true, + 'HVALS' => true, + 'HGETALL' => true, + 'HSCAN' => true, + 'PING' => true, + 'AUTH' => true, + 'SELECT' => true, + 'ECHO' => true, + 'QUIT' => true, + 'OBJECT' => true, + 'BITCOUNT' => true, + 'TIME' => true, + 'SORT' => true, ); - return in_array(strtoupper($command),$readOnlyCommands); + return array_key_exists(strtoupper($command), $readOnlyCommands); } } From 4484f4c1b76bc448ce72dbf9a49df70f381c9eb1 Mon Sep 17 00:00:00 2001 From: Colin Mollenhour Date: Thu, 5 Oct 2017 15:26:26 -0400 Subject: [PATCH 3/3] Use static for $readOnlyCommands variable. --- Cluster.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cluster.php b/Cluster.php index cf0ebe0..24cb534 100644 --- a/Cluster.php +++ b/Cluster.php @@ -278,7 +278,7 @@ public function hash($key) public function isReadOnlyCommand($command) { - $readOnlyCommands = array( + static $readOnlyCommands = array( 'DBSIZE' => true, 'INFO' => true, 'MONITOR' => true,