sy-records / thrift2-hbase
阿里云HBase增强版的Thrift
v1.1.0
2021-10-28 06:47 UTC
Requires
- php: >=7.2
Requires (Dev)
Suggests
- hyperf/contract: The contracts of Hyperf.
- hyperf/utils: A tools package that could help developer solved the problem quickly.
- psr/container: Common Container Interface (PHP FIG PSR-11)
README
Hyperf 的 thrift2-hbase 组件。
此仓库为使用阿里云云数据库Hbase性能增强版,HBase增强版使用的Thrift接口定义是HBase的
thrift2
。
安装
composer require sy-records/thrift2-hbase -vvv
#生成 classmap
composer dump-autoload -o
在Hyperf中使用
配置文件
配置文件位于config/autoload/hbase.php
,如配置文件不存在可通过执行以下命令创建默认配置,配置文件内容如下:
php bin/hyperf.php vendor:publish sy-records/thrift2-hbase
添加配置信息
<?php declare(strict_types=1); return [ 'default' => [ 'host' => env('ALIHBASE_HOST', 'localhost'), 'port' => env('ALIHBASE_PORT', 9190), 'key_id' => env('ALIHBASE_KEYID', 'root'), 'signature' => env('ALIHBASE_SIGNATURE', 'root'), ], ];
在项目根目录.env
文件中添加相关配置信息
参数说明:
ALIHBASE_HOST=localhost ALIHBASE_PORT=9190 ALIHBASE_KEYID=root ALIHBASE_SIGNATURE=root
代码提示
在PhpStorm中直接操作是没有代码提示的,可添加@var
使得编辑器增加代码提示,如下所示
这样操作$client
或$hbase
时,编辑器就会给出对应的代码提示。
<?php declare(strict_types=1); namespace App\Controller; use Hyperf\Di\Annotation\Inject; use Luffy\AliHbaseThrift\Service\AliHbaseThriftInterface; class IndexController extends AbstractController { /** * 使用注解时 * @Inject() * @var AliHbaseThriftInterface */ private $hbase; public function index() { /** * @var $client \Luffy\Thrift2Hbase\THBaseServiceClient */ $client = $this->hbase->getClient(); /** * @var $hbase \Luffy\AliHbaseThrift\Service\AliHbaseThriftService */ $hbase = make(AliHbaseThriftInterface::class); /** * @var $client \Luffy\Thrift2Hbase\THBaseServiceClient */ $client = $hbase->getClient(); $res = $client->get("scanface:test", new \Luffy\Thrift2Hbase\TGet(["row" => "001"])); var_dump($res->columnValues); } }
这样操作$client
或$hbase
时,编辑器就会给出对应的代码提示。
在其他框架中使用
配置文件
在对应的配置文件中添加如下配置信息,参数说明见上文
return [ 'host' => "localhost", 'port' => 9190, 'key_id' => 'root', 'signature' => 'root', ];
使用
$hbase = new Luffy\AliHbaseThrift\Service\AliHbaseThriftService($config['host'], $config['port'], $config['key_id'], $config['signature']);
贡献者
扩展服务
此仓库是作为操作Hbase
基础库发布的,另有完整的Hbase
+Solr
协程支持组件,操作更加便捷。