Edit File by line
/home/barbar84/www/wp-conte.../plugins/nginx-he.../admin
File: predis.php
<?php // phpcs:disable
[0] Fix | Delete
[1] Fix | Delete
/*
[2] Fix | Delete
* This file is part of the Predis package.
[3] Fix | Delete
*
[4] Fix | Delete
* (c) Daniele Alessandri <suppakilla@gmail.com>
[5] Fix | Delete
*
[6] Fix | Delete
* For the full copyright and license information, please view the LICENSE
[7] Fix | Delete
* file that was distributed with this source code.
[8] Fix | Delete
*/
[9] Fix | Delete
[10] Fix | Delete
namespace Predis\Command;
[11] Fix | Delete
[12] Fix | Delete
use InvalidArgumentException;
[13] Fix | Delete
[14] Fix | Delete
/**
[15] Fix | Delete
* Defines an abstraction representing a Redis command.
[16] Fix | Delete
*
[17] Fix | Delete
* @author Daniele Alessandri <suppakilla@gmail.com>
[18] Fix | Delete
*/
[19] Fix | Delete
interface CommandInterface
[20] Fix | Delete
{
[21] Fix | Delete
/**
[22] Fix | Delete
* Returns the ID of the Redis command. By convention, command identifiers
[23] Fix | Delete
* must always be uppercase.
[24] Fix | Delete
*
[25] Fix | Delete
* @return string
[26] Fix | Delete
*/
[27] Fix | Delete
public function getId();
[28] Fix | Delete
[29] Fix | Delete
/**
[30] Fix | Delete
* Assign the specified slot to the command for clustering distribution.
[31] Fix | Delete
*
[32] Fix | Delete
* @param int $slot Slot ID.
[33] Fix | Delete
*/
[34] Fix | Delete
public function setSlot($slot);
[35] Fix | Delete
[36] Fix | Delete
/**
[37] Fix | Delete
* Returns the assigned slot of the command for clustering distribution.
[38] Fix | Delete
*
[39] Fix | Delete
* @return int|null
[40] Fix | Delete
*/
[41] Fix | Delete
public function getSlot();
[42] Fix | Delete
[43] Fix | Delete
/**
[44] Fix | Delete
* Sets the arguments for the command.
[45] Fix | Delete
*
[46] Fix | Delete
* @param array $arguments List of arguments.
[47] Fix | Delete
*/
[48] Fix | Delete
public function setArguments(array $arguments);
[49] Fix | Delete
[50] Fix | Delete
/**
[51] Fix | Delete
* Sets the raw arguments for the command without processing them.
[52] Fix | Delete
*
[53] Fix | Delete
* @param array $arguments List of arguments.
[54] Fix | Delete
*/
[55] Fix | Delete
public function setRawArguments(array $arguments);
[56] Fix | Delete
[57] Fix | Delete
/**
[58] Fix | Delete
* Gets the arguments of the command.
[59] Fix | Delete
*
[60] Fix | Delete
* @return array
[61] Fix | Delete
*/
[62] Fix | Delete
public function getArguments();
[63] Fix | Delete
[64] Fix | Delete
/**
[65] Fix | Delete
* Gets the argument of the command at the specified index.
[66] Fix | Delete
*
[67] Fix | Delete
* @param int $index Index of the desired argument.
[68] Fix | Delete
*
[69] Fix | Delete
* @return mixed|null
[70] Fix | Delete
*/
[71] Fix | Delete
public function getArgument($index);
[72] Fix | Delete
[73] Fix | Delete
/**
[74] Fix | Delete
* Parses a raw response and returns a PHP object.
[75] Fix | Delete
*
[76] Fix | Delete
* @param string $data Binary string containing the whole response.
[77] Fix | Delete
*
[78] Fix | Delete
* @return mixed
[79] Fix | Delete
*/
[80] Fix | Delete
public function parseResponse($data);
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
/**
[84] Fix | Delete
* Base class for Redis commands.
[85] Fix | Delete
*
[86] Fix | Delete
* @author Daniele Alessandri <suppakilla@gmail.com>
[87] Fix | Delete
*/
[88] Fix | Delete
abstract class Command implements CommandInterface
[89] Fix | Delete
{
[90] Fix | Delete
private $slot;
[91] Fix | Delete
private $arguments = array();
[92] Fix | Delete
[93] Fix | Delete
/**
[94] Fix | Delete
* Returns a filtered array of the arguments.
[95] Fix | Delete
*
[96] Fix | Delete
* @param array $arguments List of arguments.
[97] Fix | Delete
*
[98] Fix | Delete
* @return array
[99] Fix | Delete
*/
[100] Fix | Delete
protected function filterArguments(array $arguments)
[101] Fix | Delete
{
[102] Fix | Delete
return $arguments;
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
/**
[106] Fix | Delete
* {@inheritdoc}
[107] Fix | Delete
*/
[108] Fix | Delete
public function setArguments(array $arguments)
[109] Fix | Delete
{
[110] Fix | Delete
$this->arguments = $this->filterArguments($arguments);
[111] Fix | Delete
unset($this->slot);
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
/**
[115] Fix | Delete
* {@inheritdoc}
[116] Fix | Delete
*/
[117] Fix | Delete
public function setRawArguments(array $arguments)
[118] Fix | Delete
{
[119] Fix | Delete
$this->arguments = $arguments;
[120] Fix | Delete
unset($this->slot);
[121] Fix | Delete
}
[122] Fix | Delete
[123] Fix | Delete
/**
[124] Fix | Delete
* {@inheritdoc}
[125] Fix | Delete
*/
[126] Fix | Delete
public function getArguments()
[127] Fix | Delete
{
[128] Fix | Delete
return $this->arguments;
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
/**
[132] Fix | Delete
* {@inheritdoc}
[133] Fix | Delete
*/
[134] Fix | Delete
public function getArgument($index)
[135] Fix | Delete
{
[136] Fix | Delete
if (isset($this->arguments[$index])) {
[137] Fix | Delete
return $this->arguments[$index];
[138] Fix | Delete
}
[139] Fix | Delete
}
[140] Fix | Delete
[141] Fix | Delete
/**
[142] Fix | Delete
* {@inheritdoc}
[143] Fix | Delete
*/
[144] Fix | Delete
public function setSlot($slot)
[145] Fix | Delete
{
[146] Fix | Delete
$this->slot = $slot;
[147] Fix | Delete
}
[148] Fix | Delete
[149] Fix | Delete
/**
[150] Fix | Delete
* {@inheritdoc}
[151] Fix | Delete
*/
[152] Fix | Delete
public function getSlot()
[153] Fix | Delete
{
[154] Fix | Delete
if (isset($this->slot)) {
[155] Fix | Delete
return $this->slot;
[156] Fix | Delete
}
[157] Fix | Delete
}
[158] Fix | Delete
[159] Fix | Delete
/**
[160] Fix | Delete
* {@inheritdoc}
[161] Fix | Delete
*/
[162] Fix | Delete
public function parseResponse($data)
[163] Fix | Delete
{
[164] Fix | Delete
return $data;
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
/**
[168] Fix | Delete
* Normalizes the arguments array passed to a Redis command.
[169] Fix | Delete
*
[170] Fix | Delete
* @param array $arguments Arguments for a command.
[171] Fix | Delete
*
[172] Fix | Delete
* @return array
[173] Fix | Delete
*/
[174] Fix | Delete
public static function normalizeArguments(array $arguments)
[175] Fix | Delete
{
[176] Fix | Delete
if (count($arguments) === 1 && is_array($arguments[0])) {
[177] Fix | Delete
return $arguments[0];
[178] Fix | Delete
}
[179] Fix | Delete
[180] Fix | Delete
return $arguments;
[181] Fix | Delete
}
[182] Fix | Delete
[183] Fix | Delete
/**
[184] Fix | Delete
* Normalizes the arguments array passed to a variadic Redis command.
[185] Fix | Delete
*
[186] Fix | Delete
* @param array $arguments Arguments for a command.
[187] Fix | Delete
*
[188] Fix | Delete
* @return array
[189] Fix | Delete
*/
[190] Fix | Delete
public static function normalizeVariadic(array $arguments)
[191] Fix | Delete
{
[192] Fix | Delete
if (count($arguments) === 2 && is_array($arguments[1])) {
[193] Fix | Delete
return array_merge(array($arguments[0]), $arguments[1]);
[194] Fix | Delete
}
[195] Fix | Delete
[196] Fix | Delete
return $arguments;
[197] Fix | Delete
}
[198] Fix | Delete
}
[199] Fix | Delete
[200] Fix | Delete
/**
[201] Fix | Delete
* @link http://redis.io/commands/zrange
[202] Fix | Delete
* @author Daniele Alessandri <suppakilla@gmail.com>
[203] Fix | Delete
*/
[204] Fix | Delete
class ZSetRange extends Command
[205] Fix | Delete
{
[206] Fix | Delete
/**
[207] Fix | Delete
* {@inheritdoc}
[208] Fix | Delete
*/
[209] Fix | Delete
public function getId()
[210] Fix | Delete
{
[211] Fix | Delete
return 'ZRANGE';
[212] Fix | Delete
}
[213] Fix | Delete
[214] Fix | Delete
/**
[215] Fix | Delete
* {@inheritdoc}
[216] Fix | Delete
*/
[217] Fix | Delete
protected function filterArguments(array $arguments)
[218] Fix | Delete
{
[219] Fix | Delete
if (count($arguments) === 4) {
[220] Fix | Delete
$lastType = gettype($arguments[3]);
[221] Fix | Delete
[222] Fix | Delete
if ($lastType === 'string' && strtoupper($arguments[3]) === 'WITHSCORES') {
[223] Fix | Delete
// Used for compatibility with older versions
[224] Fix | Delete
$arguments[3] = array('WITHSCORES' => true);
[225] Fix | Delete
$lastType = 'array';
[226] Fix | Delete
}
[227] Fix | Delete
[228] Fix | Delete
if ($lastType === 'array') {
[229] Fix | Delete
$options = $this->prepareOptions(array_pop($arguments));
[230] Fix | Delete
[231] Fix | Delete
return array_merge($arguments, $options);
[232] Fix | Delete
}
[233] Fix | Delete
}
[234] Fix | Delete
[235] Fix | Delete
return $arguments;
[236] Fix | Delete
}
[237] Fix | Delete
[238] Fix | Delete
/**
[239] Fix | Delete
* Returns a list of options and modifiers compatible with Redis.
[240] Fix | Delete
*
[241] Fix | Delete
* @param array $options List of options.
[242] Fix | Delete
*
[243] Fix | Delete
* @return array
[244] Fix | Delete
*/
[245] Fix | Delete
protected function prepareOptions($options)
[246] Fix | Delete
{
[247] Fix | Delete
$opts = array_change_key_case($options, CASE_UPPER);
[248] Fix | Delete
$finalizedOpts = array();
[249] Fix | Delete
[250] Fix | Delete
if (!empty($opts['WITHSCORES'])) {
[251] Fix | Delete
$finalizedOpts[] = 'WITHSCORES';
[252] Fix | Delete
}
[253] Fix | Delete
[254] Fix | Delete
return $finalizedOpts;
[255] Fix | Delete
}
[256] Fix | Delete
[257] Fix | Delete
/**
[258] Fix | Delete
* Checks for the presence of the WITHSCORES modifier.
[259] Fix | Delete
*
[260] Fix | Delete
* @return bool
[261] Fix | Delete
*/
[262] Fix | Delete
protected function withScores()
[263] Fix | Delete
{
[264] Fix | Delete
$arguments = $this->getArguments();
[265] Fix | Delete
[266] Fix | Delete
if (count($arguments) < 4) {
[267] Fix | Delete
return false;
[268] Fix | Delete
}
[269] Fix | Delete
[270] Fix | Delete
return strtoupper($arguments[3]) === 'WITHSCORES';
[271] Fix | Delete
}
[272] Fix | Delete
[273] Fix | Delete
/**
[274] Fix | Delete
* {@inheritdoc}
[275] Fix | Delete
*/
[276] Fix | Delete
public function parseResponse($data)
[277] Fix | Delete
{
[278] Fix | Delete
if ($this->withScores()) {
[279] Fix | Delete
$result = array();
[280] Fix | Delete
[281] Fix | Delete
for ($i = 0; $i < count($data); $i++) {
[282] Fix | Delete
$result[$data[$i]] = $data[++$i];
[283] Fix | Delete
}
[284] Fix | Delete
[285] Fix | Delete
return $result;
[286] Fix | Delete
}
[287] Fix | Delete
[288] Fix | Delete
return $data;
[289] Fix | Delete
}
[290] Fix | Delete
}
[291] Fix | Delete
[292] Fix | Delete
/**
[293] Fix | Delete
* @link http://redis.io/commands/sinterstore
[294] Fix | Delete
* @author Daniele Alessandri <suppakilla@gmail.com>
[295] Fix | Delete
*/
[296] Fix | Delete
class SetIntersectionStore extends Command
[297] Fix | Delete
{
[298] Fix | Delete
/**
[299] Fix | Delete
* {@inheritdoc}
[300] Fix | Delete
*/
[301] Fix | Delete
public function getId()
[302] Fix | Delete
{
[303] Fix | Delete
return 'SINTERSTORE';
[304] Fix | Delete
}
[305] Fix | Delete
[306] Fix | Delete
/**
[307] Fix | Delete
* {@inheritdoc}
[308] Fix | Delete
*/
[309] Fix | Delete
protected function filterArguments(array $arguments)
[310] Fix | Delete
{
[311] Fix | Delete
if (count($arguments) === 2 && is_array($arguments[1])) {
[312] Fix | Delete
return array_merge(array($arguments[0]), $arguments[1]);
[313] Fix | Delete
}
[314] Fix | Delete
[315] Fix | Delete
return $arguments;
[316] Fix | Delete
}
[317] Fix | Delete
}
[318] Fix | Delete
[319] Fix | Delete
/**
[320] Fix | Delete
* @link http://redis.io/commands/sinter
[321] Fix | Delete
* @author Daniele Alessandri <suppakilla@gmail.com>
[322] Fix | Delete
*/
[323] Fix | Delete
class SetIntersection extends Command
[324] Fix | Delete
{
[325] Fix | Delete
/**
[326] Fix | Delete
* {@inheritdoc}
[327] Fix | Delete
*/
[328] Fix | Delete
public function getId()
[329] Fix | Delete
{
[330] Fix | Delete
return 'SINTER';
[331] Fix | Delete
}
[332] Fix | Delete
[333] Fix | Delete
/**
[334] Fix | Delete
* {@inheritdoc}
[335] Fix | Delete
*/
[336] Fix | Delete
protected function filterArguments(array $arguments)
[337] Fix | Delete
{
[338] Fix | Delete
return self::normalizeArguments($arguments);
[339] Fix | Delete
}
[340] Fix | Delete
}
[341] Fix | Delete
[342] Fix | Delete
/**
[343] Fix | Delete
* @link http://redis.io/commands/eval
[344] Fix | Delete
* @author Daniele Alessandri <suppakilla@gmail.com>
[345] Fix | Delete
*/
[346] Fix | Delete
class ServerEval extends Command
[347] Fix | Delete
{
[348] Fix | Delete
/**
[349] Fix | Delete
* {@inheritdoc}
[350] Fix | Delete
*/
[351] Fix | Delete
public function getId()
[352] Fix | Delete
{
[353] Fix | Delete
return 'EVAL';
[354] Fix | Delete
}
[355] Fix | Delete
[356] Fix | Delete
/**
[357] Fix | Delete
* Calculates the SHA1 hash of the body of the script.
[358] Fix | Delete
*
[359] Fix | Delete
* @return string SHA1 hash.
[360] Fix | Delete
*/
[361] Fix | Delete
public function getScriptHash()
[362] Fix | Delete
{
[363] Fix | Delete
return sha1($this->getArgument(0));
[364] Fix | Delete
}
[365] Fix | Delete
}
[366] Fix | Delete
[367] Fix | Delete
/**
[368] Fix | Delete
* @link http://redis.io/commands/rename
[369] Fix | Delete
* @author Daniele Alessandri <suppakilla@gmail.com>
[370] Fix | Delete
*/
[371] Fix | Delete
class KeyRename extends Command
[372] Fix | Delete
{
[373] Fix | Delete
/**
[374] Fix | Delete
* {@inheritdoc}
[375] Fix | Delete
*/
[376] Fix | Delete
public function getId()
[377] Fix | Delete
{
[378] Fix | Delete
return 'RENAME';
[379] Fix | Delete
}
[380] Fix | Delete
}
[381] Fix | Delete
[382] Fix | Delete
/**
[383] Fix | Delete
* @link http://redis.io/commands/setex
[384] Fix | Delete
* @author Daniele Alessandri <suppakilla@gmail.com>
[385] Fix | Delete
*/
[386] Fix | Delete
class StringSetExpire extends Command
[387] Fix | Delete
{
[388] Fix | Delete
/**
[389] Fix | Delete
* {@inheritdoc}
[390] Fix | Delete
*/
[391] Fix | Delete
public function getId()
[392] Fix | Delete
{
[393] Fix | Delete
return 'SETEX';
[394] Fix | Delete
}
[395] Fix | Delete
}
[396] Fix | Delete
[397] Fix | Delete
/**
[398] Fix | Delete
* @link http://redis.io/commands/mset
[399] Fix | Delete
* @author Daniele Alessandri <suppakilla@gmail.com>
[400] Fix | Delete
*/
[401] Fix | Delete
class StringSetMultiple extends Command
[402] Fix | Delete
{
[403] Fix | Delete
/**
[404] Fix | Delete
* {@inheritdoc}
[405] Fix | Delete
*/
[406] Fix | Delete
public function getId()
[407] Fix | Delete
{
[408] Fix | Delete
return 'MSET';
[409] Fix | Delete
}
[410] Fix | Delete
[411] Fix | Delete
/**
[412] Fix | Delete
* {@inheritdoc}
[413] Fix | Delete
*/
[414] Fix | Delete
protected function filterArguments(array $arguments)
[415] Fix | Delete
{
[416] Fix | Delete
if (count($arguments) === 1 && is_array($arguments[0])) {
[417] Fix | Delete
$flattenedKVs = array();
[418] Fix | Delete
$args = $arguments[0];
[419] Fix | Delete
[420] Fix | Delete
foreach ($args as $k => $v) {
[421] Fix | Delete
$flattenedKVs[] = $k;
[422] Fix | Delete
$flattenedKVs[] = $v;
[423] Fix | Delete
}
[424] Fix | Delete
[425] Fix | Delete
return $flattenedKVs;
[426] Fix | Delete
}
[427] Fix | Delete
[428] Fix | Delete
return $arguments;
[429] Fix | Delete
}
[430] Fix | Delete
}
[431] Fix | Delete
[432] Fix | Delete
/**
[433] Fix | Delete
* @link http://redis.io/commands/expireat
[434] Fix | Delete
* @author Daniele Alessandri <suppakilla@gmail.com>
[435] Fix | Delete
*/
[436] Fix | Delete
class KeyExpireAt extends Command
[437] Fix | Delete
{
[438] Fix | Delete
/**
[439] Fix | Delete
* {@inheritdoc}
[440] Fix | Delete
*/
[441] Fix | Delete
public function getId()
[442] Fix | Delete
{
[443] Fix | Delete
return 'EXPIREAT';
[444] Fix | Delete
}
[445] Fix | Delete
[446] Fix | Delete
/**
[447] Fix | Delete
* {@inheritdoc}
[448] Fix | Delete
*/
[449] Fix | Delete
public function parseResponse($data)
[450] Fix | Delete
{
[451] Fix | Delete
return (bool) $data;
[452] Fix | Delete
}
[453] Fix | Delete
}
[454] Fix | Delete
[455] Fix | Delete
/**
[456] Fix | Delete
* @link http://redis.io/commands/blpop
[457] Fix | Delete
* @author Daniele Alessandri <suppakilla@gmail.com>
[458] Fix | Delete
*/
[459] Fix | Delete
class ListPopFirstBlocking extends Command
[460] Fix | Delete
{
[461] Fix | Delete
/**
[462] Fix | Delete
* {@inheritdoc}
[463] Fix | Delete
*/
[464] Fix | Delete
public function getId()
[465] Fix | Delete
{
[466] Fix | Delete
return 'BLPOP';
[467] Fix | Delete
}
[468] Fix | Delete
[469] Fix | Delete
/**
[470] Fix | Delete
* {@inheritdoc}
[471] Fix | Delete
*/
[472] Fix | Delete
protected function filterArguments(array $arguments)
[473] Fix | Delete
{
[474] Fix | Delete
if (count($arguments) === 2 && is_array($arguments[0])) {
[475] Fix | Delete
list($arguments, $timeout) = $arguments;
[476] Fix | Delete
array_push($arguments, $timeout);
[477] Fix | Delete
}
[478] Fix | Delete
[479] Fix | Delete
return $arguments;
[480] Fix | Delete
}
[481] Fix | Delete
}
[482] Fix | Delete
[483] Fix | Delete
/**
[484] Fix | Delete
* @link http://redis.io/commands/unsubscribe
[485] Fix | Delete
* @author Daniele Alessandri <suppakilla@gmail.com>
[486] Fix | Delete
*/
[487] Fix | Delete
class PubSubUnsubscribe extends Command
[488] Fix | Delete
{
[489] Fix | Delete
/**
[490] Fix | Delete
* {@inheritdoc}
[491] Fix | Delete
*/
[492] Fix | Delete
public function getId()
[493] Fix | Delete
{
[494] Fix | Delete
return 'UNSUBSCRIBE';
[495] Fix | Delete
}
[496] Fix | Delete
[497] Fix | Delete
/**
[498] Fix | Delete
* {@inheritdoc}
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function