2020
10-24
10-24
php redis setnx分布式锁简单原理解析
我就废话不多说了,大家还是直接看代码吧~<?php//高并发分布式锁header("Content-type:text/html;charset=utf-8");$redis=newRedis();$redis->connect('127.0.0.1',6379);echo"Connectiontoserversucessfully";//echo$redis->get("name");exit;$expire=1;$key='test1';$lock=false;$is_lock=$redis->setnx($key,time()+$expire);if(!$is_lock){$lock_time=$redis->get($key);//锁已过期,重置if($lock_time<tim...
继续阅读 >