Browse Source

测试redis

master
wanghongjun 1 month ago
parent
commit
bd2033e0fd
  1. 7
      app/Http/Controllers/Device/CameraApiController.php
  2. 5
      app/Services/HikParkingCameraService.php

7
app/Http/Controllers/Device/CameraApiController.php

@ -6,7 +6,7 @@ use App\Models\ParkingCamera;
use App\Services\ParkingCameraService; use App\Services\ParkingCameraService;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Redis;
class CameraApiController extends BaseController class CameraApiController extends BaseController
{ {
@ -28,6 +28,7 @@ class CameraApiController extends BaseController
$data = ParkingCamera::query()->select(['id', 'camera_ip', 'status']) $data = ParkingCamera::query()->select(['id', 'camera_ip', 'status'])
->get() ->get()
->toArray(); ->toArray();
Redis::set('camera_body', json_encode($data), 300);
return $this->responseService->success(['list' => $data]); return $this->responseService->success(['list' => $data]);
} }
@ -46,12 +47,12 @@ class CameraApiController extends BaseController
public function getCameraBody(): JsonResponse public function getCameraBody(): JsonResponse
{ {
$body = Cache::get('camera_body'); $body = Redis::get('camera_body');
if (!$body) { if (!$body) {
return $this->responseService->error('empty'); return $this->responseService->error('empty');
} else { } else {
$bodyArr = json_decode($body); $bodyArr = json_decode($body);
Cache::delete('camera_body'); Redis::delete('camera_body');
} }
return $this->responseService->success($bodyArr, 'SUCCESS'); return $this->responseService->success($bodyArr, 'SUCCESS');
} }

5
app/Services/HikParkingCameraService.php

@ -2,9 +2,8 @@
namespace App\Services; namespace App\Services;
use GuzzleHttp\Client;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Redis;
class HikParkingCameraService class HikParkingCameraService
{ {
@ -187,7 +186,7 @@ class HikParkingCameraService
// ->withDigestAuth($this->device['username'], $this->device['password']) // ->withDigestAuth($this->device['username'], $this->device['password'])
// ->put($url, $body); // ->put($url, $body);
Cache::put('camera_body', json_encode($body), 300); Redis::set('camera_body', json_encode($body), 300);
//dd($response->json(), $response->body(), $response->object(), $response); //dd($response->json(), $response->body(), $response->object(), $response);
} }
} }

Loading…
Cancel
Save