定制 pigeonboys/fastsub 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

pigeonboys/fastsub

最新稳定版本:v0.9.0

Composer 安装命令:

composer require pigeonboys/fastsub

包简介

A blazing-fast, Redis-powered subscription service for instant, cached access across projects.

README 文档

README

Introduction

The Fastsub package leverages Redis hashes to efficiently manage subscriptions. Each identity—such as a serial number, user ID, or other unique identifiers—has a dedicated hash. Subscription data is stored as key-value pairs within these hashes, where the values can be plain strings or JSON-encoded objects. This setup allows for easy tracking of subscription details like products, expiration dates, and more. JSON encoding also supports multiple subscriptions per identity, enabling the management of various services under one unique identifier. Other services can query these identity-specific Redis hashes for real-time access to subscription data.

Installation

To install the package, run the following command:

$ composer require pigeonboys/fastsub

Usage

Configuration

Before calling the SubscriptionQuery class for the first time, the SubscriptionConfiguration class must be initialized:

use PigeonBoys\Fastsub;

Fastsub\SubscriptionConfiguration::initialize(host: '127.0.0.1', port: 6379, database: 0);

Set Subscriptions

You can set the value of a field (key) as a plain string. However, it is recommended to use a JSON-encoded object to store additional subscription details.

use PigeonBoys\Fastsub;

// Set key-value pair in the <serialnumber> hash
Fastsub\SubscriptionQuery::hash('serialnumber')->updateOrCreate('111111', '[{"product":"test-product","ends_at":1738774349}]');

// Set multiple key-value pairs in the <serialnumber> hash
Fastsub\SubscriptionQuery::hash('serialnumber')->upsert([
    '111111' => '[{"product":"test-product","ends_at":1738774349}]',
    '222222' => '[{"product":"test-product","ends_at":1738774349}]',
]);

Get Subscriptions from field

You can retrieve the plain string value of a field (key) using the get method. Each field corresponds to an array index.

use PigeonBoys\Fastsub;

// Retrieve the field '111111' from the 'serialnumber' hash
$s = Fastsub\SubscriptionQuery::hash('serialnumber')->field('111111')->get();

// Response:
array:1 [▼
  111111 => "[{"product":"test-product","ends_at":1738774349}]"
]

To retrieve the field as an array (assuming it was stored as a JSON-encoded string), use the json method:

use PigeonBoys\Fastsub;

// Retrieve the field '111111' from the 'serialnumber' hash as a JSON object
$s = Fastsub\SubscriptionQuery::hash('serialnumber')->field('111111')->json();

// Response:
array:1 [▼
  111111 => array:1 [▼
    0 => array:2 [▼
      "product" => "test-product"
      "ends_at" => 1738774349
    ]
  ]
]

Get Subscriptions from Multiple Fields

To retrieve the plain string values of multiple fields (keys), use the get method with an array of field names.

use PigeonBoys\Fastsub;

// Retrieve fields '111111' and '222222' from the 'serialnumber' hash
$s = Fastsub\SubscriptionQuery::hash('serialnumber')->fields(['111111', '222222'])->get();

// Response:
array:2 [▼
  111111 => "[{"product":"test-product","ends_at":1738774349}]"
  222222 => "[{"product":"test-product","ends_at":1738774349}]"
]

Similarly, to retrieve the fields as JSON-encoded arrays, use the json method:

use PigeonBoys\Fastsub;

// Retrieve fields '111111' and '222222' from the 'serialnumber' hash as JSON objects
$s = Fastsub\SubscriptionQuery::hash('serialnumber')->fields(['111111', '222222'])->json();

// Response:
array:2 [▼
  111111 => array:1 [▼
    0 => array:2 [▼
      "product" => "test-product"
      "ends_at" => 1738774349
    ]
  ]
  222222 => array:2 [▼
    0 => array:2 [▼
      "product" => "test-product"
      "ends_at" => 1738774349
    ]
  ]
]

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-13