easyswoole 使用redis執行geoRadiusByMember Count無效修復

此BUG作者已更新:https://github.com/easy-swoole/redis/pull/23/files 

問題原因 ,geoRadiusByMember  參數列表如下,使用Count的時候需要帶上 Count  X 條數,例如需要5條就是 Count  5,

GEORADIUSBYMEMBER key member radius m|km|ft|mi [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT count] [ASC|DESC] [STORE key] [STOREDIST key]

而框架提供的方法 

geoRadiusByMember($key, $location, $radius, $unit, $withCoord, $withDist, $withHash, $count, $sort, $storeKey, $storeDistKey);

存在count參數,但是怎麼設置也沒有效果,設置數組還要報錯,跟蹤問題,定位

vendor/easyswoole/redis/src/Client.php文件方法,此處爲考慮到count這種特殊情況,

 

 public function sendCommand(array $commandList): bool
    {
        $argNum = count($commandList);
        $str = "*{$argNum}\r\n";
        foreach ($commandList as $value) {
            $len = strlen($value);
            $str = $str . '$' . "{$len}\r\n{$value}\r\n";
        }
        return $this->send($str);
    }

修改如下,即可正常返回

public function sendCommand(array $commandList): bool
    {
        $argNum = 0;
        foreach ($commandList as $data ){
            if(is_array($data)){
                $argNum  = $argNum  + (count($data) + 1);
            }else{
                $argNum ++;
            }            
        }
        $str = "*{$argNum}\r\n";
        foreach ($commandList as $value) {
            if(is_array($value)){
                foreach ($value as $key => $values) {
                    $len = strlen($key);
                    $str = $str . '$' . "{$len}\r\n{$key}\r\n";
                    
                    $len = strlen($values);
                    $str = $str . '$' . "{$len}\r\n{$values}\r\n";
                }
            }else{
                $len = strlen($value);
                $str = $str . '$' . "{$len}\r\n{$value}\r\n";
            }            
        }
        return $this->send($str);
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章