2017-09-16 17:20:03 2460次浏览 1条回答 0 悬赏 10 金钱

如题:
1.jpg

在使用sort函数的时候出错了,但是命令可以正常执行。求解。有大神可以讲下sort在使用by或者get的时候怎么填写参数就感激不尽了

补充于 2017-09-22 17:25

我在尝试了以后如果需要加倒叙人在后面逗号添加。
如:Yii::$app->redis->sort($daily_score_key, 'LIMIT', '0', '12','DESC');

最佳答案

  • 杨淇 发布于 2017-09-20 10:31 举报

    yii\redis\Connection 支持的命令中找到以下注释:

    'SORT', // key [BY pattern] [LIMIT offset count] [GET pattern [GET pattern ...]] [ASC|DESC] [ALPHA] [STORE destination] Sort the elements in a list, set or sorted set
    

    所有的这些命令都会通过下面这个方法执行:

    /**

     * Allows issuing all supported commands via magic methods.
     *
     * ```php
     * $redis->hmset(['test_collection', 'key1', 'val1', 'key2', 'val2'])
     * ```
     *
     * @param string $name name of the missing method to execute
     * @param array $params method call arguments
     * @return mixed
     */
    public function __call($name, $params)
    {
        $redisCommand = strtoupper(Inflector::camel2words($name, false));
        if (in_array($redisCommand, $this->redisCommands)) {
            return $this->executeCommand($name, $params);
        } else {
            return parent::__call($name, $params);
        }
    }
    
        public function executeCommand($name, $params = [])
        {
            $this->open();
    
            array_unshift($params, $name);
            $command = '*' . count($params) . "\r\n";
            foreach ($params as $arg) {
                $command .= '$' . mb_strlen($arg, '8bit') . "\r\n" . $arg . "\r\n";
            }
    
            \Yii::trace("Executing Redis Command: {$name}", __METHOD__);
            fwrite($this->_socket, $command);
    
            return $this->parseResponse(implode(' ', $params));
        }
    

    最终将命令拼成字符串执行,所以正确的写法是

    Yii::$app->redis->sort('keyName', 'LIMIT', '0', '1']);
    
    没有找到数据。
您需要登录后才可以回答。登录 | 立即注册
Loong
职场新人

Loong

注册时间:2017-09-16
最后登录:2018-11-19
在线时长:4小时25分
  • 粉丝1
  • 金钱50
  • 威望0
  • 积分90

热门问题