fix the sample region info

This commit is contained in:
lion 2025-10-21 13:31:01 +08:00
parent f7ad4309f8
commit 8a7a899c64
3 changed files with 10 additions and 8 deletions

View File

@ -13,7 +13,7 @@ go get github.com/lionsoul2014/ip2region/binding/golang
SearchByStr(string) (string, error) SearchByStr(string) (string, error)
Search([]byte) (string, error) Search([]byte) (string, error)
``` ```
查询出错则 error 会包含错误信息,查询成功会返回字符串的 `region` 信息,如果指定的 IP 查询不到则会返回空字符串 `""` 查询出错则 error 会包含具体的错误信息,查询成功会返回字符串的 `region` 信息,如果指定的 IP 查询不到则会返回空字符串 `""`
### 关于 IPv4 / IPv6 ### 关于 IPv4 / IPv6
该 xdb 查询客户端实现同时支持对 IPv4 和 IPv6 的查询,使用方式如下: 该 xdb 查询客户端实现同时支持对 IPv4 和 IPv6 的查询,使用方式如下:
@ -160,9 +160,10 @@ ip2region>>
ip2region xdb searcher test program ip2region xdb searcher test program
source xdb: ../../data/ip2region_v6.xdb (IPv6, vectorIndex) source xdb: ../../data/ip2region_v6.xdb (IPv6, vectorIndex)
type 'quit' to exit type 'quit' to exit
ip2region>> ::
{region: , ioCount: 1, took: 42.157µs}
ip2region>> 240e:87c:892:ffff:ffff:ffff:ffff:ffff ip2region>> 240e:87c:892:ffff:ffff:ffff:ffff:ffff
{region: 中国|广东省|深圳市|专线用户, ioCount: 12, took: 130.294µs} {region: 中国|北京市|北京市|专线用户, ioCount: 10, took: 88.769µs}
ip2region>>
``` ```
输入对应版本的 ip 地址进行查询即可,输入 quit 退出测试程序。可以设置 `cache-policy` 为 file/vectorIndex/content 来测试不同的查询缓存机制。 输入对应版本的 ip 地址进行查询即可,输入 quit 退出测试程序。可以设置 `cache-policy` 为 file/vectorIndex/content 来测试不同的查询缓存机制。

View File

@ -9,7 +9,8 @@ npm install ip2region.js --save
### 关于查询 API ### 关于查询 API
查询 API 的原型为: 查询 API 的原型为:
```javascript ```javascript
// 通过字符串 IP 或者 parseIP 解析得到的二进制 IP (Buffer类型) 进行查询
search(ip: string | Buffer): string; search(ip: string | Buffer): string;
``` ```
如果查询出错会抛异常,查询成功则会返回字符的 `region` 信息,如果指定的 IP 查询不到则会返回空字符串 `""` 如果查询出错会抛异常,查询成功则会返回字符的 `region` 信息,如果指定的 IP 查询不到则会返回空字符串 `""`

View File

@ -192,14 +192,14 @@ ip2region>> 120.229.45.2
例如:使用默认的 data/ip2region_v6.xdb 进行 IPv6 的查询测试: 例如:使用默认的 data/ip2region_v6.xdb 进行 IPv6 的查询测试:
```bash ```bash
➜ php git:(fr_php_ipv6) ✗ php search_test.php --db=../../data/ip2region_v6.xdb ➜ php git:(master) ✗ php ./search_test.php --db=../../data/ip2region_v6.xdb
ip2region xdb searcher test program ip2region xdb searcher test program
source xdb file: ../../data/ip2region_v6.xdb (IPv6, vectorIndex) source xdb file: ../../data/ip2region_v6.xdb (IPv6, vectorIndex)
type 'quit' to exit type 'quit' to exit
ip2region>> :: ip2region>> ::
{region: |||, ioCount: 2, took: 0.06982 ms} {region: , ioCount: 1, took: 0.08887 ms}
ip2region>> 2604:bc80:8001:11a4:ffff:ffff:ffff:ffff ip2region>> 240e:3b7:3272:d8d0:db09:c067:8d59:539e
{region: 中国|广东省|深圳市|数据中心, ioCount: 13, took: 0.19409 ms} {region: 中国|广东省|深圳市|家庭宽带, ioCount: 8, took: 0.09595 ms}
``` ```
输入 ip 即可进行查询测试。也可以分别设置 `cache-policy` 为 file/vectorIndex/content 来测试三种不同缓存实现的效率。 输入 ip 即可进行查询测试。也可以分别设置 `cache-policy` 为 file/vectorIndex/content 来测试三种不同缓存实现的效率。