cheer/neptune-php

Redis 连接池客户端

v0.0.1 2019-02-01 09:11 UTC

This package is auto-updated.

Last update: 2024-08-29 04:31:47 UTC


README

介绍

这是一个用于使用 Redis 连接池调用 gRPC 服务的 PHP 客户端封装包;使用此包,您可以快速连接并使用 neptune(一个 Redis 连接池服务端)项目。

环境说明

  • php5.6+
  • 安装 grpc 扩展

安装

使用 Composer 包管理器

composer require cheer/neptune-php

使用说明

  • 首先需要运行 neptune 服务端;直接到该项目下的 Release 部分下载编译好的程序;

  • 调用示例:

require 'vendor/autoload.php';

//redis 连接信息
$option = [
    'ip'=>'192.168.137.100',
    'port'=>'6379',
    //'auth'=>'123456',//没有密码直接忽略
    'db_num'=>5,//需要存储到redis的库编号
    'init_cap'=>10,//初始连接数
    'max_cap'=>50,//最大连接数
    'timeout'=>30,//连接超时时间,超时后会释放连接
];

$server = '192.168.137.1:50033';//grpc服务端绑定ip端口

$client = new \Cheer\NeptuneClient\Client($server, $option);
$registerId = $client->registerPool();//进行连接池注册,注册后得到一个连接池ID,可以保存下来
//$client->setRegisterId($registerId);//如果已经保存了连接池ID直接调用该方法即可,无需重复调用注册方法
$key = "NeptuneClient";
$info = ['id'=>1,'info'=>'Hello World', 'time'=>time()];

$ret = $client->set($key, serialize($info));

生成 proto 的 PHP 类

如果希望对项目进行开发修改 proto 文件后需要重新生成 proto 类文件;

生成需要安装 proto 和 grpc_php_plugin,然后在项目目录中执行以下命令;

protoc --proto_path=./ --php_out=../grpc/ --grpc_out=../grpc/ --plugin=protoc-gen-grpc=/usr/local/bin/grpc_php_plugin  redis.proto