我正在使用Laravel构建登录限制系统,我用它来保存缓存数据库上的每个失败登录. (我使用Redis).
代码:
class FailedLogins { const NUM_FAILURES_TO_LOCK = 30,TIME_RANGE = 10; // In minutes public function add($email,$ip = null) { if (is_null($ip)) $ip = request()->ip(); $index = md5($email . $ip); Cache::tags('Failed.logins')->put($index,1,self::TIME_RANGE); } public function hasTooMany() { $numFailedLogins = count(Cache::tags('Failed.logins')->get()); return ($numFailedLogins >= self::NUM_FAILURES_TO_LOCK); } }
问题出在hasTooMany方法上,我必须在get方法上提供一个关键参数.我试图在这一行上做什么:Cache :: tags(‘Failed.logins’) – > get()是获取带有Failed.logins标记的所有条目,所以我可以计算有多少条目.