PHP code example of cheer / neptune-php

1. Go to this page and download the library: Download cheer/neptune-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cheer / neptune-php example snippets


composer 



//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));

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