我在SymbolController
中使用paginate函数,它根据页码返回数据。该函数以正确的形式返回数据。但是,我正在使用redis,我正在存储返回的数据,但是我遗漏了它在redis中存储完整的分页html内容,但在返回时它正确返回json。以下是功能:
public function paginate(Request $request)
{
$pageNumber = $request->id;
$all = self::$redis::get('symbollist:'.$pageNumber);
if(is_null($all)){
$symbol = new Symbol();
$all = $symbol::paginate(10,['*'], 'page', $pageNumber);
self::$redis::set('symbollist:'.$pageNumber,$all);//store here
}
return $all;
}
如何存储以redis返回的值。
注意:该函数完全返回我需要的内容。只有将其存储在Redis
中才会出现问题从API返回的数据。
{"current_page":1,"data":[{"id":1550,"symbol":"ZYLOG","series":"EQ","isin":"INE225I01026","created_at":"2018-03-11 06:13:27","updated_at":"2018-03-11 06:13:27"},{"id":1549,"symbol":"ZYDUSWELL","series":"EQ","isin":"INE768C01010","created_at":"2018-03-11 06:13:27","updated_at":"2018-03-11 06:13:27"},{"id":1548,"symbol":"ZUARIGLOB","series":"EQ","isin":"INE217A01012","created_at":"2018-03-11 06:13:27","updated_at":"2018-03-11 06:13:27"},{"id":1547,"symbol":"ZUARI","series":"EQ","isin":"INE840M01016","created_at":"2018-03-11 06:13:27","updated_at":"2018-03-11 06:13:27"},{"id":1546,"symbol":"ZOTA","series":"SM","isin":"INE358U01012","created_at":"2018-03-11 06:13:27","updated_at":"2018-03-11 06:13:27"},{"id":1545,"symbol":"ZODIACLOTH","series":"EQ","isin":"INE206B01013","created_at":"2018-03-11 06:13:27","updated_at":"2018-03-11 06:13:27"},{"id":1544,"symbol":"ZICOM","series":"EQ","isin":"INE871B01014","created_at":"2018-03-11 06:13:26","updated_at":"2018-03-11 06:13:26"},{"id":1543,"symbol":"ZENTEC","series":"EQ","isin":"INE251B01027","created_at":"2018-03-11 06:13:26","updated_at":"2018-03-11 06:13:26"},{"id":1542,"symbol":"ZENSARTECH","series":"EQ","isin":"INE520A01019","created_at":"2018-03-11 06:13:26","updated_at":"2018-03-11 06:13:26"},{"id":1541,"symbol":"ZENITHEXPO","series":"EQ","isin":"INE058B01018","created_at":"2018-03-11 06:13:26","updated_at":"2018-03-11 06:13:26"}],"first_page_url":"http:\/\/127.0.0.1:8000\/api\/symbol\/1?page=1","from":1,"last_page":155,"last_page_url":"http:\/\/127.0.0.1:8000\/api\/symbol\/1?page=155","next_page_url":"http:\/\/127.0.0.1:8000\/api\/symbol\/1?page=2","path":"http:\/\/127.0.0.1:8000\/api\/symbol\/1","per_page":10,"prev_page_url":null,"to":10,"total":1550}
分页符调用后$all
中的数据。
LengthAwarePaginator {#551 ▼
#total: 1550
#lastPage: 155
#items: Collection {#543 ▶}
#perPage: 10
#currentPage: 2
#path: "http://127.0.0.1:8000/api/symbol/2"
#query: []
#fragment: null
#pageName: "page"
}