/**
  * ZADD key [NX|XX] [CH] [INCR] score member [score member ...]
  * Available since 1.2.0.
  * Time complexity: O(log(N)) for each item added, where N is the number of elements in the sorted set.
  * @link http://redis.io/commands/zadd
  *
  * @param string $key
  * @param array $members array(member => score [, member => score ...])
  * @param string|null $nx NX or XX
  * @param bool|false $ch
  * @param bool|false $incr
  * @return int|string
  */
 public function zadd($key, array $members, $nx = null, $ch = false, $incr = false)
 {
     $params = [$key];
     if ($nx) {
         $params[] = $nx;
     }
     if ($ch) {
         $params[] = 'CH';
     }
     if ($incr) {
         $params[] = 'INCR';
     }
     $params[] = Parameter::assocArrayFlip($members);
     return $this->returnCommand(['ZADD'], $params);
 }
 /**
  * SORT key [BY pattern] [LIMIT offset count] [GET pattern [GET pattern ...]] [ASC|DESC] [ALPHA] [STORE destination]
  * Available since 1.0.0.
  * Time complexity: O(N+M*log(M)) or O(N)
  * @link http://redis.io/commands/sort
  *
  * @param string $key
  * @param string|null $pattern
  * @param int|array|null $limit
  * @param string|string[]|null $patterns
  * @param bool|null $asc
  * @param bool $alpha
  * @param string|null $destination
  * @return mixed
  */
 public function sort($key, $pattern = null, $limit = null, $patterns = null, $asc = null, $alpha = false, $destination = null)
 {
     $params = [$key];
     if ($pattern) {
         $params[] = 'BY';
         $params[] = $pattern;
     }
     if ($limit) {
         $params[] = 'LIMIT';
         $params[] = Parameter::limit($limit);
     }
     if ($patterns) {
         foreach ((array) $patterns as $p) {
             $params[] = 'GET';
             $params[] = $p;
         }
     }
     if (isset($asc)) {
         $params[] = $asc ? 'ASC' : 'DESC';
     }
     if ($alpha) {
         $params[] = 'ALPHA';
     }
     if ($destination) {
         $params[] = 'STORE';
         $params[] = $destination;
     }
     return $this->returnCommand(['SORT'], $params);
 }
 /**
  * CLIENT KILL [ip:port] [ID client-id] [TYPE normal|slave|pubsub] [ADDR ip:port] [SKIPME yes/no]
  * Available since 2.4.0.
  * Time complexity: O(N) where N is the number of client connections
  * @link http://redis.io/commands/client-kill
  *
  * @param string|array|null $addr
  * @param int|null $clientId
  * @param string|null $type normal|slave|pubsub
  * @param string|array|null $addr2
  * @param bool|null $skipme
  * @return bool|int
  * When called with the three arguments format:
  * Simple string reply: True if the connection exists and has been closed
  * When called with the filter / value format:
  * Integer reply: the number of clients killed.
  */
 public function clientKill($addr = null, $clientId = null, $type = null, $addr2 = null, $skipme = null)
 {
     $params = [];
     if ($addr) {
         $params[] = Parameter::address($addr);
     }
     if ($clientId) {
         $params[] = 'ID';
         $params[] = $clientId;
     }
     if ($type) {
         $params[] = 'TYPE';
         $params[] = $type;
     }
     if ($addr2) {
         $params[] = 'ADDR';
         $params[] = Parameter::address($addr2);
     }
     if (isset($skipme)) {
         $params[] = 'SKIPME';
         $params[] = $skipme ? 'yes' : 'no';
     }
     return $this->returnCommand(['CLIENT', 'KILL'], $params);
 }
 /**
  * ZREVRANGEBYLEX key max min [LIMIT offset count]
  * Available since 2.8.9.
  * Time complexity: O(log(N)+M) with N being the number of elements in the sorted set
  * and M the number of elements being returned.
  * If M is constant (e.g. always asking for the first 10 elements with LIMIT), you can consider it O(log(N)).
  * @link http://redis.io/commands/zrevrangebylex
  *
  * @param string $key
  * @param string $max
  * @param string $min
  * @param int|array $limit
  * @return string[] List of elements in the specified score range.
  */
 public function zrevrangebylex($key, $max, $min, $limit = null)
 {
     $params = [$key, $max, $min];
     if ($limit) {
         $params[] = 'LIMIT';
         $params[] = Parameter::limit($limit);
     }
     return $this->returnCommand(['ZREVRANGEBYLEX'], $params);
 }
 /**
  * COMMAND GETKEYS command
  * Available since 2.8.13.
  * Time complexity: O(N) where N is the number of arguments to the command
  * @link http://redis.io/commands/command-getkeys
  *
  * @param string $command
  * @return string[] List of keys from your command.
  */
 public function commandGetkeys($command)
 {
     return $this->returnCommand(['COMMAND', 'GETKEYS'], Parameter::command($command));
 }
 /**
  * ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count]
  * Available since 2.2.0.
  * Time complexity: O(log(N)+M) with N being the number of elements in the sorted set
  * and M the number of elements being returned.
  * If M is constant (e.g. always asking for the first 10 elements with LIMIT), you can consider it O(log(N)).
  * @link http://redis.io/commands/zrevrangebyscore
  *
  * @param string $key
  * @param string $max
  * @param string $min
  * @param bool|false $withscores
  * @param string|array|null $limit
  * @return string[]|array list of elements in the specified score range (optionally with their scores).
  */
 public function zrevrangebyscore($key, $max, $min, $withscores = false, $limit = null)
 {
     $params = [$key, $max, $min];
     if ($withscores) {
         $params[] = 'WITHSCORES';
     }
     if ($limit) {
         $params[] = 'LIMIT';
         $params[] = Parameter::limit($limit);
     }
     return $this->returnCommand(['ZREVRANGEBYSCORE'], $params, $withscores ? ResponseParser::PARSE_ASSOC_ARRAY : null);
 }
 /**
  * MSETNX key value [key value ...]
  * Available since 1.0.1.
  * Time complexity: O(N) where N is the number of keys to set.
  * @link http://redis.io/commands/msetnx
  *
  * @param array $keyValues
  * @return int 1 if the all the keys were set. 0 if no key was set (at least one key already existed).
  */
 public function msetnx(array $keyValues)
 {
     return $this->returnCommand(['MSETNX'], Parameter::assocArray($keyValues));
 }
 /**
  * HMSET key field value [field value ...]
  * Available since 2.0.0.
  * Time complexity: O(N) where N is the number of fields being set.
  * @link http://redis.io/commands/hmset
  *
  * @param string $key
  * @param string|string[] $fieldValues
  * @return bool True
  */
 public function hmset($key, array $fieldValues)
 {
     return $this->returnCommand(['HMSET'], [$key, Parameter::assocArray($fieldValues)]);
 }