DatabaseSyncRedisServer.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace App\Handlers;
  3. use Illuminate\Support\Facades\Log;
  4. use Illuminate\Support\Facades\Redis;
  5. class DatabaseSyncRedisServer
  6. {
  7. const SHOP_LOCATION_KEY = 'shops_location';
  8. /**
  9. * 同步站点位置
  10. * @param $shop_id
  11. * @param $lat
  12. * @param $lng
  13. * @return mixed
  14. * Author: Mead
  15. */
  16. public static function syncShopLocation($shop_id, $lat, $lng)
  17. {
  18. Log::error([$shop_id, number_format($lat, 8), number_format($lng, 8)]);
  19. /** @var $redis \Predis\Client */
  20. $redis = Redis::connection();
  21. return $redis->geoadd(self::SHOP_LOCATION_KEY, '113.67462248', '34.72577707', $shop_id);
  22. // return $redis->geoadd(self::SHOP_LOCATION_KEY, number_format($lng, 8), number_format($lat, 8), $shop_id);
  23. }
  24. /**
  25. * 删除站点定位
  26. * @return mixed
  27. * Author: Mead
  28. */
  29. public static function delShopsLocation($id = 0)
  30. {
  31. /** @var $redis \Predis\Client */
  32. $redis = Redis::connection();
  33. if ($id) {
  34. return $redis->zrank(self::SHOP_LOCATION_KEY, $id);
  35. }
  36. return $redis->del(self::SHOP_LOCATION_KEY);
  37. }
  38. }