Background
Solution
SetNx with TTL? · Issue #309 · nrk/predis.
<?php
Redis::set('key', 1, 'ex', 3, 'nx');
References
- https://laravel.com/docs/6.x/redis, "Redis - Laravel - The PHP Framework For Web Artisans".
- https://laravel.com/api/6.x/Illuminate/Redis/Connections/PhpRedisClusterConnection.html#method_setnx,
"Laravel API".
- https://laravel.com/api/6.x/Illuminate/Redis/Connections/PhpRedisClusterConnection.html#method_set, " Laravel API".
- https://github.com/phpredis/phpredis#examples-4, "phpredis/phpredis: A PHP extension for Redis".
- https://github.com/nrk/predis/issues/309#issuecomment-221203097, "SetNx with TTL? · Issue #309 · nrk/predis"
More
- https://divinglaravel.com/introduction-to-redis, "Introduction to Redis - Diving Laravel".
- https://ukagaka.github.io/php/2017/09/21/redisLock.html, "redis加锁的几种实现".
- https://blog.huoding.com/2015/09/14/463, "谈谈Redis的SETNX | 火丁笔记".
- https://programming.vip/docs/redis-distributed-lock-php.html, "Redis Distributed Lock--PHP".