问题代码:
if(!Redis::scontains($redisKey, $path)){ return response()->json([ 'code' => 99998, 'message' => '无操作权限' ], 200); } if(!Redis::hget($redisKey, 'admin_id')){ return response()->json([ 'code' => -1, 'message' => '未登录' ], 200); }
将获取结果放在条件里面做判断报错
解决办法用 try{ }catch(){ }
try{ $contain = Redis::scontains($redisKey,$path); }catch (\Exception $exception){ $contain = false; } if(!$contain){ return response()->json([ 'code' => 99999, 'message' => '无权限操作' ],200); } try{ $adminId = Redis::hget($redisKey, 'admin_id'); }catch (\Exception $e){ $adminId = 0; } if(!$adminId){ return response()->json([ 'code' => -1, 'message' => '未登录' ], 200); }
本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:Laravel框架 redis hget() scontains()方法报错解决 阿星小栈 - Python技术站