承接 jdwx/redis-pubsub 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jdwx/redis-pubsub

最新稳定版本:v0.2.0

Composer 安装命令:

composer require jdwx/redis-pubsub

包简介

README 文档

README

This is a lightweight PHP client for asynchronous Redis pub/sub functionality with TLS and authentication. It uses PHP's inbuilt stream functions and has no external dependencies.

The target use case is for a long-running process that is subscribed to one or more Redis channels and needs to process incoming messages in a timely fashion, but also has other stuff to do.

It also supports a simple publishing interface. This is suitable for apps that need to publish messages to a Redis channel, but don't otherwise interact with Redis.

This is not intended to be a full-featured Redis client. That space is extremely well covered by other extensions and packages.

This package requires PHP 8.0 or later.

Installation

Via composer:

composer require jdwx/redis-pubsub

Usage

Publisher:

use JDWX\RedisPubSub\RedisPubSub;

# By default, a connection is made to localhost:6379 without TLS.
$rps = new RedisPubSub();
$rps->publish( 'test', 'Hello, world!' );

Subscriber:

use JDWX\RedisPubSub\RedisPubSub;

# TLS is enabled by providing the paths to the client certificate and key, and,
# optionally, the CA certificate if the server should be verified.
$rps = new RedisPubSub( 'localhost', 6379, './client.crt', './client.key', './ca.crt' );

# Perform authentication.
$rps->auth( 'password' );

# Subscribe to a channel.
$rps->subscribe( 'test' );

# This will block until a message is received.
$msg = $rps->recv();

# This will not block if there are no pending messages.
$msg = $rps->tryRecv();

# This will wait for up to 5 seconds for a message to return.
$msg = $rps->tryRecv( 5.0 );

# This will wait for a message for up to 5 seconds without returning it.
$msg = $rps->tryWait( 5.0 );

# A callback function.
function MyCallback( array $msg ) : void {
    var_dump( $msg );
}

# This will pass all messages currently in the queue to the callback function,
# one at a time.
$rps->recvAll( 'MyCallback' );

# This will wait 5 seconds for messages to arrive, passing them one at a time
# to the callback function.
$rps->recvAllWait( 5.0, 'MyCallback' );

License

This library is licensed under the BSD 2-clause license. See the LICENSE file for details.

统计信息

  • 总下载量: 11
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2023-04-03