PHPackages                             kail520/redis\_lbs - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. kail520/redis\_lbs

ActiveLibrary[Caching](/categories/caching)

kail520/redis\_lbs
==================

v1.1.6(7y ago)0321[1 PRs](https://github.com/kail520/redis_lbs/pulls)MITPHPPHP &gt;=5.4.0

Since Jan 3Pushed 5y agoCompare

[ Source](https://github.com/kail520/redis_lbs)[ Packagist](https://packagist.org/packages/kail520/redis_lbs)[ RSS](/packages/kail520-redis-lbs/feed)WikiDiscussions master Synced yesterday

READMEChangelog (8)Dependencies (1)Versions (9)Used By (0)

安装
==

[](#安装)

需要使用composer，[安装composer](https://getcomposer.org/download/), [composer中国镜像](http://www.phpcomposer.com/)

如果是应用在项目当中的话找到根目录，需要和 `composer.json`同级

```
composer require kail520/redis_lbs

```

配置
--

[](#配置)

使用时，需要修改配置文件 `params.php`

```
  'geoset_name' => 'LBS_set',
    'radium_option' => [
        'WITHDIST' => true,
        'SORT' => 'asc',
        'WITHHASH' => false,
    ],
    'redis_connection' => [
        'host'     => '127.0.0.1',      //连接地址
        'port'     => 6379,             //端口
        'database' => 1,                //库索引
        'password' => null,             //密码
    ],

```

***但是***，如果是在 `vendor` 文件夹下修改就不能将它从版本库中移除了，所以也可以按照以上的格式写一个数组初始化的时候添加进去比如:

```
$config = [
              'geoset_name' => 'LBS_set',         //集合名
              'radium_option' => [                //搜寻附近的人的时候定义的一些参数
                  'WITHDIST' => true,
                  'SORT' => 'asc',
                  'WITHHASH' => false,
              ],
              'redis_connection' => [
                  'host'     => '127.0.0.1',      //连接地址
                  'port'     => 6379,             //端口
                  'database' => 1,                //库索引
                  'password' => null,             //密码
              ],
          ];
 $lbs = new \LBS\Services\LBSService($config);

```

有以下三种使用方式

```
1> $lbs = new \LBS\Services\LBSServer();

2> public function __construct(LBSInterface $LBS)
       {
           $list = $LBS->list($LBS->geoset_name);

           dd($list);
       }
   }
3> $search2 = \LBSServer::searchByMembers('fesco',500,'m');

```

\#基本操作

初始化
---

[](#初始化)

```
require_once __DIR__.'/vendor/autoload.php';
$lbs = new \LBS\Services\LBSService();

```

添加
--

[](#添加)

```
$add_params = [
    [
        'name' => 'yabao_road',
        'long' => '116.43620200729366',
        'lat' => '39.916880160714435'
    ],
    [
        'name' => 'jianguomen',
        'long' => '116.4356870231628',
        'lat' => '39.908560377800676'
    ],
    [
        'name' => 'chaoyangmen',
        'long' => '116.4345336732864',
        'lat' => '39.924466658329585'
    ],
    [
        'name' => 'galaxy_soho',
        'long' => '116.4335788068771',
        'lat' => '39.921372916981106'
    ],
    [
        'name' => 'cofco',
        'long' => '116.43564410781856',
        'lat' => '39.92024564137184'
    ],
    [
        'name' => 'fesco',
        'long' => '116.435182767868',
        'lat' => '39.91811857809279'
    ],

];
/**
 * 在集合中新加一个坐标
 * @param array $params
 *  结构是 ['name'=>'xxx','long'=>'1.2321','lat'=>'1.3112']或者[['name'=>'xxx','long'=>'1.2321','lat'=>'1.3112']]
 * @param null $key
 * @return int
 */
$res = $lbs->add($add_params);

返回
int 6

```

删除
--

[](#删除)

```
/**
 * 删除集合中指定元素
 * @param $name
 * @param null $key  默认存在集合，可以指定
 * @return int
 */
$res = $lbs->del('gao1');

返回
int 0 或 1

如果是指定的集合名就
$res = $lbs->del('gao1','set-name');

```

用坐标查询附近的单位
----------

[](#用坐标查询附近的单位)

```
/**
 * 查询范围内元素，如果不转 key就用默认的
 * @param $long     经度
 * @param $lat      纬度
 * @param $radius   范围
 * @param $unit     单位  (仅支持 m,km,ft,mi)
 * @param null $key 集合名
 * @return mixed
 */
$search = $lbs->search('116.435182767868','39.91811857809279',500,'m');

返回数组
array:4 [▼
  0 => array:2 [▼
    "name" => "fesco"
    "dist" => "0.1250"
  ]
  1 => array:2 [▼
    "name" => "yabao_road"
    "dist" => "162.8454"
  ]
  2 => array:2 [▼
    "name" => "cofco"
    "dist" => "239.7758"
  ]
  3 => array:2 [▼
    "name" => "galaxy_soho"
    "dist" => "386.9165"
  ]
]

```

根据已有的位置查询
---------

[](#根据已有的位置查询)

```
/**
 * 根据集合中的元素查询范围内元素，如果不转 key就用默认的
 * @param $name         集合中的元素名
 * @param $radius       范围
 * @param $unit         单位
 * @param null $key     集合名
 * @return mixed
 */
$search = $lbs->->searchByMembers('fesco',500,'m');

返回数组
array:4 [▼
  0 => array:2 [▼
    "name" => "fesco"
    "dist" => "0.1250"
  ]
  1 => array:2 [▼
    "name" => "yabao_road"
    "dist" => "162.8454"
  ]
  2 => array:2 [▼
    "name" => "cofco"
    "dist" => "239.7758"
  ]
  3 => array:2 [▼
    "name" => "galaxy_soho"
    "dist" => "386.9165"
  ]
]

```

列出集合的所有值（其实就是 zrange)
---------------------

[](#列出集合的所有值其实就是-zrange)

```
/**
 * 列出集合中的内容
 * @param $key          集合的key
 * @param int $start    起始位置
 * @param int $end      结束位置 -1 为直到末尾
 * @return array
 */
$list = $lbs->list($test->geoset_name,2,-1);

返回数组
array:6 [▼
  0 => "jianguomen"
  1 => "yabao_road"
  2 => "fesco"
  3 => "cofco"
  4 => "galaxy_soho"
  5 => "chaoyangmen"
]

```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

8

Last Release

2686d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/21029751?v=4)[kail520](/maintainers/kail520)[@kail520](https://github.com/kail520)

---

Top Contributors

[![kail520](https://avatars.githubusercontent.com/u/21029751?v=4)](https://github.com/kail520 "kail520 (1 commits)")

### Embed Badge

![Health badge](/badges/kail520-redis-lbs/health.svg)

```
[![Health](https://phpackages.com/badges/kail520-redis-lbs/health.svg)](https://phpackages.com/packages/kail520-redis-lbs)
```

###  Alternatives

[rhubarbgroup/redis-cache

A persistent object cache backend for WordPress powered by Redis. Supports Predis, PhpRedis, Relay, replication, sentinels, clustering and WP-CLI.

51795.3k1](/packages/rhubarbgroup-redis-cache)[monospice/laravel-redis-sentinel-drivers

Redis Sentinel integration for Laravel and Lumen.

103830.5k](/packages/monospice-laravel-redis-sentinel-drivers)[jamescauwelier/psredis

Sentinel client for the popular php redis client

77392.9k5](/packages/jamescauwelier-psredis)[cache/predis-adapter

A PSR-6 cache implementation using Redis (Predis). This implementation supports tags

272.6M13](/packages/cache-predis-adapter)[symfony-bundles/redis-bundle

Symfony Redis Bundle

271.1M5](/packages/symfony-bundles-redis-bundle)[pdffiller/qless-php

PHP Bindings for qless

29113.2k1](/packages/pdffiller-qless-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
