1
0
Fork 0

Add SuggestionService

This commit is contained in:
Daniel Supernault 2019-04-28 16:38:23 -06:00
parent ed4838d248
commit f0ce2a4335
No known key found for this signature in database
GPG Key ID: 0DEF1C662C9033F7
1 changed files with 46 additions and 0 deletions

View File

@ -0,0 +1,46 @@
<?php
namespace App\Services;
use Redis;
use App\Profile;
class SuggestionService {
const CACHE_KEY = 'pf:services:suggestion:ids';
public static function get($start = 0, $stop = -1)
{
return Redis::zrange(self::CACHE_KEY, $start, $stop);
}
public static function set($val)
{
return Redis::zadd(self::CACHE_KEY, 1, $val);
}
public static function del($val)
{
return Redis::zrem(self::CACHE_KEY, $val);
}
public static function add($val)
{
return self::set($val);
}
public static function rem($val)
{
return self::del($val);
}
public static function warmCache()
{
if(Redis::zcount(self::CACHE_KEY, '-inf', '+inf') == 0) {
$ids = Profile::whereNull('domain')->whereIsSuggestable(true)->pluck('id');
foreach($ids as $id) {
self::set($id);
}
}
}
}