pfinal / idempotent
幂等
v1.0.0
2018-04-27 10:14 UTC
Requires
This package is auto-updated.
Last update: 2024-11-13 17:22:11 UTC
README
安装
composer require pfinal/idempotent
创建表
CREATE TABLE `idempotent` ( `id` bigint(11) unsigned NOT NULL AUTO_INCREMENT, `seq` varchar(50) NOT NULL DEFAULT '' COMMENT '请求序号', `response` longtext COMMENT '响应内容', `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `ind_seq` (`seq`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '幂等';
调用示例
<?php include __DIR__ . '/vendor/autoload.php'; //请求唯一标识 $seq = 'c4ca4238a0b923820dcc509a6f75849a'; //数据据库配置信息 \PFinal\Idempotent\Idempotent::$config['db.config'] = [ 'dsn' => 'mysql:host=127.0.0.1;dbname=test', 'username' => 'root', 'password' => 'root', 'charset' => 'utf8', 'tablePrefix' => '', ]; $result = \PFinal\Idempotent\Idempotent::run($seq, function () { //你自己的业务 return time(); }); //同一个$seq多次请求,将得到相同的结果 echo $result;