for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace awssat\Visits;
use Illuminate\Database\Eloquent\Model;
class Keys
{
public $prefix;
public $testing = '';
public $modelName = false;
public $id;
public $visits;
public $primary = 'id';
public $instanceOfModel = false;
public $tag;
/**
* Keys constructor.
* @param $subject
* @param $tag
*/
public function __construct($subject, $tag)
$this->modelName = strtolower(str_plural(class_basename(is_string($subject) ? $subject : get_class($subject))));
$this->prefix = config('visits.redis_keys_prefix');
$this->testing = app()->environment('testing') ? 'testing:' : '';
$this->primary = (new $subject)->getKeyName();
$this->tag = $tag;
$this->visits = $this->visits($subject);
if ($subject instanceof Model) {
$this->instanceOfModel = true;
$this->modelName = strtolower(str_singular(class_basename(get_class($subject))));
$this->id = $subject->{$subject->getKeyName()};
}
* Get cache key
*
* @param $key
* @return string
public function visits($key)
return "{$this->prefix}:$this->testing" .
strtolower(str_plural(class_basename(is_string($key) ? $key : get_class($key))))
. "_{$this->tag}";
* @param $ip
public function ip($ip)
return "{$this->prefix}:$this->testing" . snake_case("recorded_ips:" . ($this->instanceOfModel ? "{$this->modelName}_{$this->tag}_{$this->id}:" : '') . $ip);
* @param $limit
* @param $isLow
public function cache($limit = '*', $isLow = false)
$key = "{$this->prefix}:$this->testing" . "lists";
if ($limit == '*') {
return "{$key}:*";
return "{$key}:" . ($isLow ? "low" : "top") . "{$limit}_{$this->modelName}";
* @param $period
public function period($period)
return "{$this->visits}_{$period}";