php代码:

采用哈希类型存储数据,有序集合存储分页数据,进行倒序与正序的排序。

$getGoodsInfo   =   M('goods_test')->select();
for($i=0;$i<count($getGoodsInfo);$i++){
$addStatus = $obRedis->zAdd('goods_key',$getGoodsInfo[$i]['id'],$getGoodsInfo[$i]['id']);
if($addStatus){
$obRedis->hMset('goods:'.$getGoodsInfo[$i]['id'],['goods_id'=>$getGoodsInfo[$i]['goods_id'],'original_img'=>$getGoodsInfo[$i]['original_img'],'goods_content'=>$getGoodsInfo[$i]['goods_content'],'goods_name'=>$getGoodsInfo[$i]['goods_name'],'shop_price'=>$getGoodsInfo[$i]['shop_price']]);
}
}
// $obRedis->delete('goods_key');
//分页获取数据
$zrand = $obRedis->zRevRange('goods_key',0,10);
if($zrand){
for($i=0;$i<count($zrand);$i++){
$zget[] = $obRedis->hGetAll('goods:'.$zrand[$i]);
}
}
//某个值查询
$searchGoodsName = 'yuyu_购物车测试';
$getAllzrand = $obRedis->zRevRange('goods_key',0,-1);

$searchArr = [];
for($i=0;$i<count($getAllzrand);$i++){
$getZrandInfo = $obRedis->hGet('goods:'.$getAllzrand[$i],'goods_name');
if($getZrandInfo == $searchGoodsName){
$searchArr[] = $obRedis->hGetAll('goods:'.$getAllzrand[$i]);
}
}