1<?php 2 3/* 4 * This file is part of the Predis package. 5 * 6 * (c) Daniele Alessandri <suppakilla@gmail.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12namespace Predis\Command; 13 14/** 15 * @link http://redis.io/commands/zscan 16 * 17 * @author Daniele Alessandri <suppakilla@gmail.com> 18 */ 19class ZSetScan extends Command 20{ 21 /** 22 * {@inheritdoc} 23 */ 24 public function getId() 25 { 26 return 'ZSCAN'; 27 } 28 29 /** 30 * {@inheritdoc} 31 */ 32 protected function filterArguments(array $arguments) 33 { 34 if (count($arguments) === 3 && is_array($arguments[2])) { 35 $options = $this->prepareOptions(array_pop($arguments)); 36 $arguments = array_merge($arguments, $options); 37 } 38 39 return $arguments; 40 } 41 42 /** 43 * Returns a list of options and modifiers compatible with Redis. 44 * 45 * @param array $options List of options. 46 * 47 * @return array 48 */ 49 protected function prepareOptions($options) 50 { 51 $options = array_change_key_case($options, CASE_UPPER); 52 $normalized = array(); 53 54 if (!empty($options['MATCH'])) { 55 $normalized[] = 'MATCH'; 56 $normalized[] = $options['MATCH']; 57 } 58 59 if (!empty($options['COUNT'])) { 60 $normalized[] = 'COUNT'; 61 $normalized[] = $options['COUNT']; 62 } 63 64 return $normalized; 65 } 66 67 /** 68 * {@inheritdoc} 69 */ 70 public function parseResponse($data) 71 { 72 if (is_array($data)) { 73 $members = $data[1]; 74 $result = array(); 75 76 for ($i = 0; $i < count($members); ++$i) { 77 $result[$members[$i]] = (float) $members[++$i]; 78 } 79 80 $data[1] = $result; 81 } 82 83 return $data; 84 } 85} 86