源碼
public function getList($start,$num) {
$redis = $this->_context->getRedis();
//total count
$count = $redis->zCard('base:list:' . $guestTypeId);
if ($count == 0)
return array('total' => 0, 'items' => null);
//ids
$option = array('withscores' => false, 'limit' => array((int)$start, (int)$num));
$ids = $redis->zRevRangeByScore('base:list', '+inf', '-inf', $option);
//items
$items = $this->getListByIds($ids);
return array('total' => $count, 'items' => $items);
}
public function getListByIds($ids) {
$redis = $this->_context->getRedis();
$result = array();
foreach ($ids as $itemId => $itemVal) {
$detail = $redis->hGetAll('base:info:' . $itemVal);
array_push($result, $detail);
}
return $result;
}
獲取列表
$option = array('withscores' => false, 'limit' => array((int)$start, (int)$num));
$ids = $redis->zRevRangeByScore('base:list', '+inf', '-inf', $option);
獲取明細
$result = array();
$detail = $redis->hGetAll('base:info:' . $id);
array_push($result, $detail);