Download the PHP package nermif/php-redis-stock without Composer

On this page you can find all versions of the php package nermif/php-redis-stock. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-redis-stock

PHP Redis 库存与销售管理库

基于 Redis Lua 脚本的原子化库存扣减与销售记录组件,专为高并发电商场景设计。
提供门面 (Facade) 与底层原子类两种模式,兼顾易用性与灵活性。


✨ 特性


⚙️ 快速开始

安装

基础使用(推荐门面)

统一响应格式

门面所有方法均返回:


🏁 错误码一览

常量 值 含义
CODE_SUCCESS 1 成功
CODE_ERR_INSUFFICIENT -1 库存不足
CODE_ERR_NOT_EXISTS -2 库存未初始化
CODE_ERR_INVALID_QUANTITY -3 数量非法(≤0)
CODE_ERR_REDIS_UNAVAILABLE -4 Redis 服务不可用
CODE_ERR_LIMIT_EXCEEDED -5 超过限购数量
CODE_ERR_ALREADY_PROCESSED -6 订单已处理(幂等拦截)
CODE_ERR_INVALID_AMOUNT -7 金额非法
CODE_ERR_ORDER_CANCELED -8 订单已取消(并发拦截)
CODE_ERR_ORDER_NOT_PROCESSED -9 订单未处理(取消时)

门面类和底层类都实现了 StockSalesCodes 接口,可以直接通过 类名::CODE_XXX 判断返回值。


🗂️ 示例项目

示例代码位于 examples/ 目录:

文件 说明
facade_usage.php ⭐ 推荐 – 门面类完整示例
seckill_demo.php 秒杀全流程演示(库存+销售+排行榜)
stock_usage.php 库存高级用法(批量、监控、修复)
framework_usage.php Laravel / ThinkPHP 集成代码片段

运行示例前确保 Redis 已启动:


🧩 高级用法(直接使用底层类)

如果需要门面未提供的能力(如批量扣减、自定义重试),可以直接操作 RedisStock 和 RedisSales:

底层类同样实现 StockSalesCodes,可使用统一的错误码常量。


🔧 框架集成

Laravel

ThinkPHP


🏗️ 内部架构(面向高阶开发者)

系统通过门面模式组织对外接口,内部分工清晰:

购买流程:purchase() 内部调用 recordPurchaseWithStock Lua 脚本,一次性原子完成:
库存校验 → 限购检查 → 库存扣减 → 售罄标记 → 记录销量/销售额/排行榜 → 订单幂等标记。

用户无需分别调用 decrStock() + recordPurchase(),也无需在业务层手动判断售罄。


⚠️ 生产环境建议

  1. Key 前缀 – 务必使用 {} 包裹前缀核心部分(如 {stock}:),否则多 Key 操作在集群下会报 CROSSSLOT。
  2. Redis 配置 – maxmemory-policy 建议设为 volatile-lru,避免意外驱逐导致售罄标记丢失。
  3. 日志注入 – 建议注入 PSR‑3 日志器。当 repair() 触发修复时可通过日志追踪底层异常。
  4. 批量操作 – decrMultiStocks 虽然支持原子扣减,但单次 SKU 数建议不超过 20,避免长时间阻塞 Redis。
  5. 限购过期的理解 – 用户购买记录的 TTL 默认为 30 天,超时后限购计数自动清零,请按业务需求调整。

🧪 测试

测试套件包含 120+ 用例,覆盖库存、销售、门面层及边界场景。


📄 许可

MIT License. 可自由用于个人或商业项目。


All versions of php-redis-stock with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2.0
ext-redis Version *
psr/log Version ^1.0|^2.0|^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package nermif/php-redis-stock contains the following files

Loading the files please wait ...