limingxinleo/idempotent

Making multiple identical function calls has the same effect as making a single function call.

v0.3.1 2023-06-28 03:56 UTC

This package is auto-updated.

Last update: 2024-03-28 05:36:49 UTC


README

安装

composer require limingxinleo/idempotent

使用

Hyperf 框架

以下代码会在 2s 内返回相同的数据

<?php

use Hyperf\Utils\ApplicationContext;
use Idempotent\Idempotent;

$container = ApplicationContext::getContainer();
$id = 'create_order:1';
$result = $container->get(Idempotent::class)->run($id, static function(){
    sleep(2);
    return uniqid();
});

var_dump($result);