php - How to get all cache entries with a tag on Laravel -


i'm building login throttling system using laravel, use save every failed login on cache database. (i use redis).

the code:

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);     } } 

the issue on hastoomany method, have provide key parameter on get method. trying on line: cache::tags('failed.logins')->get() entries failed.logins tag, can count how many there are.

well, not working, because can't that. recommend me use can solve it? if it's redis solutions that's fine too.

you use redis hashes:

http://redis.io/commands/hset

but can't set individual expiration date on hash keys, have delete them manually, or use main key hour in it, like: failed.logins:08 , expire whole.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -