├── .gitignore ├── README.md ├── composer.json ├── phpunit.php ├── src ├── Client.php ├── ClusterClient.php ├── ClusterConfig.php ├── CommandConst.php ├── CommandHandle │ ├── AbstractCommandHandle.php │ ├── AppEnd.php │ ├── Auth.php │ ├── BLPop.php │ ├── BRPop.php │ ├── BRPopLPush.php │ ├── BZPopMax.php │ ├── BZPopMin.php │ ├── BgRewriteAof.php │ ├── BgSave.php │ ├── BitCount.php │ ├── BitField.php │ ├── BitOp.php │ ├── BitPos.php │ ├── ClientGetName.php │ ├── ClientKill.php │ ├── ClientList.php │ ├── ClientPause.php │ ├── ClientSetName.php │ ├── ClusterCommand │ │ ├── ClusterAddSlots.php │ │ ├── ClusterCountFailureReports.php │ │ ├── ClusterCountKeySinSlot.php │ │ ├── ClusterDelSlots.php │ │ ├── ClusterFailOver.php │ │ ├── ClusterForget.php │ │ ├── ClusterGetKeySinSlot.php │ │ ├── ClusterInfo.php │ │ ├── ClusterKeySlot.php │ │ ├── ClusterMeet.php │ │ ├── ClusterNodes.php │ │ ├── ClusterReplicate.php │ │ ├── ClusterReset.php │ │ ├── ClusterSaveConfig.php │ │ ├── ClusterSetConfigEpoch.php │ │ ├── ClusterSetSlot.php │ │ ├── ClusterSlaves.php │ │ ├── ClusterSlots.php │ │ ├── Readonly.php │ │ └── Readwrite.php │ ├── Command.php │ ├── CommandCount.php │ ├── CommandGetKeys.php │ ├── CommandInfo.php │ ├── ConfigGet.php │ ├── ConfigResetStat.php │ ├── ConfigRewrite.php │ ├── ConfigSet.php │ ├── Construct.php │ ├── DBSize.php │ ├── DebugObject.php │ ├── DebugSegfault.php │ ├── Decr.php │ ├── DecrBy.php │ ├── Del.php │ ├── Discard.php │ ├── DiscardPipe.php │ ├── Dump.php │ ├── Exec.php │ ├── ExecPipe.php │ ├── Exists.php │ ├── Expire.php │ ├── ExpireAt.php │ ├── FlushAll.php │ ├── FlushDb.php │ ├── GeoAdd.php │ ├── GeoDist.php │ ├── GeoHash.php │ ├── GeoPos.php │ ├── GeoRadius.php │ ├── GeoRadiusByMember.php │ ├── Get.php │ ├── GetBit.php │ ├── GetRange.php │ ├── GetSet.php │ ├── HDel.php │ ├── HExists.php │ ├── HGet.php │ ├── HGetAll.php │ ├── HIncrBy.php │ ├── HIncrByFloat.php │ ├── HKeys.php │ ├── HLen.php │ ├── HMGet.php │ ├── HMSet.php │ ├── HScan.php │ ├── HSet.php │ ├── HSetNx.php │ ├── HValS.php │ ├── Incr.php │ ├── IncrBy.php │ ├── IncrByFloat.php │ ├── Info.php │ ├── Keys.php │ ├── LIndex.php │ ├── LInsert.php │ ├── LLen.php │ ├── LPop.php │ ├── LPuShx.php │ ├── LPush.php │ ├── LRange.php │ ├── LRem.php │ ├── LSet.php │ ├── LTrim.php │ ├── LastSave.php │ ├── MGet.php │ ├── MSet.php │ ├── MSetNx.php │ ├── Monitor.php │ ├── Move.php │ ├── Multi.php │ ├── PExpire.php │ ├── PSetEx.php │ ├── PSubscribe.php │ ├── PTTL.php │ ├── PUnSubscribe.php │ ├── Persist.php │ ├── PfAdd.php │ ├── PfCount.php │ ├── PfMerge.php │ ├── Ping.php │ ├── PubSub.php │ ├── Publish.php │ ├── RPop.php │ ├── RPopLPush.php │ ├── RPuShx.php │ ├── RPush.php │ ├── RandomKey.php │ ├── RawCommand.php │ ├── Rename.php │ ├── RenameNx.php │ ├── Role.php │ ├── SAdd.php │ ├── SCard.php │ ├── SDiff.php │ ├── SDiffStore.php │ ├── SInter.php │ ├── SInterStore.php │ ├── SIsMember.php │ ├── SMembers.php │ ├── SMove.php │ ├── SPop.php │ ├── SRandMember.php │ ├── SRem.php │ ├── SScan.php │ ├── SUnIonStore.php │ ├── SUnion.php │ ├── SYNC.php │ ├── Save.php │ ├── Scan.php │ ├── Select.php │ ├── Set.php │ ├── SetBit.php │ ├── SetEx.php │ ├── SetNx.php │ ├── SetRange.php │ ├── Shutdown.php │ ├── SlowLog.php │ ├── StartPipe.php │ ├── StrLen.php │ ├── Subscribe.php │ ├── SubscribeStop.php │ ├── Time.php │ ├── Ttl.php │ ├── Type.php │ ├── UnWatch.php │ ├── Unlink.php │ ├── Unsubscribe.php │ ├── Watch.php │ ├── XAck.php │ ├── XAdd.php │ ├── XClaim.php │ ├── XDel.php │ ├── XGroup.php │ ├── XInfo.php │ ├── XLen.php │ ├── XPending.php │ ├── XRange.php │ ├── XRead.php │ ├── XReadGroup.php │ ├── XRevRange.php │ ├── XTrim.php │ ├── ZAdd.php │ ├── ZCard.php │ ├── ZCount.php │ ├── ZInCrBy.php │ ├── ZInTerStore.php │ ├── ZLexCount.php │ ├── ZPopMax.php │ ├── ZPopMin.php │ ├── ZRange.php │ ├── ZRangeByLex.php │ ├── ZRangeByScore.php │ ├── ZRank.php │ ├── ZRem.php │ ├── ZRemRangeByLex.php │ ├── ZRemRangeByRank.php │ ├── ZRemRangeByScore.php │ ├── ZRevRange.php │ ├── ZRevRangeByScore.php │ ├── ZRevRank.php │ ├── ZScan.php │ ├── ZScore.php │ └── ZUnionStore.php ├── Config.php ├── CrcHash.php ├── Exception │ ├── RedisClusterException.php │ └── RedisException.php ├── Pipe.php ├── Redis.php ├── RedisCluster.php ├── RedisTransaction.php ├── Response.php └── UnixSocketClient.php └── tests ├── ClientTest.php ├── EventTest.php ├── OtherTest.php ├── RedisClusterTest.php ├── RedisTest.php └── UnixSocketRedisTest.php /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea/ 2 | /vendor/ 3 | /composer.lock 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Redis客户端 2 | 3 | ## 单元测试 4 | 测试前记得修改phpunit.php修改配置 5 | ``` 6 | ./vendor/bin/co-phpunit tests 7 | ``` 8 | ## redis详细文档 9 | http://www.easyswoole.com/Components/Redis/introduction.html 10 | 11 | ## 支持方法 12 | 目前,该redis客户端组件,已经支持除去脚本外的所有方法(目前支持了178个方法): 13 | 14 | - 连接方法(connection) 15 | - 集群方法(cluster) 16 | - geohash 17 | - 哈希(hash) 18 | - 键(keys) 19 | - 列表(lists) 20 | - 发布/订阅(pub/sub) 21 | - 服务器(server) 22 | - 字符串(string) 23 | - 有序集合(sorted sets) 24 | - 集合 (sets) 25 | - 流(stream) 26 | - 事务 (transaction) 27 | - 管道支持 (pipe) 28 | 29 | > 由于redis的命令较多,可能漏掉1,2个命令 30 | 31 | 32 | ## redis使用示例 33 | 34 | ```php 35 | '127.0.0.1', 40 | 'port' => '6379', 41 | 'auth' => 'easyswoole', 42 | 'serialize' => \EasySwoole\Redis\Config::SERIALIZE_NONE 43 | ])); 44 | var_dump($redis->set('a',1)); 45 | var_dump($redis->get('a')); 46 | }); 47 | ``` 48 | 49 | ## redis集群使用示例 50 | 51 | ```php 52 | '', 62 | 'serialize' => \EasySwoole\Redis\Config::SERIALIZE_PHP 63 | ])); 64 | var_dump($redis->set('a',1)); 65 | var_dump($redis->get('a')); 66 | var_dump($redis->clusterKeySlot('a')); 67 | 68 | }); 69 | ``` -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "easyswoole/redis", 3 | "type": "library", 4 | "description": "easyswoole component", 5 | "keywords" : ["swoole", "framework", "async","easyswoole"], 6 | "homepage" : "https://www.easyswoole.com/", 7 | "license" : "Apache-2.0", 8 | "authors": [ 9 | { 10 | "name": "YF", 11 | "email": "291323003@qq.com" 12 | } 13 | ], 14 | "require": { 15 | "php": ">=8.1.0", 16 | "ext-swoole":">=4.4.0", 17 | "easyswoole/spl": "^2.0" 18 | }, 19 | "require-dev": { 20 | "easyswoole/swoole-ide-helper": "^1.2", 21 | "easyswoole/phpunit":">=1.0.0" 22 | }, 23 | "autoload": { 24 | "psr-4": { 25 | "EasySwoole\\Redis\\": "src/" 26 | } 27 | }, 28 | "autoload-dev": { 29 | "psr-4": { 30 | "EasySwoole\\Redis\\Test\\":"test/" 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /phpunit.php: -------------------------------------------------------------------------------- 1 | isConnected; 20 | } 21 | 22 | /** 23 | * @param bool $isConnected 24 | */ 25 | public function setIsConnected(bool $isConnected): void 26 | { 27 | $this->isConnected = $isConnected; 28 | } 29 | 30 | /** 31 | * @return string 32 | */ 33 | public function getHost(): string 34 | { 35 | return $this->host; 36 | } 37 | 38 | /** 39 | * @param string $host 40 | */ 41 | public function setHost(string $host): void 42 | { 43 | $this->host = $host; 44 | } 45 | 46 | /** 47 | * @return int 48 | */ 49 | public function getPort(): int 50 | { 51 | return $this->port; 52 | } 53 | 54 | /** 55 | * @param int $port 56 | */ 57 | public function setPort(int $port): void 58 | { 59 | $this->port = $port; 60 | } 61 | 62 | 63 | } -------------------------------------------------------------------------------- /src/ClusterConfig.php: -------------------------------------------------------------------------------- 1 | '127.0.0.1', 14 | 'port' => 6379, 15 | ] 16 | ]; 17 | protected $auth; 18 | protected $timeout = 3.0; 19 | protected $reconnectTimes = 3; 20 | protected $serialize = self::SERIALIZE_NONE; 21 | 22 | public function __construct($serverList=[], array $data = null, $autoCreateProperty = false) 23 | { 24 | !empty($serverList)&&($this->serverList = $serverList); 25 | parent::__construct($data, $autoCreateProperty); 26 | } 27 | 28 | 29 | /** 30 | * @return array 31 | */ 32 | public function getServerList(): array 33 | { 34 | return $this->serverList; 35 | } 36 | 37 | /** 38 | * @param array $serverList 39 | */ 40 | public function setServerList(array $serverList): void 41 | { 42 | $this->serverList = $serverList; 43 | } 44 | 45 | /** 46 | * @return float 47 | */ 48 | public function getTimeout(): float 49 | { 50 | return $this->timeout; 51 | } 52 | 53 | /** 54 | * @param float $timeout 55 | */ 56 | public function setTimeout(float $timeout): void 57 | { 58 | $this->timeout = $timeout; 59 | } 60 | 61 | /** 62 | * @return int 63 | */ 64 | public function getReconnectTimes(): int 65 | { 66 | return $this->reconnectTimes; 67 | } 68 | 69 | /** 70 | * @param int $reconnectTimes 71 | */ 72 | public function setReconnectTimes(int $reconnectTimes): void 73 | { 74 | $this->reconnectTimes = $reconnectTimes; 75 | } 76 | 77 | /** 78 | * @return int 79 | */ 80 | public function getSerialize(): int 81 | { 82 | return $this->serialize; 83 | } 84 | 85 | /** 86 | * @param int $serialize 87 | */ 88 | public function setSerialize(int $serialize): void 89 | { 90 | $this->serialize = $serialize; 91 | } 92 | 93 | /** 94 | * @return mixed 95 | */ 96 | public function getAuth() 97 | { 98 | return $this->auth; 99 | } 100 | 101 | /** 102 | * @param mixed $auth 103 | */ 104 | public function setAuth($auth): void 105 | { 106 | $this->auth = $auth; 107 | } 108 | 109 | } -------------------------------------------------------------------------------- /src/CommandHandle/AppEnd.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | $value=array_shift($data); 18 | 19 | $command = [CommandConst::APPEND,$key,$value]; 20 | $commandData = array_merge($command,$data); 21 | return $commandData; 22 | } 23 | 24 | 25 | public function handelRecv(Response $recv) 26 | { 27 | return $recv->getData(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/CommandHandle/Auth.php: -------------------------------------------------------------------------------- 1 | getData(); 31 | 32 | if (is_array($data)){ 33 | return [$data[0] => $this->unSerialize($data[1])]; 34 | }else{ 35 | return $data; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/CommandHandle/BRPop.php: -------------------------------------------------------------------------------- 1 | getData(); 31 | if (is_array($data)){ 32 | return [$data[0] => $this->unSerialize($data[1])]; 33 | }else{ 34 | return $data; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/CommandHandle/BRPopLPush.php: -------------------------------------------------------------------------------- 1 | getData(); 28 | return $this->unSerialize($data); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/CommandHandle/BZPopMax.php: -------------------------------------------------------------------------------- 1 | getData(); 26 | 27 | if ($data) { 28 | $data[1] = $this->unSerialize($data[1]); 29 | } 30 | 31 | return $data; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/CommandHandle/BZPopMin.php: -------------------------------------------------------------------------------- 1 | getData(); 26 | 27 | if ($data) { 28 | $data[1] = $this->unSerialize($data[1]); 29 | } 30 | 31 | return $data; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/CommandHandle/BgRewriteAof.php: -------------------------------------------------------------------------------- 1 | getData(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/CommandHandle/BgSave.php: -------------------------------------------------------------------------------- 1 | getData(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/CommandHandle/BitCount.php: -------------------------------------------------------------------------------- 1 | 4 | */ 5 | 6 | 7 | namespace EasySwoole\Redis\CommandHandle; 8 | 9 | 10 | use EasySwoole\Redis\CommandConst; 11 | use EasySwoole\Redis\Response; 12 | 13 | class BitCount extends AbstractCommandHandle 14 | { 15 | protected $commandName = 'BITCOUNT'; 16 | 17 | public function handelCommandData(...$data) 18 | { 19 | $key = array_shift($data); 20 | $this->setClusterExecClientByKey($key); 21 | $start = array_shift($data); 22 | $end = array_shift($data); 23 | 24 | $commandData = [CommandConst::BITCOUNT, $key]; 25 | 26 | if ($start !== null) { 27 | $commandData = array_merge($commandData, [$start]); 28 | if ($end !== null) { 29 | $commandData = array_merge($commandData, [$end]); 30 | } 31 | } 32 | 33 | return $commandData; 34 | } 35 | 36 | public function handelRecv(Response $recv) 37 | { 38 | return $recv->getData(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/CommandHandle/BitField.php: -------------------------------------------------------------------------------- 1 | 4 | */ 5 | 6 | 7 | namespace EasySwoole\Redis\CommandHandle; 8 | 9 | 10 | use EasySwoole\Redis\CommandConst; 11 | use EasySwoole\Redis\Response; 12 | 13 | class BitField extends AbstractCommandHandle 14 | { 15 | protected $commandName = 'BITFIELD'; 16 | 17 | public function handelCommandData(...$data) 18 | { 19 | $key = array_shift($data); 20 | $this->setClusterExecClientByKey($key); 21 | $subcommands = array_shift($data); 22 | $overflow = array_shift($data); 23 | $subcommandArgs = array_shift($data); 24 | 25 | $commandData = [CommandConst::BITFIELD, $key]; 26 | 27 | if (count($subcommands) === count($subcommands, 1)) { 28 | $commandData = array_merge($commandData, $subcommands); 29 | } else { 30 | foreach ($subcommands as $subcommand) { 31 | $commandData = array_merge($commandData, $subcommand); 32 | } 33 | } 34 | 35 | if ($overflow !== null) { 36 | $commandData = array_merge($commandData, ['OVERFLOW', $overflow]); 37 | if (count($subcommandArgs) === count($subcommandArgs, 1)) { 38 | $commandData = array_merge($commandData, $subcommandArgs); 39 | } else { 40 | foreach ($subcommandArgs as $subcommandArg) { 41 | $commandData = array_merge($commandData, $subcommandArg); 42 | } 43 | } 44 | } 45 | 46 | return $commandData; 47 | } 48 | 49 | public function handelRecv(Response $recv) 50 | { 51 | return $recv->getData(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/CommandHandle/BitOp.php: -------------------------------------------------------------------------------- 1 | 4 | */ 5 | 6 | 7 | namespace EasySwoole\Redis\CommandHandle; 8 | 9 | 10 | use EasySwoole\Redis\CommandConst; 11 | use EasySwoole\Redis\Response; 12 | 13 | class BitOp extends AbstractCommandHandle 14 | { 15 | protected $commandName = 'BITOP'; 16 | 17 | public function handelCommandData(...$data) 18 | { 19 | $operation = array_shift($data); 20 | $destKey = array_shift($data); 21 | $this->setClusterExecClientByKey($destKey); 22 | $key = array_shift($data); 23 | $otherKeys = array_shift($data); 24 | 25 | $commandData = [CommandConst::BITOP, $operation, $destKey, $key]; 26 | 27 | if ($otherKeys) { 28 | $commandData = array_merge($commandData, $otherKeys); 29 | } 30 | return $commandData; 31 | } 32 | 33 | public function handelRecv(Response $recv) 34 | { 35 | return $recv->getData(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/CommandHandle/BitPos.php: -------------------------------------------------------------------------------- 1 | 4 | */ 5 | 6 | 7 | namespace EasySwoole\Redis\CommandHandle; 8 | 9 | 10 | use EasySwoole\Redis\CommandConst; 11 | use EasySwoole\Redis\Response; 12 | 13 | class BitPos extends AbstractCommandHandle 14 | { 15 | protected $commandName = 'BITPOS'; 16 | 17 | public function handelCommandData(...$data) 18 | { 19 | $key = array_shift($data); 20 | $this->setClusterExecClientByKey($key); 21 | $bit = array_shift($data); 22 | $start = array_shift($data); 23 | $end = array_shift($data); 24 | 25 | $commandData = [CommandConst::BITPOS, $key, $bit]; 26 | 27 | if ($start !== null) { 28 | $commandData = array_merge($commandData, [$start]); 29 | if ($end !== null) { 30 | $commandData = array_merge($commandData, [$end]); 31 | } 32 | } 33 | return $commandData; 34 | } 35 | 36 | public function handelRecv(Response $recv) 37 | { 38 | return $recv->getData(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/CommandHandle/ClientGetName.php: -------------------------------------------------------------------------------- 1 | getData(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/CommandHandle/ClientKill.php: -------------------------------------------------------------------------------- 1 | getData(); 26 | $result = []; 27 | foreach (explode(PHP_EOL, $data) as $clientKey => $value) { 28 | if (empty($value)) { 29 | continue; 30 | } 31 | $arr = explode(' ', $value); 32 | $result[$clientKey] = []; 33 | foreach ($arr as $kv) { 34 | $kvArr = explode('=', $kv); 35 | $result[$clientKey][$kvArr[0]] = $kvArr[1]; 36 | } 37 | } 38 | return $result; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/CommandHandle/ClientPause.php: -------------------------------------------------------------------------------- 1 | getData(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/CommandHandle/ClusterCommand/ClusterCountKeySinSlot.php: -------------------------------------------------------------------------------- 1 | getData(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/CommandHandle/ClusterCommand/ClusterDelSlots.php: -------------------------------------------------------------------------------- 1 | getData(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/CommandHandle/ClusterCommand/ClusterForget.php: -------------------------------------------------------------------------------- 1 | getData(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/CommandHandle/ClusterCommand/ClusterInfo.php: -------------------------------------------------------------------------------- 1 | getData()) as $value){ 26 | if (empty($value)){ 27 | continue; 28 | } 29 | $kvArr = explode(':',$value); 30 | $result[$kvArr[0]] = $kvArr[1]; 31 | } 32 | return $result; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/CommandHandle/ClusterCommand/ClusterKeySlot.php: -------------------------------------------------------------------------------- 1 | getData(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/CommandHandle/ClusterCommand/ClusterMeet.php: -------------------------------------------------------------------------------- 1 | getData()); 25 | $nodeList = []; 26 | foreach ($list as $serverData) { 27 | $data = explode(' ', $serverData); 28 | if (empty($data[0])) { 29 | continue; 30 | } 31 | list($host, $port) = explode(':', explode('@', $data[1])[0]); 32 | $node = [ 33 | 'name' => $data[0], 34 | 'host' => $host, 35 | 'port' => $port, 36 | 'flags' => $data[2], 37 | 'connected' => $data[7], 38 | 'slotList' => $this->getSlotList($data), 39 | ]; 40 | $nodeList[$node['name']] = $node; 41 | } 42 | return $nodeList; 43 | } 44 | 45 | protected function getSlotList($data) 46 | { 47 | $slotList = []; 48 | //获取8后面的数据 49 | $slotOriginalData = array_slice($data, 8); 50 | foreach ($slotOriginalData as $slotString) { 51 | $slotList[] = explode('-', $slotString); 52 | } 53 | return $slotList; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/CommandHandle/ClusterCommand/ClusterReplicate.php: -------------------------------------------------------------------------------- 1 | getData(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/CommandHandle/ClusterCommand/ClusterSaveConfig.php: -------------------------------------------------------------------------------- 1 | getData(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/CommandHandle/ClusterCommand/ClusterSetSlot.php: -------------------------------------------------------------------------------- 1 | getData(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/CommandHandle/ClusterCommand/ClusterSlots.php: -------------------------------------------------------------------------------- 1 | getData(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/CommandHandle/ClusterCommand/Readonly.php: -------------------------------------------------------------------------------- 1 | getData(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/CommandHandle/CommandCount.php: -------------------------------------------------------------------------------- 1 | getData(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/CommandHandle/CommandGetKeys.php: -------------------------------------------------------------------------------- 1 | getData(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/CommandHandle/CommandInfo.php: -------------------------------------------------------------------------------- 1 | getData(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/CommandHandle/ConfigGet.php: -------------------------------------------------------------------------------- 1 | getData(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/CommandHandle/ConfigResetStat.php: -------------------------------------------------------------------------------- 1 | config = $config; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/CommandHandle/DBSize.php: -------------------------------------------------------------------------------- 1 | getData(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/CommandHandle/DebugObject.php: -------------------------------------------------------------------------------- 1 | getData(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/CommandHandle/DebugSegfault.php: -------------------------------------------------------------------------------- 1 | getData(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/CommandHandle/Decr.php: -------------------------------------------------------------------------------- 1 | getData(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/CommandHandle/DecrBy.php: -------------------------------------------------------------------------------- 1 | getData(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/CommandHandle/Del.php: -------------------------------------------------------------------------------- 1 | getData(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/CommandHandle/Discard.php: -------------------------------------------------------------------------------- 1 | redis->getTransaction()->setCommandLog([]); 24 | $this->redis->getTransaction()->setIsTransaction(false); 25 | return true; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/CommandHandle/DiscardPipe.php: -------------------------------------------------------------------------------- 1 | redis->getPipe()->setIsStartPipe(false); 18 | return true; 19 | } 20 | 21 | 22 | public function handelRecv(Response $recv) 23 | { 24 | $this->redis->getPipe()->setCommandLog([]); 25 | return true; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/CommandHandle/Dump.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | 18 | $command = [CommandConst::DUMP,$key]; 19 | $commandData = array_merge($command,$data); 20 | return $commandData; 21 | } 22 | 23 | 24 | public function handelRecv(Response $recv) 25 | { 26 | return $recv->getData(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/CommandHandle/Exec.php: -------------------------------------------------------------------------------- 1 | getData(); 24 | $commandLog = $this->redis->getTransaction()->getCommandLog(); 25 | $this->redis->getTransaction()->setCommandLog([]); 26 | $this->redis->getTransaction()->setIsTransaction(false); 27 | if ($data===null){ 28 | return $data; 29 | } 30 | foreach ($data as $k=>$value){ 31 | $command = array_shift($commandLog); 32 | $commandClassName = "\\EasySwoole\\Redis\\CommandHandle\\".$command[0]; 33 | /** 34 | * @var $commandClass AbstractCommandHandle 35 | */ 36 | $commandClass = new $commandClassName($this->redis); 37 | //兼容hook event 38 | $commandClass->setCommandData($command[1]); 39 | 40 | $response = new Response(); 41 | $response->setData($value); 42 | $response->setStatus($response::STATUS_OK); 43 | $data[$k] = $commandClass->getData($response); 44 | } 45 | 46 | return $data; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/CommandHandle/ExecPipe.php: -------------------------------------------------------------------------------- 1 | redis->getPipe()->getCommandLog(); 17 | $this->redis->getPipe()->setIsStartPipe(false); 18 | $commandData = ''; 19 | foreach ($commandLog as $command) { 20 | //兼容hook event 21 | $this->onBeforeEvent($command[1]); 22 | 23 | $argNum = count($command[1]); 24 | $str = "*{$argNum}\r\n"; 25 | foreach ($command[1] as $value) { 26 | $len = strlen($value); 27 | $str = $str . '$' . "{$len}\r\n{$value}\r\n"; 28 | } 29 | 30 | $commandData .= "{$str}"; 31 | } 32 | return $commandData; 33 | } 34 | 35 | 36 | public function handelRecv(Response $recv) 37 | { 38 | $commandLog = $this->redis->getPipe()->getCommandLog(); 39 | $this->redis->getPipe()->setCommandLog([]); 40 | $data = []; 41 | foreach ($commandLog as $k => $command) { 42 | $commandClassName = "\\EasySwoole\\Redis\\CommandHandle\\" . $command[0]; 43 | /** 44 | * @var $commandClass AbstractCommandHandle 45 | */ 46 | $commandClass = new $commandClassName($this->redis); 47 | //兼容hook event 48 | $commandClass->setCommandData($command[1]); 49 | //获取返回tcp数据 50 | $response = $this->redis->recv($this->redis->getConfig()->getTimeout()); 51 | $data[$k] = $commandClass->getData($response); 52 | } 53 | return $data; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/CommandHandle/Exists.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 18 | 19 | $command = [CommandConst::EXISTS,$key]; 20 | $commandData = array_merge($command,$data); 21 | return $commandData; 22 | } 23 | 24 | 25 | public function handelRecv(Response $recv) 26 | { 27 | return $recv->getData(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/CommandHandle/Expire.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | $expireTime=array_shift($data); 18 | 19 | $command = [CommandConst::EXPIRE,$key,$expireTime]; 20 | $commandData = array_merge($command,$data); 21 | return $commandData; 22 | } 23 | 24 | 25 | public function handelRecv(Response $recv) 26 | { 27 | return $recv->getData(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/CommandHandle/ExpireAt.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | $expireTime=array_shift($data); 18 | 19 | 20 | 21 | 22 | $command = [CommandConst::EXPIREAT,$key,$expireTime]; 23 | $commandData = array_merge($command,$data); 24 | return $commandData; 25 | } 26 | 27 | 28 | public function handelRecv(Response $recv) 29 | { 30 | return $recv->getData(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/CommandHandle/FlushAll.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | $data = array_shift($data); 18 | $command = [CommandConst::GEOADD,$key]; 19 | foreach ($data as $locationData){ 20 | $command[] = $locationData['longitude']??$locationData[0]; 21 | $command[] = $locationData['latitude']??$locationData[1]; 22 | $command[] = $locationData['name']??$locationData[2]; 23 | } 24 | 25 | $commandData = array_merge($command); 26 | return $commandData; 27 | } 28 | 29 | 30 | public function handelRecv(Response $recv) 31 | { 32 | return $recv->getData(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/CommandHandle/GeoDist.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | $location1=array_shift($data); 18 | $location2=array_shift($data); 19 | $unit=array_shift($data); 20 | 21 | $command = [CommandConst::GEODIST,$key,$location1,$location2,$unit]; 22 | $commandData = array_merge($command,$data); 23 | return $commandData; 24 | } 25 | 26 | 27 | public function handelRecv(Response $recv) 28 | { 29 | return $recv->getData(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/CommandHandle/GeoHash.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | $location=array_shift($data); 18 | 19 | $command = [CommandConst::GEOHASH,$key,$location]; 20 | $commandData = array_merge($command,$data); 21 | return $commandData; 22 | } 23 | 24 | 25 | public function handelRecv(Response $recv) 26 | { 27 | return $recv->getData(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/CommandHandle/GeoPos.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | $location1=array_shift($data); 18 | 19 | $command = [CommandConst::GEOPOS,$key,$location1]; 20 | $commandData = array_merge($command,$data); 21 | return $commandData; 22 | } 23 | 24 | 25 | public function handelRecv(Response $recv) 26 | { 27 | return $recv->getData(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/CommandHandle/GeoRadius.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 18 | $longitude = array_shift($data); 19 | $latitude = array_shift($data); 20 | $radius = array_shift($data); 21 | $unit = array_shift($data); 22 | $withCoord = array_shift($data); 23 | $withDist = array_shift($data); 24 | $withHash = array_shift($data); 25 | $count = array_shift($data); 26 | $sort = array_shift($data); 27 | $storeKey = array_shift($data); 28 | $storeDistKey = array_shift($data); 29 | 30 | 31 | 32 | $command = [CommandConst::GEORADIUS, $key, $longitude, $latitude, $radius, $unit,]; 33 | 34 | if ($withCoord === true) { 35 | $command[] = 'WITHCOORD'; 36 | } 37 | if ($withDist === true) { 38 | $command[] = 'WITHDIST'; 39 | } 40 | if ($withHash === true) { 41 | $command[] = 'WITHHASH'; 42 | } 43 | if ($count !== null) { 44 | $command[] = 'COUNT'; 45 | $command[] = (int)$count; 46 | } 47 | if ($sort !== null) { 48 | $command[] = $sort; 49 | } 50 | if ($storeKey !== null) { 51 | $command[] = 'STORE'; 52 | $command[] = $storeKey; 53 | } 54 | if ($storeDistKey !== null) { 55 | $command[] = 'STOREDIST'; 56 | $command[] = $storeDistKey; 57 | } 58 | $commandData = array_merge($command, $data); 59 | return $commandData; 60 | } 61 | 62 | 63 | public function handelRecv(Response $recv) 64 | { 65 | return $recv->getData(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/CommandHandle/GeoRadiusByMember.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 18 | $location = array_shift($data); 19 | $radius = array_shift($data); 20 | $unit = array_shift($data); 21 | $withCoord = array_shift($data); 22 | $withDist = array_shift($data); 23 | $withHash = array_shift($data); 24 | $count = array_shift($data); 25 | $sort = array_shift($data); 26 | $storeKey = array_shift($data); 27 | $storeDistKey = array_shift($data); 28 | 29 | $command = [CommandConst::GEORADIUSBYMEMBER, $key, $location, $radius, $unit, ]; 30 | 31 | if ($withCoord === true) { 32 | $command[] = 'WITHCOORD'; 33 | } 34 | if ($withDist === true) { 35 | $command[] = 'WITHDIST'; 36 | } 37 | if ($withHash === true) { 38 | $command[] = 'WITHHASH'; 39 | } 40 | if ($count !== null) { 41 | $command[] = 'COUNT'; 42 | $command[] = (int)$count; 43 | } 44 | if ($sort !== null) { 45 | $command[] = $sort; 46 | } 47 | if ($storeKey !== null) { 48 | $command[] = 'STORE'; 49 | $command[] = $storeKey; 50 | } 51 | if ($storeDistKey !== null) { 52 | $command[] = 'STOREDIST'; 53 | $command[] = $storeDistKey; 54 | } 55 | $commandData = array_merge($command, $data); 56 | return $commandData; 57 | } 58 | 59 | 60 | public function handelRecv(Response $recv) 61 | { 62 | return $recv->getData(); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/CommandHandle/Get.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 15 | $command = [CommandConst::GET, $key]; 16 | $commandData = $command; 17 | return $commandData; 18 | } 19 | 20 | public function handelRecv(Response $recv) 21 | { 22 | $data = $recv->getData(); 23 | return $this->unSerialize($data); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/CommandHandle/GetBit.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | $offset=array_shift($data); 18 | 19 | 20 | 21 | 22 | $command = [CommandConst::GETBIT,$key,$offset]; 23 | $commandData = array_merge($command,$data); 24 | return $commandData; 25 | } 26 | 27 | 28 | public function handelRecv(Response $recv) 29 | { 30 | return $recv->getData(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/CommandHandle/GetRange.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | $start=array_shift($data); 18 | $end=array_shift($data); 19 | 20 | 21 | $command = [CommandConst::GETRANGE,$key,$start,$end]; 22 | $commandData = array_merge($command,$data); 23 | return $commandData; 24 | } 25 | 26 | 27 | public function handelRecv(Response $recv) 28 | { 29 | return $recv->getData(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/CommandHandle/GetSet.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | $value=array_shift($data); 18 | 19 | 20 | $value = $this->serialize($value); 21 | 22 | $command = [CommandConst::GETSET,$key,$value]; 23 | $commandData = array_merge($command,$data); 24 | return $commandData; 25 | } 26 | 27 | 28 | public function handelRecv(Response $recv) 29 | { 30 | $data = $recv->getData(); 31 | return $this->unSerialize($data); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/CommandHandle/HDel.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | $field=array_shift($data); 18 | 19 | $command = [CommandConst::HDEL,$key,$field]; 20 | $commandData = array_merge($command,$data); 21 | return $commandData; 22 | } 23 | 24 | 25 | public function handelRecv(Response $recv) 26 | { 27 | return $recv->getData(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/CommandHandle/HExists.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | $field=array_shift($data); 18 | 19 | 20 | 21 | 22 | $command = [CommandConst::HEXISTS,$key,$field]; 23 | $commandData = array_merge($command,$data); 24 | return $commandData; 25 | } 26 | 27 | 28 | public function handelRecv(Response $recv) 29 | { 30 | return $recv->getData(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/CommandHandle/HGet.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 18 | $field = array_shift($data); 19 | 20 | $command = [CommandConst::HGET, $key, $field]; 21 | $commandData = array_merge($command, $data); 22 | return $commandData; 23 | } 24 | 25 | 26 | public function handelRecv(Response $recv) 27 | { 28 | $data = $recv->getData(); 29 | return $this->unSerialize($data); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/CommandHandle/HGetAll.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 18 | 19 | $command = [CommandConst::HGETALL, $key]; 20 | $commandData = array_merge($command, $data); 21 | return $commandData; 22 | } 23 | 24 | 25 | public function handelRecv(Response $recv) 26 | { 27 | $result = []; 28 | $data = $recv->getData(); 29 | $dataCount = count($data); 30 | for ($i = 0; $i < $dataCount / 2; $i++) { 31 | $result[$data[$i * 2]] = $this->unSerialize($data[$i * 2 + 1]); 32 | } 33 | return $result; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/CommandHandle/HIncrBy.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | $field=array_shift($data); 18 | $increment=array_shift($data); 19 | 20 | 21 | 22 | 23 | $command = [CommandConst::HINCRBY,$key,$field,$increment]; 24 | $commandData = array_merge($command,$data); 25 | return $commandData; 26 | } 27 | 28 | 29 | public function handelRecv(Response $recv) 30 | { 31 | return $recv->getData(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/CommandHandle/HIncrByFloat.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | $field=array_shift($data); 18 | $increment=array_shift($data); 19 | 20 | 21 | 22 | 23 | $command = [CommandConst::HINCRBYFLOAT,$key,$field,$increment]; 24 | $commandData = array_merge($command,$data); 25 | return $commandData; 26 | } 27 | 28 | 29 | public function handelRecv(Response $recv) 30 | { 31 | return $recv->getData(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/CommandHandle/HKeys.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | 18 | 19 | $command = [CommandConst::HKEYS,$key]; 20 | $commandData = array_merge($command,$data); 21 | return $commandData; 22 | } 23 | 24 | 25 | public function handelRecv(Response $recv) 26 | { 27 | return $recv->getData(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/CommandHandle/HLen.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | 18 | 19 | 20 | 21 | $command = [CommandConst::HLEN,$key]; 22 | $commandData = array_merge($command,$data); 23 | return $commandData; 24 | } 25 | 26 | 27 | public function handelRecv(Response $recv) 28 | { 29 | return $recv->getData(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/CommandHandle/HMGet.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 18 | $hashKeys = array_shift($data); 19 | 20 | $command = [CommandConst::HMGET, $key]; 21 | $commandData = array_merge($command, $hashKeys); 22 | return $commandData; 23 | } 24 | 25 | 26 | public function handelRecv(Response $recv) 27 | { 28 | $fieldData = array_slice($this->commandData,2); 29 | $data = $recv->getData(); 30 | $array = []; 31 | foreach ($data as $key => $value) { 32 | $array[$fieldData[$key]] = $this->unSerialize($value); 33 | } 34 | 35 | return $array; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/CommandHandle/HMSet.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 18 | $data = array_shift($data); 19 | 20 | $kvData = []; 21 | foreach ($data as $k => $value) { 22 | $kvData[] = $k; 23 | $kvData[] = $this->serialize($value); 24 | } 25 | $command = [CommandConst::HMSET, $key]; 26 | $commandData = array_merge($command, $kvData); 27 | return $commandData; 28 | } 29 | 30 | 31 | public function handelRecv(Response $recv) 32 | { 33 | return true; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/CommandHandle/HScan.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 16 | $cursor=array_shift($data); 17 | $pattern=array_shift($data); 18 | $count=array_shift($data); 19 | $command = [CommandConst::HSCAN,$key,$cursor]; 20 | if ($pattern!==null){ 21 | $command[] = 'MATCH'; 22 | $command[] = $pattern; 23 | } 24 | if ($count!==null){ 25 | $command[] = 'COUNT'; 26 | $command[] = $count; 27 | } 28 | $commandData = $command; 29 | return $commandData; 30 | } 31 | 32 | 33 | public function handelRecv(Response $recv) 34 | { 35 | $data = $recv->getData(); 36 | $result = []; 37 | foreach ($data[1] as $k=>$value){ 38 | if ($k%2==0){ 39 | $result[$value] = []; 40 | }else{ 41 | $result[$data[1][$k-1]]=$this->unSerialize($value); 42 | } 43 | } 44 | $data[1] = $result; 45 | return $data; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/CommandHandle/HSet.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 18 | $field = array_shift($data); 19 | $value = array_shift($data); 20 | 21 | $value = $this->serialize($value); 22 | 23 | $command = [CommandConst::HSET, $key, $field, $value]; 24 | $commandData = array_merge($command, $data); 25 | return $commandData; 26 | } 27 | 28 | 29 | public function handelRecv(Response $recv) 30 | { 31 | return $recv->getData(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/CommandHandle/HSetNx.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 18 | $field = array_shift($data); 19 | $value = array_shift($data); 20 | 21 | 22 | $value = $this->serialize($value); 23 | 24 | 25 | $command = [CommandConst::HSETNX, $key, $field, $value]; 26 | $commandData = array_merge($command, $data); 27 | return $commandData; 28 | } 29 | 30 | 31 | public function handelRecv(Response $recv) 32 | { 33 | return $recv->getData(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/CommandHandle/HValS.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 18 | 19 | $command = [CommandConst::HVALS, $key]; 20 | $commandData = array_merge($command); 21 | return $commandData; 22 | } 23 | 24 | 25 | public function handelRecv(Response $recv) 26 | { 27 | $data = $recv->getData(); 28 | foreach ($data as $key => $value) { 29 | $data[$key] = $this->unSerialize($value); 30 | } 31 | return $data; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/CommandHandle/Incr.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | 18 | 19 | $command = [CommandConst::INCR,$key]; 20 | $commandData = array_merge($command,$data); 21 | return $commandData; 22 | } 23 | 24 | 25 | public function handelRecv(Response $recv) 26 | { 27 | return $recv->getData(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/CommandHandle/IncrBy.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | $value=array_shift($data); 18 | 19 | 20 | 21 | 22 | $command = [CommandConst::INCRBY,$key,$value]; 23 | $commandData = array_merge($command,$data); 24 | return $commandData; 25 | } 26 | 27 | 28 | public function handelRecv(Response $recv) 29 | { 30 | return $recv->getData(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/CommandHandle/IncrByFloat.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | $value=array_shift($data); 18 | 19 | 20 | 21 | 22 | $command = [CommandConst::INCRBYFLOAT,$key,$value]; 23 | $commandData = array_merge($command,$data); 24 | return $commandData; 25 | } 26 | 27 | 28 | public function handelRecv(Response $recv) 29 | { 30 | return $recv->getData(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/CommandHandle/Info.php: -------------------------------------------------------------------------------- 1 | getData(); 31 | $result = []; 32 | foreach (explode('# ', $data) as $value) { 33 | if (empty($value)) { 34 | continue; 35 | } 36 | $arr = explode("\r\n", $value); 37 | $sectionKey = array_shift($arr); 38 | $result[$sectionKey] = []; 39 | foreach ($arr as $kv) { 40 | if (empty($kv)) { 41 | continue; 42 | } 43 | $kvArr = explode(':', $kv); 44 | $result[$sectionKey][$kvArr[0]] = $kvArr[1]; 45 | } 46 | } 47 | 48 | return $result; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/CommandHandle/Keys.php: -------------------------------------------------------------------------------- 1 | getData(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/CommandHandle/LIndex.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | $index=array_shift($data); 18 | 19 | $command = [CommandConst::LINDEX,$key,$index]; 20 | $commandData = array_merge($command,$data); 21 | return $commandData; 22 | } 23 | 24 | 25 | public function handelRecv(Response $recv) 26 | { 27 | $data = $recv->getData(); 28 | return $this->unSerialize($data); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/CommandHandle/LInsert.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 18 | $isBefore = array_shift($data); 19 | $pivot = array_shift($data); 20 | $value = array_shift($data); 21 | 22 | $value = $this->serialize($value); 23 | $pivot = $this->serialize($pivot); 24 | $command = [CommandConst::LINSERT, $key, $isBefore, $pivot, $value]; 25 | $commandData = array_merge($command); 26 | return $commandData; 27 | } 28 | 29 | 30 | public function handelRecv(Response $recv) 31 | { 32 | return $recv->getData(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/CommandHandle/LLen.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | 18 | $command = [CommandConst::LLEN,$key]; 19 | $commandData = array_merge($command,$data); 20 | return $commandData; 21 | } 22 | 23 | 24 | public function handelRecv(Response $recv) 25 | { 26 | return $recv->getData(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/CommandHandle/LPop.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 18 | 19 | $command = [CommandConst::LPOP, $key]; 20 | $commandData = array_merge($command, $data); 21 | return $commandData; 22 | } 23 | 24 | 25 | public function handelRecv(Response $recv) 26 | { 27 | $data = $recv->getData(); 28 | return $this->unSerialize($data); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/CommandHandle/LPuShx.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 18 | $value = array_shift($data); 19 | 20 | 21 | $value = $this->serialize($value); 22 | 23 | 24 | $command = [CommandConst::LPUSHX, $key, $value]; 25 | $commandData = array_merge($command, $data); 26 | return $commandData; 27 | } 28 | 29 | 30 | public function handelRecv(Response $recv) 31 | { 32 | return $recv->getData(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/CommandHandle/LPush.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 18 | foreach ($data as $k=>$value){ 19 | $data[$k] = $this->serialize($value); 20 | } 21 | 22 | $command = [CommandConst::LPUSH, $key]; 23 | $commandData = array_merge($command, $data); 24 | return $commandData; 25 | } 26 | 27 | 28 | public function handelRecv(Response $recv) 29 | { 30 | return $recv->getData(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/CommandHandle/LRange.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 18 | $start = array_shift($data); 19 | $stop = array_shift($data); 20 | 21 | 22 | $command = [CommandConst::LRANGE, $key, $start, $stop]; 23 | $commandData = array_merge($command, $data); 24 | return $commandData; 25 | } 26 | 27 | 28 | public function handelRecv(Response $recv) 29 | { 30 | $data = $recv->getData(); 31 | foreach ($data as $key => $va) { 32 | $data[$key] = $this->unSerialize($va); 33 | } 34 | return $data; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/CommandHandle/LRem.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 18 | $count = array_shift($data); 19 | $value = array_shift($data); 20 | 21 | $value = $this->serialize($value); 22 | 23 | $command = [CommandConst::LREM, $key, $count, $value]; 24 | $commandData = array_merge($command, $data); 25 | return $commandData; 26 | } 27 | 28 | 29 | public function handelRecv(Response $recv) 30 | { 31 | return $recv->getData(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/CommandHandle/LSet.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 18 | $index = array_shift($data); 19 | $value = array_shift($data); 20 | 21 | 22 | $value = $this->serialize($value); 23 | 24 | 25 | $command = [CommandConst::LSET, $key, $index, $value]; 26 | $commandData = array_merge($command, $data); 27 | return $commandData; 28 | } 29 | 30 | 31 | public function handelRecv(Response $recv) 32 | { 33 | return true; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/CommandHandle/LTrim.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | $start=array_shift($data); 18 | $stop=array_shift($data); 19 | 20 | 21 | 22 | 23 | $command = [CommandConst::LTRIM,$key,$start,$stop]; 24 | $commandData = array_merge($command,$data); 25 | return $commandData; 26 | } 27 | 28 | 29 | public function handelRecv(Response $recv) 30 | { 31 | return true; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/CommandHandle/LastSave.php: -------------------------------------------------------------------------------- 1 | getData(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/CommandHandle/MGet.php: -------------------------------------------------------------------------------- 1 | getData(); 31 | foreach ($data as $key => $value) { 32 | $data[$key] = $this->unSerialize($value); 33 | } 34 | 35 | return $data; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/CommandHandle/MSet.php: -------------------------------------------------------------------------------- 1 | $value) { 18 | $kvData[] = $k; 19 | $kvData[] = $this->serialize($value); 20 | } 21 | $command = [CommandConst::MSET]; 22 | $commandData = array_merge($command,$kvData); 23 | return $commandData; 24 | } 25 | 26 | 27 | public function handelRecv(Response $recv) 28 | { 29 | return true; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/CommandHandle/MSetNx.php: -------------------------------------------------------------------------------- 1 | $value) { 19 | $kvData[] = $key; 20 | $kvData[] = $this->serialize($value); 21 | } 22 | $command = [CommandConst::MSETNX]; 23 | $commandData = array_merge($command, $kvData); 24 | return $commandData; 25 | } 26 | 27 | 28 | public function handelRecv(Response $recv) 29 | { 30 | return $recv->getData(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/CommandHandle/Monitor.php: -------------------------------------------------------------------------------- 1 | callback = $callback; 18 | $command = [CommandConst::MONITOR]; 19 | $commandData = array_merge($command, $data); 20 | return $commandData; 21 | } 22 | 23 | 24 | public function handelRecv(Response $recv) 25 | { 26 | $this->redis->setMonitorStop(false); 27 | while ($this->redis->isMonitorStop() == false) { 28 | $recv = $this->redis->recv(-1); 29 | if ($recv === null) { 30 | return false; 31 | } 32 | call_user_func($this->callback, $this->redis, $recv->getData()); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/CommandHandle/Move.php: -------------------------------------------------------------------------------- 1 | getData(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/CommandHandle/Multi.php: -------------------------------------------------------------------------------- 1 | redis->setTransaction(new RedisTransaction()); 25 | $this->redis->getTransaction()->setIsTransaction(true); 26 | return true; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/CommandHandle/PExpire.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | $expireTime=array_shift($data); 18 | 19 | $command = [CommandConst::PEXPIRE,$key,$expireTime]; 20 | $commandData = array_merge($command,$data); 21 | return $commandData; 22 | } 23 | 24 | 25 | public function handelRecv(Response $recv) 26 | { 27 | return $recv->getData(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/CommandHandle/PSetEx.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 18 | $expireTime = array_shift($data); 19 | $value = array_shift($data); 20 | 21 | 22 | $value = $this->serialize($value); 23 | 24 | 25 | $command = [CommandConst::PSETEX, $key, $expireTime, $value]; 26 | $commandData = array_merge($command, $data); 27 | return $commandData; 28 | } 29 | 30 | 31 | public function handelRecv(Response $recv) 32 | { 33 | return true; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/CommandHandle/PSubscribe.php: -------------------------------------------------------------------------------- 1 | callback = $callback; 19 | $command = [CommandConst::PSUBSCRIBE, $pattern]; 20 | $commandData = array_merge($command, $data); 21 | return $commandData; 22 | } 23 | 24 | 25 | public function handelRecv(Response $recv) 26 | { 27 | $this->redis->setSubscribeStop(false); 28 | while ($this->redis->isSubscribeStop() == false) { 29 | $recv = $this->redis->recv(-1); 30 | if ($recv === null) { 31 | return false; 32 | } 33 | if ($recv->getData()[0] == 'pmessage') { 34 | call_user_func($this->callback, $this->redis, $recv->getData()[2], $recv->getData()[3]); 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/CommandHandle/PTTL.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | 18 | 19 | 20 | 21 | $command = [CommandConst::PTTL,$key]; 22 | $commandData = array_merge($command,$data); 23 | return $commandData; 24 | } 25 | 26 | 27 | public function handelRecv(Response $recv) 28 | { 29 | return $recv->getData(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/CommandHandle/PUnSubscribe.php: -------------------------------------------------------------------------------- 1 | getData(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/CommandHandle/Persist.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | 18 | 19 | 20 | 21 | $command = [CommandConst::PERSIST,$key]; 22 | $commandData = array_merge($command,$data); 23 | return $commandData; 24 | } 25 | 26 | 27 | public function handelRecv(Response $recv) 28 | { 29 | return $recv->getData(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/CommandHandle/PfAdd.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | $elements=array_shift($data); 18 | 19 | $command = [CommandConst::PFADD,$key]; 20 | $commandData = array_merge($command,$elements); 21 | return $commandData; 22 | } 23 | 24 | 25 | public function handelRecv(Response $recv) 26 | { 27 | return $recv->getData(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/CommandHandle/PfCount.php: -------------------------------------------------------------------------------- 1 | getData(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/CommandHandle/PfMerge.php: -------------------------------------------------------------------------------- 1 | getData(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/CommandHandle/PubSub.php: -------------------------------------------------------------------------------- 1 | getData(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/CommandHandle/Publish.php: -------------------------------------------------------------------------------- 1 | getData(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/CommandHandle/RPop.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | 18 | 19 | $command = [CommandConst::RPOP,$key]; 20 | $commandData = array_merge($command,$data); 21 | return $commandData; 22 | } 23 | 24 | 25 | public function handelRecv(Response $recv) 26 | { 27 | $data = $recv->getData(); 28 | return $this->unSerialize($data); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/CommandHandle/RPopLPush.php: -------------------------------------------------------------------------------- 1 | getData(); 27 | return $this->unSerialize($data); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/CommandHandle/RPuShx.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 18 | $value = array_shift($data); 19 | 20 | $value = $this->serialize($value); 21 | 22 | 23 | $command = [CommandConst::RPUSHX, $key, $value]; 24 | $commandData = array_merge($command, $data); 25 | return $commandData; 26 | } 27 | 28 | 29 | public function handelRecv(Response $recv) 30 | { 31 | return $recv->getData(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/CommandHandle/RPush.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 18 | 19 | foreach ($data as $k => $va) { 20 | $data[$k] = $this->serialize($va); 21 | } 22 | $command = [CommandConst::RPUSH, $key]; 23 | $commandData = array_merge($command, $data); 24 | return $commandData; 25 | } 26 | 27 | 28 | public function handelRecv(Response $recv) 29 | { 30 | return $recv->getData(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/CommandHandle/RandomKey.php: -------------------------------------------------------------------------------- 1 | getData(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/CommandHandle/RawCommand.php: -------------------------------------------------------------------------------- 1 | getData(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/CommandHandle/Rename.php: -------------------------------------------------------------------------------- 1 | getData(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/CommandHandle/Role.php: -------------------------------------------------------------------------------- 1 | getData(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/CommandHandle/SAdd.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 18 | $data = array_shift($data); 19 | 20 | 21 | foreach ($data as $k => $va) { 22 | $data[$k] = $this->serialize($va); 23 | } 24 | 25 | $command = [CommandConst::SADD, $key]; 26 | $commandData = array_merge($command, $data); 27 | return $commandData; 28 | } 29 | 30 | 31 | public function handelRecv(Response $recv) 32 | { 33 | return $recv->getData(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/CommandHandle/SCard.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | 18 | 19 | 20 | 21 | $command = [CommandConst::SCARD,$key]; 22 | $commandData = array_merge($command,$data); 23 | return $commandData; 24 | } 25 | 26 | 27 | public function handelRecv(Response $recv) 28 | { 29 | return $recv->getData(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/CommandHandle/SDiff.php: -------------------------------------------------------------------------------- 1 | getData(); 27 | foreach ($data as $key => $value) { 28 | $data[$key] = $this->unSerialize($value); 29 | } 30 | return $data; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/CommandHandle/SDiffStore.php: -------------------------------------------------------------------------------- 1 | getData(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/CommandHandle/SInter.php: -------------------------------------------------------------------------------- 1 | getData(); 27 | foreach ($data as $key => $value) { 28 | $data[$key] = $this->unSerialize($value); 29 | } 30 | return $data; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/CommandHandle/SInterStore.php: -------------------------------------------------------------------------------- 1 | getData(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/CommandHandle/SIsMember.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 18 | $member = array_shift($data); 19 | 20 | 21 | $member = $this->serialize($member); 22 | 23 | 24 | $command = [CommandConst::SISMEMBER, $key, $member]; 25 | $commandData = array_merge($command, $data); 26 | return $commandData; 27 | } 28 | 29 | 30 | public function handelRecv(Response $recv) 31 | { 32 | return $recv->getData(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/CommandHandle/SMembers.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 18 | 19 | $command = [CommandConst::SMEMBERS, $key]; 20 | $commandData = array_merge($command, $data); 21 | return $commandData; 22 | } 23 | 24 | 25 | public function handelRecv(Response $recv) 26 | { 27 | $data = $recv->getData(); 28 | foreach ($data as $key => $value) { 29 | $data[$key] = $this->unSerialize($value); 30 | } 31 | return $data; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/CommandHandle/SMove.php: -------------------------------------------------------------------------------- 1 | serialize($member); 21 | 22 | 23 | $command = [CommandConst::SMOVE,$source,$destination,$member]; 24 | $commandData = array_merge($command,$data); 25 | return $commandData; 26 | } 27 | 28 | 29 | public function handelRecv(Response $recv) 30 | { 31 | return $recv->getData(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/CommandHandle/SPop.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 18 | $count = array_shift($data); 19 | 20 | $command = [CommandConst::SPOP, $key]; 21 | if (!is_null($count) && $count > 1) { 22 | $command[] = $count; 23 | $this->count = $count; 24 | } 25 | 26 | return $command; 27 | } 28 | 29 | 30 | public function handelRecv(Response $recv) 31 | { 32 | 33 | $data = $recv->getData(); 34 | if ($this->count > 1) { 35 | foreach ($data as $key => $value) { 36 | $data[$key] = $this->unSerialize($value); 37 | } 38 | return $data; 39 | } else { 40 | return $this->unSerialize($data); 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/CommandHandle/SRandMember.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 18 | $count = array_shift($data); 19 | 20 | $command = [CommandConst::SRANDMEMBER, $key]; 21 | if ($count !== null) { 22 | $command[] = $count; 23 | } 24 | $commandData = array_merge($command); 25 | return $commandData; 26 | } 27 | 28 | 29 | public function handelRecv(Response $recv) 30 | { 31 | $data = $recv->getData(); 32 | if (is_array($data)) { 33 | foreach ($data as $key => $value) { 34 | $data[$key] = $this->unSerialize($value); 35 | } 36 | }else{ 37 | $data = $this->unSerialize($data); 38 | } 39 | 40 | return $data; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/CommandHandle/SRem.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 18 | $member1 = array_shift($data); 19 | $members = []; 20 | 21 | $member1 = $this->serialize($member1); 22 | foreach ($data as $k => $va) { 23 | $members[$k] = $this->serialize($va); 24 | } 25 | $command = [CommandConst::SREM, $key, $member1]; 26 | $commandData = array_merge($command, $members); 27 | return $commandData; 28 | } 29 | 30 | 31 | public function handelRecv(Response $recv) 32 | { 33 | return $recv->getData(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/CommandHandle/SScan.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 16 | $cursor=array_shift($data); 17 | $pattern=array_shift($data); 18 | $count=array_shift($data); 19 | $command = [CommandConst::SSCAN,$key,$cursor]; 20 | if ($pattern!==null){ 21 | $command[] = 'MATCH'; 22 | $command[] = $pattern; 23 | } 24 | if ($count!==null){ 25 | $command[] = 'COUNT'; 26 | $command[] = $count; 27 | } 28 | $commandData = $command; 29 | return $commandData; 30 | } 31 | 32 | 33 | public function handelRecv(Response $recv) 34 | { 35 | $data = $recv->getData(); 36 | foreach ($data[1] as $k=>$value){ 37 | $data[1][$k] = $this->unSerialize($value); 38 | } 39 | return $data; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/CommandHandle/SUnIonStore.php: -------------------------------------------------------------------------------- 1 | getData(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/CommandHandle/SUnion.php: -------------------------------------------------------------------------------- 1 | getData(); 27 | foreach ($data as $key => $value) { 28 | $data[$key] = $this->unSerialize($value); 29 | } 30 | return $data; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/CommandHandle/SYNC.php: -------------------------------------------------------------------------------- 1 | getData(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/CommandHandle/Save.php: -------------------------------------------------------------------------------- 1 | getData(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/CommandHandle/Select.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | $val = array_shift($data); 18 | $timeout = array_shift($data); 19 | $val = $this->serialize($val); 20 | $command = [CommandConst::SET, $key, $val]; 21 | //int的时候 22 | if (is_int($timeout) && $timeout > 0) { 23 | $command[] = 'EX'; 24 | $command[] = $timeout; 25 | } 26 | //string的时候 27 | if (is_string($timeout) && in_array($timeout, ['NX', 'XX'])) { 28 | $command[] = $timeout; 29 | } 30 | //传入数组 31 | if (is_array($timeout)) { 32 | if (!empty($timeout['EX'])) { 33 | $command[] = 'EX'; 34 | $command[] = $timeout['EX']; 35 | unset($timeout['EX']); 36 | } 37 | if (!empty($timeout['PX'])) { 38 | $command[] = 'PX'; 39 | $command[] = $timeout['PX']; 40 | unset($timeout['PX']); 41 | } 42 | foreach ($timeout as $v) { 43 | $command[] = $v; 44 | } 45 | } 46 | $commandData = $command; 47 | return $commandData; 48 | } 49 | 50 | 51 | public function handelRecv(Response $recv) 52 | { 53 | if ($recv->getData() === null) { 54 | return null; 55 | } else { 56 | return true; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/CommandHandle/SetBit.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | $offset=array_shift($data); 18 | $value=array_shift($data); 19 | 20 | 21 | 22 | 23 | $command = [CommandConst::SETBIT,$key,$offset,$value]; 24 | $commandData = array_merge($command,$data); 25 | return $commandData; 26 | } 27 | 28 | 29 | public function handelRecv(Response $recv) 30 | { 31 | return $recv->getData(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/CommandHandle/SetEx.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 18 | $expireTime = array_shift($data); 19 | $value = array_shift($data); 20 | 21 | $value = $this->serialize($value); 22 | 23 | $command = [CommandConst::SETEX, $key, $expireTime, $value]; 24 | $commandData = array_merge($command, $data); 25 | return $commandData; 26 | } 27 | 28 | 29 | public function handelRecv(Response $recv) 30 | { 31 | return true; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/CommandHandle/SetNx.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | $value=array_shift($data); 18 | $value = $this->serialize($value); 19 | $command = [CommandConst::SETNX,$key,$value]; 20 | $commandData = array_merge($command,$data); 21 | return $commandData; 22 | } 23 | 24 | 25 | public function handelRecv(Response $recv) 26 | { 27 | return $recv->getData(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/CommandHandle/SetRange.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | $offset=array_shift($data); 18 | $value=array_shift($data); 19 | 20 | 21 | 22 | 23 | $command = [CommandConst::SETRANGE,$key,$offset,$value]; 24 | $commandData = array_merge($command,$data); 25 | return $commandData; 26 | } 27 | 28 | 29 | public function handelRecv(Response $recv) 30 | { 31 | return $recv->getData(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/CommandHandle/Shutdown.php: -------------------------------------------------------------------------------- 1 | getData(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/CommandHandle/SlowLog.php: -------------------------------------------------------------------------------- 1 | getData(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/CommandHandle/StartPipe.php: -------------------------------------------------------------------------------- 1 | redis->setPipe(new Pipe()); 20 | $this->redis->getPipe()->setIsStartPipe(true); 21 | return true; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/CommandHandle/StrLen.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | 18 | 19 | 20 | 21 | $command = [CommandConst::STRLEN,$key]; 22 | $commandData = array_merge($command,$data); 23 | return $commandData; 24 | } 25 | 26 | 27 | public function handelRecv(Response $recv) 28 | { 29 | return $recv->getData(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/CommandHandle/Subscribe.php: -------------------------------------------------------------------------------- 1 | callback = $callback; 20 | $command = [CommandConst::SUBSCRIBE, $channel]; 21 | $commandData = array_merge($command, $data); 22 | return $commandData; 23 | } 24 | 25 | 26 | public function handelRecv(Response $recv) 27 | { 28 | $this->redis->setSubscribeStop(false); 29 | while ($this->redis->isSubscribeStop() == false) { 30 | $recv = $this->redis->recv(-1); 31 | if ($recv === null) { 32 | return false; 33 | } 34 | if ($recv->getData()[0] == 'message') { 35 | call_user_func($this->callback, $this->redis, $recv->getData()[1], $recv->getData()[2]); 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/CommandHandle/SubscribeStop.php: -------------------------------------------------------------------------------- 1 | subscribeStop = true; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/CommandHandle/Time.php: -------------------------------------------------------------------------------- 1 | getData(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/CommandHandle/Ttl.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | 18 | 19 | 20 | 21 | $command = [CommandConst::TTL,$key]; 22 | $commandData = array_merge($command,$data); 23 | return $commandData; 24 | } 25 | 26 | 27 | public function handelRecv(Response $recv) 28 | { 29 | return $recv->getData(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/CommandHandle/Type.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | 18 | 19 | 20 | 21 | $command = [CommandConst::TYPE,$key]; 22 | $commandData = array_merge($command,$data); 23 | return $commandData; 24 | } 25 | 26 | 27 | public function handelRecv(Response $recv) 28 | { 29 | return $recv->getData(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/CommandHandle/UnWatch.php: -------------------------------------------------------------------------------- 1 | getData(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/CommandHandle/Unsubscribe.php: -------------------------------------------------------------------------------- 1 | getData(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/CommandHandle/Watch.php: -------------------------------------------------------------------------------- 1 | 4 | */ 5 | 6 | 7 | namespace EasySwoole\Redis\CommandHandle; 8 | 9 | 10 | use EasySwoole\Redis\CommandConst; 11 | use EasySwoole\Redis\Response; 12 | 13 | class XAck extends AbstractCommandHandle 14 | { 15 | protected $commandName = 'XACK'; 16 | 17 | public function handelCommandData(...$data) 18 | { 19 | $key = array_shift($data); 20 | $group = array_shift($data); 21 | $ids = array_shift($data); 22 | $this->setClusterExecClientByKey($key); 23 | 24 | $command = [CommandConst::XACK, $key, $group]; 25 | 26 | $commandData = array_merge($command, $ids); 27 | 28 | return $commandData; 29 | } 30 | 31 | 32 | public function handelRecv(Response $recv) 33 | { 34 | return $recv->getData(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/CommandHandle/XAdd.php: -------------------------------------------------------------------------------- 1 | 4 | */ 5 | 6 | 7 | namespace EasySwoole\Redis\CommandHandle; 8 | 9 | 10 | use EasySwoole\Redis\CommandConst; 11 | use EasySwoole\Redis\Response; 12 | 13 | class XAdd extends AbstractCommandHandle 14 | { 15 | protected $commandName = 'XADD'; 16 | 17 | public function handelCommandData(...$data) 18 | { 19 | $key = array_shift($data); 20 | $id = array_shift($data); 21 | $messages = array_shift($data); 22 | $maxLen = array_shift($data); 23 | $isApproximate = array_shift($data); 24 | $this->setClusterExecClientByKey($key); 25 | 26 | $commandData = [CommandConst::XADD, $key]; 27 | 28 | if (!is_null($maxLen) && is_int($maxLen)) { 29 | if ($isApproximate) { 30 | $commandData = array_merge($commandData, ['MAXLEN', '~', $maxLen]); 31 | } else { 32 | $commandData = array_merge($commandData, ['MAXLEN', $maxLen]); 33 | } 34 | } 35 | 36 | $commandData = array_merge($commandData, [$id]); 37 | 38 | foreach ($messages as $k => $v) { 39 | $commandData = array_merge($commandData, [$k, $v]); 40 | } 41 | return $commandData; 42 | } 43 | 44 | public function handelRecv(Response $recv) 45 | { 46 | return $recv->getData(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/CommandHandle/XClaim.php: -------------------------------------------------------------------------------- 1 | 4 | */ 5 | 6 | 7 | namespace EasySwoole\Redis\CommandHandle; 8 | 9 | 10 | use EasySwoole\Redis\CommandConst; 11 | use EasySwoole\Redis\Response; 12 | 13 | class XClaim extends AbstractCommandHandle 14 | { 15 | protected $commandName = 'XCLAIM'; 16 | 17 | public function handelCommandData(...$data) 18 | { 19 | $key = array_shift($data); 20 | $group = array_shift($data); 21 | $consumer = array_shift($data); 22 | $minIdleTime = array_shift($data); 23 | $ids = array_shift($data); 24 | $options = array_shift($data); 25 | $this->setClusterExecClientByKey($key); 26 | 27 | $command = [CommandConst::XCLAIM, $key, $group, $consumer, $minIdleTime]; 28 | $commandData = array_merge($command, $ids); 29 | 30 | foreach ($options as $k => $option) { 31 | $commandData = array_merge($commandData, [$key, $option]); 32 | } 33 | 34 | return $commandData; 35 | } 36 | 37 | public function handelRecv(Response $recv) 38 | { 39 | $data = $recv->getData(); 40 | if (!is_array($data)) return false; 41 | 42 | $result = []; 43 | foreach ($data as $item) { 44 | $id = $item[0]; 45 | $values = $item[1]; 46 | $result[$id] = array_combine( 47 | array_filter($values, function ($index) { 48 | return (!($index & 1)); 49 | }, ARRAY_FILTER_USE_KEY), 50 | array_filter($values, function ($index) { 51 | return ($index & 1); 52 | }, ARRAY_FILTER_USE_KEY) 53 | ); 54 | } 55 | return $result; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/CommandHandle/XDel.php: -------------------------------------------------------------------------------- 1 | 4 | */ 5 | 6 | 7 | namespace EasySwoole\Redis\CommandHandle; 8 | 9 | 10 | use EasySwoole\Redis\CommandConst; 11 | use EasySwoole\Redis\Response; 12 | 13 | class XDel extends AbstractCommandHandle 14 | { 15 | protected $commandName = 'XLEN'; 16 | 17 | public function handelCommandData(...$data) 18 | { 19 | $key = array_shift($data); 20 | $ids = array_shift($data); 21 | $this->setClusterExecClientByKey($key); 22 | 23 | $command = [CommandConst::XDEL, $key]; 24 | $commandData = array_merge($command, $ids); 25 | return $commandData; 26 | } 27 | 28 | public function handelRecv(Response $recv) 29 | { 30 | return $recv->getData(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/CommandHandle/XGroup.php: -------------------------------------------------------------------------------- 1 | 4 | */ 5 | 6 | 7 | namespace EasySwoole\Redis\CommandHandle; 8 | 9 | 10 | use EasySwoole\Redis\CommandConst; 11 | use EasySwoole\Redis\Response; 12 | 13 | class XGroup extends AbstractCommandHandle 14 | { 15 | protected $commandName = 'XGROUP'; 16 | 17 | public function handelCommandData(...$data) 18 | { 19 | $operation = array_shift($data); 20 | $key = array_shift($data); 21 | $group = array_shift($data); 22 | $msgId = array_shift($data); 23 | $mkStream = array_shift($data); 24 | $this->setClusterExecClientByKey($key); 25 | 26 | $command = [CommandConst::XGROUP]; 27 | switch ($operation) { 28 | case 'CREATE': 29 | { 30 | $commandData = array_merge($command, [$operation, $key, $group, $msgId]); 31 | if ($mkStream) $commandData = array_merge($commandData, ['MKSTREAM']); 32 | break; 33 | } 34 | case 'SETID': 35 | case 'DELCONSUMER': 36 | { 37 | $commandData = array_merge($command, [$operation, $key, $group, $msgId]); 38 | break; 39 | } 40 | case 'DESTROY': 41 | { 42 | $commandData = array_merge($command, [$operation, $key, $group]); 43 | break; 44 | } 45 | case 'HELP': 46 | { 47 | $commandData = array_merge($command, [$operation]); 48 | break; 49 | } 50 | default: 51 | { 52 | $commandData = $command; 53 | break; 54 | } 55 | } 56 | 57 | return $commandData; 58 | } 59 | 60 | public function handelRecv(Response $recv) 61 | { 62 | $data = $recv->getData(); 63 | if ($data === 'OK') { 64 | return true; 65 | } 66 | 67 | return $data; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/CommandHandle/XInfo.php: -------------------------------------------------------------------------------- 1 | 4 | */ 5 | 6 | 7 | namespace EasySwoole\Redis\CommandHandle; 8 | 9 | 10 | use EasySwoole\Redis\CommandConst; 11 | use EasySwoole\Redis\Response; 12 | 13 | class XInfo extends AbstractCommandHandle 14 | { 15 | protected $commandName = 'XINFO'; 16 | 17 | public function handelCommandData(...$data) 18 | { 19 | $operation = array_shift($data); 20 | $key = array_shift($data); 21 | $group = array_shift($data); 22 | $this->setClusterExecClientByKey($key); 23 | 24 | $command = [CommandConst::XINFO]; 25 | 26 | switch ($operation) { 27 | case 'STREAM': 28 | case 'GROUPS': 29 | { 30 | $commandData = array_merge($command, [$operation, $key]); 31 | break; 32 | } 33 | case 'CONSUMERS': 34 | { 35 | $commandData = array_merge($command, [$operation, $key, $group]); 36 | break; 37 | } 38 | default: 39 | { 40 | $commandData = $command; 41 | break; 42 | } 43 | } 44 | 45 | return $commandData; 46 | } 47 | 48 | public function handelRecv(Response $recv) 49 | { 50 | $data = $recv->getData(); 51 | if (!is_array($data)) return false; 52 | 53 | $result = []; 54 | if (count($data) == 14) { 55 | for ($i = 0; $i < 14;) { 56 | $result[$data[$i]] = $data[$i + 1]; 57 | $i += 2; 58 | } 59 | 60 | $firstEntryKey = $result['first-entry'][0] ?? ''; 61 | $firstEntryValues = $result['first-entry'][1] ?? ''; 62 | if (is_array($result['first-entry'])) { 63 | $result['first-entry'] = [ 64 | $firstEntryKey => array_combine( 65 | array_filter($firstEntryValues, function ($index) { 66 | return (!($index & 1)); 67 | }, ARRAY_FILTER_USE_KEY), 68 | array_filter($firstEntryValues, function ($index) { 69 | return ($index & 1); 70 | }, ARRAY_FILTER_USE_KEY)) 71 | ]; 72 | } 73 | 74 | $lastEntryKey = $result['last-entry'][0] ?? ''; 75 | $lastEntryValues = $result['last-entry'][1] ?? ''; 76 | if (is_array($result['last-entry'])) { 77 | $result['last-entry'] = [ 78 | $lastEntryKey => array_combine( 79 | array_filter($lastEntryValues, function ($index) { 80 | return (!($index & 1)); 81 | }, ARRAY_FILTER_USE_KEY), 82 | array_filter($lastEntryValues, function ($index) { 83 | return ($index & 1); 84 | }, ARRAY_FILTER_USE_KEY)) 85 | ]; 86 | } 87 | } else { 88 | foreach ($data as $group) { 89 | $result[] = array_combine( 90 | array_filter($group, function ($index) { 91 | return (!($index & 1)); 92 | }, ARRAY_FILTER_USE_KEY), 93 | array_filter($group, function ($index) { 94 | return ($index & 1); 95 | }, ARRAY_FILTER_USE_KEY)); 96 | } 97 | } 98 | 99 | if (empty($result)) return false; 100 | return $result; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/CommandHandle/XLen.php: -------------------------------------------------------------------------------- 1 | 4 | */ 5 | 6 | 7 | namespace EasySwoole\Redis\CommandHandle; 8 | 9 | 10 | use EasySwoole\Redis\CommandConst; 11 | use EasySwoole\Redis\Response; 12 | 13 | class XLen extends AbstractCommandHandle 14 | { 15 | protected $commandName = 'XLEN'; 16 | 17 | public function handelCommandData(...$data) 18 | { 19 | $key = array_shift($data); 20 | $this->setClusterExecClientByKey($key); 21 | 22 | $commandData = [CommandConst::XLEN, $key]; 23 | return $commandData; 24 | } 25 | 26 | public function handelRecv(Response $recv) 27 | { 28 | return $recv->getData(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/CommandHandle/XPending.php: -------------------------------------------------------------------------------- 1 | 4 | */ 5 | 6 | 7 | namespace EasySwoole\Redis\CommandHandle; 8 | 9 | 10 | use EasySwoole\Redis\CommandConst; 11 | use EasySwoole\Redis\Response; 12 | 13 | class XPending extends AbstractCommandHandle 14 | { 15 | protected $commandName = 'XPENDING'; 16 | 17 | public function handelCommandData(...$data) 18 | { 19 | $stream = array_shift($data); 20 | $group = array_shift($data); 21 | $start = array_shift($data); 22 | $end = array_shift($data); 23 | $count = array_shift($data); 24 | $consumer = array_shift($data); 25 | $this->setClusterExecClientByKey($stream); 26 | 27 | $commandData = [CommandConst::XPENDING, $stream, $group, $start, $end, $count, $consumer]; 28 | return array_filter($commandData); 29 | } 30 | 31 | public function handelRecv(Response $recv) 32 | { 33 | return $recv->getData(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/CommandHandle/XRange.php: -------------------------------------------------------------------------------- 1 | 4 | */ 5 | 6 | 7 | namespace EasySwoole\Redis\CommandHandle; 8 | 9 | 10 | use EasySwoole\Redis\CommandConst; 11 | use EasySwoole\Redis\Response; 12 | 13 | class XRange extends AbstractCommandHandle 14 | { 15 | protected $commandName = 'XRANGE'; 16 | 17 | public function handelCommandData(...$data) 18 | { 19 | $key = array_shift($data); 20 | $start = array_shift($data); 21 | $end = array_shift($data); 22 | $count = array_shift($data); 23 | $this->setClusterExecClientByKey($key); 24 | 25 | $commandData = [CommandConst::XRANGE, $key, $start, $end]; 26 | if (!is_null($count) && is_int($count)) $commandData = array_merge($commandData, ['COUNT', $count]); 27 | return $commandData; 28 | } 29 | 30 | public function handelRecv(Response $recv) 31 | { 32 | $data = $recv->getData(); 33 | 34 | $result = []; 35 | if (!is_array($data)) return false; 36 | 37 | foreach ($data as $v) { 38 | $id = $v[0]; 39 | $values = $v[1]; 40 | 41 | $result[$id] = array_combine( 42 | array_filter($values, function ($index) { 43 | return (!($index & 1)); 44 | }, ARRAY_FILTER_USE_KEY), 45 | array_filter($values, function ($index) { 46 | return ($index & 1); 47 | }, ARRAY_FILTER_USE_KEY) 48 | ); 49 | } 50 | 51 | if (empty($result)) return false; 52 | return $result; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/CommandHandle/XRead.php: -------------------------------------------------------------------------------- 1 | 4 | */ 5 | 6 | 7 | namespace EasySwoole\Redis\CommandHandle; 8 | 9 | 10 | use EasySwoole\Redis\CommandConst; 11 | use EasySwoole\Redis\Response; 12 | 13 | class XRead extends AbstractCommandHandle 14 | { 15 | protected $commandName = 'XREAD'; 16 | 17 | public function handelCommandData(...$data) 18 | { 19 | $streams = array_shift($data); 20 | $count = array_shift($data); 21 | $block = array_shift($data); 22 | $commandData = [CommandConst::XREAD]; 23 | 24 | if (!is_null($count) && is_int($count)) { 25 | $commandData = array_merge($commandData, ['COUNT', $count]); 26 | } 27 | 28 | if (!is_null($block) && is_int($block)) { 29 | $commandData = array_merge($commandData, ['BLOCK', $block]); 30 | } 31 | 32 | return array_merge($commandData, ['STREAMS'], array_keys($streams), array_values($streams)); 33 | } 34 | 35 | public function handelRecv(Response $recv) 36 | { 37 | $data = $recv->getData(); 38 | $result = []; 39 | if (!is_array($data)) return false; 40 | 41 | foreach ($data as $stream) { 42 | $key = $stream[0]; 43 | $items = $stream[1]; 44 | foreach ($items as $item) { 45 | $id = $item[0]; 46 | $values = $item[1]; 47 | $result[$key][$id] = array_combine( 48 | array_filter($values, function ($index) { 49 | return (!($index & 1)); 50 | }, ARRAY_FILTER_USE_KEY), 51 | array_filter($values, function ($index) { 52 | return ($index & 1); 53 | }, ARRAY_FILTER_USE_KEY) 54 | ); 55 | } 56 | } 57 | 58 | return $result; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/CommandHandle/XReadGroup.php: -------------------------------------------------------------------------------- 1 | 4 | */ 5 | 6 | 7 | namespace EasySwoole\Redis\CommandHandle; 8 | 9 | 10 | use EasySwoole\Redis\CommandConst; 11 | use EasySwoole\Redis\Response; 12 | 13 | class XReadGroup extends AbstractCommandHandle 14 | { 15 | protected $commandName = 'XREAD'; 16 | 17 | public function handelCommandData(...$data) 18 | { 19 | $group = array_shift($data); 20 | $consumer = array_shift($data); 21 | $streams = array_shift($data); 22 | $count = array_shift($data); 23 | $block = array_shift($data); 24 | $commandData = [CommandConst::XREADGROUP, 'GROUP', $group, $consumer]; 25 | 26 | if (!is_null($count) && is_int($count)) { 27 | $commandData = array_merge($commandData, ['COUNT', $count]); 28 | } 29 | 30 | if (!is_null($block) && is_int($block)) { 31 | $commandData = array_merge($commandData, ['BLOCK', $block]); 32 | } 33 | 34 | return array_merge($commandData, ['STREAMS'], array_keys($streams), array_values($streams)); 35 | } 36 | 37 | public function handelRecv(Response $recv) 38 | { 39 | $data = $recv->getData(); 40 | $result = []; 41 | if (!is_array($data)) return false; 42 | 43 | foreach ($data as $stream) { 44 | $key = $stream[0]; 45 | $items = $stream[1]; 46 | foreach ($items as $item) { 47 | $id = $item[0]; 48 | $values = $item[1]; 49 | $result[$key][$id] = array_combine( 50 | array_filter($values, function ($index) { 51 | return (!($index & 1)); 52 | }, ARRAY_FILTER_USE_KEY), 53 | array_filter($values, function ($index) { 54 | return ($index & 1); 55 | }, ARRAY_FILTER_USE_KEY) 56 | ); 57 | } 58 | } 59 | 60 | return $result; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/CommandHandle/XRevRange.php: -------------------------------------------------------------------------------- 1 | 4 | */ 5 | 6 | 7 | namespace EasySwoole\Redis\CommandHandle; 8 | 9 | 10 | use EasySwoole\Redis\CommandConst; 11 | use EasySwoole\Redis\Response; 12 | 13 | class XRevRange extends AbstractCommandHandle 14 | { 15 | protected $commandName = 'XREVRANGE'; 16 | 17 | public function handelCommandData(...$data) 18 | { 19 | $key = array_shift($data); 20 | $end = array_shift($data); 21 | $start = array_shift($data); 22 | $count = array_shift($data); 23 | $this->setClusterExecClientByKey($key); 24 | 25 | $commandData = [CommandConst::XREVRANGE, $key, $end, $start]; 26 | if (!is_null($count) && is_int($count)) $commandData = array_merge($commandData, ['COUNT', $count]); 27 | return $commandData; 28 | } 29 | 30 | public function handelRecv(Response $recv) 31 | { 32 | $data = $recv->getData(); 33 | 34 | $result = []; 35 | if (!is_array($data)) return false; 36 | 37 | foreach ($data as $v) { 38 | $id = $v[0]; 39 | $values = $v[1]; 40 | 41 | $result[$id] = array_combine( 42 | array_filter($values, function ($index) { 43 | return (!($index & 1)); 44 | }, ARRAY_FILTER_USE_KEY), 45 | array_filter($values, function ($index) { 46 | return ($index & 1); 47 | }, ARRAY_FILTER_USE_KEY) 48 | ); 49 | } 50 | 51 | if (empty($result)) return false; 52 | return $result; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/CommandHandle/XTrim.php: -------------------------------------------------------------------------------- 1 | 4 | */ 5 | 6 | 7 | namespace EasySwoole\Redis\CommandHandle; 8 | 9 | 10 | use EasySwoole\Redis\CommandConst; 11 | use EasySwoole\Redis\Response; 12 | 13 | class XTrim extends AbstractCommandHandle 14 | { 15 | protected $commandName = 'XTRIM'; 16 | 17 | public function handelCommandData(...$data) 18 | { 19 | $key = array_shift($data); 20 | $maxLen = array_shift($data); 21 | $isApproximate = array_shift($data); 22 | $this->setClusterExecClientByKey($key); 23 | 24 | $commandData = [CommandConst::XTRIM, $key]; 25 | if (!is_null($maxLen) && is_int($maxLen)) { 26 | if ($isApproximate) { 27 | $commandData = array_merge($commandData, ['MAXLEN', '~', $maxLen]); 28 | } else { 29 | $commandData = array_merge($commandData, ['MAXLEN', $maxLen]); 30 | } 31 | } 32 | 33 | return $commandData; 34 | } 35 | 36 | public function handelRecv(Response $recv) 37 | { 38 | return $recv->getData(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/CommandHandle/ZAdd.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 18 | $score1 = array_shift($data); 19 | $member1 = array_shift($data); 20 | 21 | $member1 = $this->serialize($member1); 22 | $members = []; 23 | foreach ($data as $k => $va) { 24 | if ($k % 2 != 0) { 25 | $members[$k] = $this->serialize($va); 26 | }else{ 27 | $members[$k] = $va; 28 | } 29 | } 30 | 31 | $command = [CommandConst::ZADD, $key, $score1, $member1]; 32 | $commandData = array_merge($command, $members); 33 | return $commandData; 34 | } 35 | 36 | 37 | public function handelRecv(Response $recv) 38 | { 39 | return $recv->getData(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/CommandHandle/ZCard.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | 18 | 19 | 20 | 21 | $command = [CommandConst::ZCARD,$key]; 22 | $commandData = array_merge($command,$data); 23 | return $commandData; 24 | } 25 | 26 | 27 | public function handelRecv(Response $recv) 28 | { 29 | return $recv->getData(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/CommandHandle/ZCount.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | $min=array_shift($data); 18 | $max=array_shift($data); 19 | 20 | 21 | 22 | 23 | $command = [CommandConst::ZCOUNT,$key,$min,$max]; 24 | $commandData = array_merge($command,$data); 25 | return $commandData; 26 | } 27 | 28 | 29 | public function handelRecv(Response $recv) 30 | { 31 | return $recv->getData(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/CommandHandle/ZInCrBy.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 15 | $increment = array_shift($data); 16 | $member = array_shift($data); 17 | $member = $this->serialize($member); 18 | $command = [CommandConst::ZINCRBY, $key, $increment, $member]; 19 | $commandData = array_merge($command, $data); 20 | 21 | return $commandData; 22 | } 23 | 24 | public function handelRecv(Response $recv) { 25 | return $recv->getData(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/CommandHandle/ZInTerStore.php: -------------------------------------------------------------------------------- 1 | 0 && $keysCount !== $weightsCount) { 24 | throw new RedisClusterException('WEIGHTS and keys array should be the same size!'); 25 | } 26 | 27 | $command = [CommandConst::ZINTERSTORE, $destination, $keysCount]; 28 | foreach ($keys as $k => $key) { 29 | $command[] = $key; 30 | } 31 | if ($weightsCount > 0) { 32 | $command[] = 'WEIGHTS'; 33 | } 34 | foreach ($weights as $k => $weight) { 35 | $command[] = $weight; 36 | } 37 | $command[] = 'AGGREGATE'; 38 | $command[] = $aggregate; 39 | $commandData = array_merge($command); 40 | return $commandData; 41 | } 42 | 43 | 44 | public function handelRecv(Response $recv) 45 | { 46 | return $recv->getData(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/CommandHandle/ZLexCount.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | $min=array_shift($data); 18 | $max=array_shift($data); 19 | 20 | 21 | 22 | 23 | $command = [CommandConst::ZLEXCOUNT,$key,$min,$max]; 24 | $commandData = array_merge($command,$data); 25 | return $commandData; 26 | } 27 | 28 | 29 | public function handelRecv(Response $recv) 30 | { 31 | return $recv->getData(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/CommandHandle/ZPopMax.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 16 | $count = array_shift($data); 17 | 18 | $commandData = [CommandConst::ZPOPMAX, $key]; 19 | if (!is_null($count) && $count > 1) { 20 | $commandData[] = $count; 21 | } 22 | 23 | return $commandData; 24 | } 25 | 26 | 27 | public function handelRecv(Response $recv) 28 | { 29 | $data = $recv->getData(); 30 | $result = []; 31 | 32 | foreach ($data as $index => $val) { 33 | if ($index % 2 == 1) { 34 | $result[$this->unSerialize($data[$index - 1])] = $val; 35 | } 36 | } 37 | 38 | return $result; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/CommandHandle/ZPopMin.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 16 | $count = array_shift($data); 17 | 18 | $commandData = [CommandConst::ZPOPMIN, $key]; 19 | if (!is_null($count) && $count > 1) { 20 | $commandData[] = $count; 21 | } 22 | 23 | return $commandData; 24 | } 25 | 26 | 27 | public function handelRecv(Response $recv) 28 | { 29 | $data = $recv->getData(); 30 | $result = []; 31 | 32 | foreach ($data as $index => $val) { 33 | if ($index % 2 == 1) { 34 | $result[$this->unSerialize($data[$index - 1])] = $val; 35 | } 36 | } 37 | 38 | return $result; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/CommandHandle/ZRange.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 19 | $start = array_shift($data); 20 | $stop = array_shift($data); 21 | $withScores = array_shift($data); 22 | $this->withScores = $withScores; 23 | $command = [CommandConst::ZRANGE, $key, $start, $stop,]; 24 | if ($withScores == true) { 25 | $command[] = 'WITHSCORES'; 26 | } 27 | $commandData = array_merge($command); 28 | return $commandData; 29 | } 30 | 31 | 32 | public function handelRecv(Response $recv) 33 | { 34 | $data = $recv->getData(); 35 | if ($this->withScores == true) { 36 | $result = []; 37 | foreach ($data as $k => $va) { 38 | if ($k % 2 == 0) { 39 | $result[$this->unSerialize($va)] = 0; 40 | } else { 41 | $result[$this->unSerialize($data[$k - 1])] = $va; 42 | } 43 | } 44 | } else { 45 | $result = []; 46 | foreach ($data as $k => $va) { 47 | $result[$k] = $this->unSerialize($va); 48 | } 49 | } 50 | 51 | return $result; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/CommandHandle/ZRangeByLex.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | $min=array_shift($data); 18 | $max=array_shift($data); 19 | 20 | $command = [CommandConst::ZRANGEBYLEX,$key,$min,$max]; 21 | $commandData = array_merge($command,$data); 22 | return $commandData; 23 | } 24 | 25 | 26 | public function handelRecv(Response $recv) 27 | { 28 | $data = $recv->getData(); 29 | foreach ($data as $key => $va) { 30 | $data[$key] = $this->unSerialize($va); 31 | } 32 | 33 | return $data; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/CommandHandle/ZRangeByScore.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 19 | $min = array_shift($data); 20 | $max = array_shift($data); 21 | $options = array_shift($data); 22 | $this->withScores = $options['withScores']??false; 23 | if ($this->withScores == true) { 24 | $command = [CommandConst::ZRANGEBYSCORE, $key, $min, $max, 'WITHSCORES',]; 25 | } else { 26 | $command = [CommandConst::ZRANGEBYSCORE, $key, $min, $max,]; 27 | } 28 | if (!empty($options['limit'])&&is_array($options['limit'])){ 29 | $command[] = 'LIMIT'; 30 | $command[]= $options['limit'][0]; 31 | $command[]= $options['limit'][1]; 32 | } 33 | 34 | $commandData = array_merge($command); 35 | return $commandData; 36 | } 37 | 38 | 39 | public function handelRecv(Response $recv) 40 | { 41 | $data = $recv->getData(); 42 | if ($this->withScores == true) { 43 | $result = []; 44 | foreach ($data as $k => $va) { 45 | if ($k % 2 == 0) { 46 | $result[$this->unSerialize($va)] = 0; 47 | } else { 48 | $result[$this->unSerialize($data[$k - 1])] = $va; 49 | } 50 | } 51 | } else { 52 | $result = []; 53 | foreach ($data as $k => $va) { 54 | $result[$k] = $this->unSerialize($va); 55 | } 56 | } 57 | return $result; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/CommandHandle/ZRank.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 18 | $member = array_shift($data); 19 | 20 | 21 | $member = $this->serialize($member); 22 | 23 | 24 | $command = [CommandConst::ZRANK, $key, $member]; 25 | $commandData = array_merge($command, $data); 26 | return $commandData; 27 | } 28 | 29 | 30 | public function handelRecv(Response $recv) 31 | { 32 | return $recv->getData(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/CommandHandle/ZRem.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 18 | $member = array_shift($data); 19 | 20 | $members = []; 21 | $member = $this->serialize($member); 22 | foreach ($data as $k => $va) { 23 | $members[$k] = $this->serialize($va); 24 | } 25 | 26 | $command = [CommandConst::ZREM, $key, $member]; 27 | $commandData = array_merge($command, $members); 28 | return $commandData; 29 | } 30 | 31 | 32 | public function handelRecv(Response $recv) 33 | { 34 | return $recv->getData(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/CommandHandle/ZRemRangeByLex.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | $min=array_shift($data); 18 | $max=array_shift($data); 19 | 20 | 21 | 22 | 23 | $command = [CommandConst::ZREMRANGEBYLEX,$key,$min,$max]; 24 | $commandData = array_merge($command,$data); 25 | return $commandData; 26 | } 27 | 28 | 29 | public function handelRecv(Response $recv) 30 | { 31 | return $recv->getData(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/CommandHandle/ZRemRangeByRank.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | $start=array_shift($data); 18 | $stop=array_shift($data); 19 | 20 | 21 | 22 | 23 | $command = [CommandConst::ZREMRANGEBYRANK,$key,$start,$stop]; 24 | $commandData = array_merge($command,$data); 25 | return $commandData; 26 | } 27 | 28 | 29 | public function handelRecv(Response $recv) 30 | { 31 | return $recv->getData(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/CommandHandle/ZRemRangeByScore.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 17 | $min=array_shift($data); 18 | $max=array_shift($data); 19 | 20 | 21 | $command = [CommandConst::ZREMRANGEBYSCORE,$key,$min,$max]; 22 | $commandData = array_merge($command,$data); 23 | return $commandData; 24 | } 25 | 26 | 27 | public function handelRecv(Response $recv) 28 | { 29 | return $recv->getData(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/CommandHandle/ZRevRange.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 19 | $start = array_shift($data); 20 | $stop = array_shift($data); 21 | $withScores = array_shift($data); 22 | $this->withScores = $withScores; 23 | 24 | $command = [CommandConst::ZREVRANGE, $key, $start, $stop]; 25 | if ($withScores == true) { 26 | $command[] = 'WITHSCORES'; 27 | } 28 | $commandData = array_merge($command); 29 | return $commandData; 30 | } 31 | 32 | 33 | public function handelRecv(Response $recv) 34 | { 35 | $data = $recv->getData(); 36 | if ($this->withScores == true) { 37 | $result = []; 38 | foreach ($data as $k => $va) { 39 | if ($k % 2 == 0) { 40 | $result[$this->unSerialize($va)] = 0; 41 | } else { 42 | $result[$this->unSerialize($data[$k - 1])] = $va; 43 | } 44 | } 45 | } else { 46 | $result = []; 47 | foreach ($data as $k => $va) { 48 | $result[$k] = $this->unSerialize($va); 49 | } 50 | } 51 | return $result; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/CommandHandle/ZRevRangeByScore.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 19 | $max = array_shift($data); 20 | $min = array_shift($data); 21 | $options = array_shift($data); 22 | $this->withScores = $options['withScores']??false; 23 | 24 | $command = [CommandConst::ZREVRANGEBYSCORE, $key, $max, $min]; 25 | if ($this->withScores == true) { 26 | $command[] = 'WITHSCORES'; 27 | } 28 | if (!empty($options['limit'])&&is_array($options['limit'])){ 29 | $command[] = 'LIMIT'; 30 | $command[]= $options['limit'][0]; 31 | $command[]= $options['limit'][1]; 32 | } 33 | $commandData = array_merge($command); 34 | return $commandData; 35 | } 36 | 37 | 38 | public function handelRecv(Response $recv) 39 | { 40 | $data = $recv->getData(); 41 | if ($this->withScores == true) { 42 | $result = []; 43 | foreach ($data as $k => $va) { 44 | if ($k % 2 == 0) { 45 | $result[$this->unSerialize($va)] = 0; 46 | } else { 47 | $result[$this->unSerialize($data[$k - 1])] = $va; 48 | } 49 | } 50 | } else { 51 | $result = []; 52 | foreach ($data as $k => $va) { 53 | $result[$k] = $this->unSerialize($va); 54 | } 55 | } 56 | return $result; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/CommandHandle/ZRevRank.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 18 | $member = array_shift($data); 19 | 20 | 21 | $member = $this->serialize($member); 22 | 23 | 24 | $command = [CommandConst::ZREVRANK, $key, $member]; 25 | $commandData = array_merge($command, $data); 26 | return $commandData; 27 | } 28 | 29 | 30 | public function handelRecv(Response $recv) 31 | { 32 | return $recv->getData(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/CommandHandle/ZScan.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 16 | $cursor=array_shift($data); 17 | $pattern=array_shift($data); 18 | $count=array_shift($data); 19 | $command = [CommandConst::ZSCAN,$key,$cursor]; 20 | if ($pattern!==null){ 21 | $command[] = 'MATCH'; 22 | $command[] = $pattern; 23 | } 24 | if ($count!==null){ 25 | $command[] = 'COUNT'; 26 | $command[] = $count; 27 | } 28 | $commandData = $command; 29 | return $commandData; 30 | } 31 | 32 | 33 | public function handelRecv(Response $recv) 34 | { 35 | $data = $recv->getData(); 36 | $result = []; 37 | foreach ($data[1] as $k=>$value){ 38 | if ($k%2==0){ 39 | $result[$this->unSerialize($value)] = []; 40 | }else{ 41 | $result[$this->unSerialize($data[1][$k-1])]=$value; 42 | } 43 | } 44 | $data[1] = $result; 45 | return $data; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/CommandHandle/ZScore.php: -------------------------------------------------------------------------------- 1 | setClusterExecClientByKey($key); 18 | $member = array_shift($data); 19 | 20 | $member = $this->serialize($member); 21 | 22 | $command = [CommandConst::ZSCORE, $key, $member]; 23 | $commandData = array_merge($command, $data); 24 | return $commandData; 25 | } 26 | 27 | 28 | public function handelRecv(Response $recv) 29 | { 30 | return $recv->getData(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/CommandHandle/ZUnionStore.php: -------------------------------------------------------------------------------- 1 | 0&&$keysCount !== $weightsCount) { 23 | throw new RedisClusterException('WEIGHTS and keys array should be the same size!'); 24 | } 25 | 26 | $command = [CommandConst::ZUNIONSTORE, $destination, $keysCount]; 27 | foreach ($keys as $k => $key) { 28 | $command[] = $key; 29 | } 30 | if ($weightsCount>0){ 31 | $command[] = 'WEIGHTS'; 32 | } 33 | foreach ($weights as $k => $weight) { 34 | $command[] = $weight; 35 | } 36 | $command[] = 'AGGREGATE'; 37 | $command[] = $aggregate; 38 | $commandData = array_merge($command); 39 | return $commandData; 40 | } 41 | 42 | 43 | public function handelRecv(Response $recv) 44 | { 45 | return $recv->getData(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/CrcHash.php: -------------------------------------------------------------------------------- 1 | > 8) ^ ord($ptr[$i]))] ^ (($crc << 8) & 0x00FFFF); 26 | return $crc % 16384; 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /src/Exception/RedisClusterException.php: -------------------------------------------------------------------------------- 1 | message = $redisErrorMsg; 19 | $this->redisErrorMsg = $redisErrorMsg; 20 | $this->redisErrorCode = $redisErrorCode; 21 | } 22 | 23 | /** 24 | * @return int 25 | */ 26 | public function getRedisErrorCode() 27 | { 28 | return $this->redisErrorCode; 29 | } 30 | 31 | /** 32 | * @return mixed 33 | */ 34 | public function getRedisErrorMsg() 35 | { 36 | return $this->redisErrorMsg; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Pipe.php: -------------------------------------------------------------------------------- 1 | commandLog; 31 | } 32 | 33 | /** 34 | * @param array $commandLog 35 | */ 36 | public function setCommandLog(array $commandLog): void 37 | { 38 | $this->commandLog = $commandLog; 39 | } 40 | 41 | public function addCommand($command) 42 | { 43 | $this->commandLog[] = $command; 44 | } 45 | 46 | /** 47 | * @return bool 48 | */ 49 | public function isStartPipe(): bool 50 | { 51 | return $this->isStartPipe; 52 | } 53 | 54 | /** 55 | * @param bool $isStartPipe 56 | */ 57 | public function setIsStartPipe(bool $isStartPipe): void 58 | { 59 | $this->isStartPipe = $isStartPipe; 60 | } 61 | 62 | } -------------------------------------------------------------------------------- /src/RedisTransaction.php: -------------------------------------------------------------------------------- 1 | commandLog; 31 | } 32 | 33 | /** 34 | * @param array $commandLog 35 | */ 36 | public function setCommandLog(array $commandLog): void 37 | { 38 | $this->commandLog = $commandLog; 39 | } 40 | 41 | function addCommand($command) 42 | { 43 | $this->commandLog[] = $command; 44 | } 45 | 46 | /** 47 | * @return bool 48 | */ 49 | public function isTransaction(): bool 50 | { 51 | return $this->isTransaction; 52 | } 53 | 54 | /** 55 | * @param bool $isTransaction 56 | */ 57 | public function setIsTransaction(bool $isTransaction): void 58 | { 59 | $this->isTransaction = $isTransaction; 60 | } 61 | } -------------------------------------------------------------------------------- /src/Response.php: -------------------------------------------------------------------------------- 1 | status; 23 | } 24 | 25 | /** 26 | * @param mixed $status 27 | */ 28 | public function setStatus($status): void 29 | { 30 | $this->status = $status; 31 | } 32 | 33 | /** 34 | * @return mixed 35 | */ 36 | public function getData() 37 | { 38 | return $this->data; 39 | } 40 | 41 | /** 42 | * @param mixed $data 43 | */ 44 | public function setData($data): void 45 | { 46 | $this->data = $data; 47 | } 48 | 49 | /** 50 | * @return mixed 51 | */ 52 | public function getMsg() 53 | { 54 | return $this->msg; 55 | } 56 | 57 | /** 58 | * @param mixed $msg 59 | */ 60 | public function setMsg($msg): void 61 | { 62 | $this->msg = $msg; 63 | } 64 | 65 | /** 66 | * @return mixed 67 | */ 68 | public function getErrorType() 69 | { 70 | return $this->errorType; 71 | } 72 | 73 | /** 74 | * @param mixed $errorType 75 | */ 76 | public function setErrorType($errorType): void 77 | { 78 | $this->errorType = $errorType; 79 | } 80 | } -------------------------------------------------------------------------------- /src/UnixSocketClient.php: -------------------------------------------------------------------------------- 1 | unixSocket = $unixSocket; 24 | $this->packageMaxLength = $packageMaxLength; 25 | } 26 | 27 | public function connect(float $timeout = 3.0): bool 28 | { 29 | if ($this->client == null) { 30 | $this->client = new \Swoole\Coroutine\Client(SWOOLE_UNIX_STREAM); 31 | $this->client->set([ 32 | 'open_eof_check' => true, 33 | 'package_eof' => "\r\n", 34 | 'package_max_length' => $this->packageMaxLength 35 | ]); 36 | } 37 | 38 | return $this->client->connect($this->unixSocket, null, $timeout); 39 | } 40 | } -------------------------------------------------------------------------------- /tests/EventTest.php: -------------------------------------------------------------------------------- 1 | REDIS_HOST, 33 | 'port' => REDIS_PORT, 34 | 'auth' => REDIS_AUTH, 35 | ]); 36 | $this->redis = new Redis($redisConfig); 37 | 38 | $this->redisCluster = new RedisCluster(new ClusterConfig(REDIS_CLUSTER_SERVER_LIST, [ 39 | 'auth' => REDIS_CLUSTER_AUTH, 40 | ])); 41 | 42 | } 43 | 44 | function testRedis(){ 45 | $redis = $this->redis; 46 | $redis->getConfig()->onBeforeEvent(function ($commandName,$commandData){ 47 | $this->assertEquals(CommandConst::SET,$commandName); 48 | $this->assertEquals('a',$commandData[0]); 49 | $this->assertEquals('1',$commandData[1]); 50 | }); 51 | $redis->getConfig()->onAfterEvent(function ($commandName,$commandData,$result){ 52 | $this->assertEquals(CommandConst::SET,$commandName); 53 | $this->assertEquals('a',$commandData[0]); 54 | $this->assertEquals('1',$commandData[1]); 55 | $this->assertEquals(true,$result); 56 | }); 57 | $redis->set('a',1); 58 | } 59 | 60 | function testCluster(){ 61 | $redis = $this->redisCluster; 62 | $redis->getConfig()->onBeforeEvent(function ($commandName,$commandData){ 63 | $this->assertEquals(CommandConst::SET,$commandName); 64 | $this->assertEquals('a',$commandData[0]); 65 | $this->assertEquals('1',$commandData[1]); 66 | }); 67 | $redis->getConfig()->onAfterEvent(function ($commandName,$commandData,$result){ 68 | $this->assertEquals(CommandConst::SET,$commandName); 69 | $this->assertEquals('a',$commandData[0]); 70 | $this->assertEquals('1',$commandData[1]); 71 | $this->assertEquals(true,$result); 72 | }); 73 | $redis->set('a',1); 74 | } 75 | 76 | function testPIPE(){ 77 | 78 | $redis = $this->redis; 79 | $redis->getConfig()->onBeforeEvent(function ($commandName,$commandData){ 80 | var_dump ($commandName,$commandData); 81 | $this->assertEquals(1,1); 82 | }); 83 | $redis->getConfig()->onAfterEvent(function ($commandName,$commandData,$result){ 84 | var_dump ($commandName,$commandData,$result); 85 | $this->assertEquals(1,1); 86 | }); 87 | $redis->startPipe(); 88 | $redis->set('a',1); 89 | $redis->get('a',1); 90 | $redis->execPipe(); 91 | } 92 | 93 | } 94 | --------------------------------------------------------------------------------