diff --git a/src/DataEngines/DataEngine.php b/src/DataEngines/DataEngine.php index 87bd206..6faa47a 100755 --- a/src/DataEngines/DataEngine.php +++ b/src/DataEngines/DataEngine.php @@ -14,7 +14,7 @@ public function delete($key, $member = null): bool; public function get(string $key, $member = null); public function set(string $key, $value, $member = null): bool; - public function flatList(string $key, int $limit): array; + public function flatList(string $key, int $limit = -1): array; public function addToFlatList(string $key, $value): bool; public function search(string $word, bool $noPrefix = true): array; public function valueList(string $search, int $limit = -1, bool $orderByAsc = false, bool $withValues = false): array; diff --git a/src/DataEngines/EloquentEngine.php b/src/DataEngines/EloquentEngine.php index 95ce4f3..366dfcf 100755 --- a/src/DataEngines/EloquentEngine.php +++ b/src/DataEngines/EloquentEngine.php @@ -87,11 +87,13 @@ public function set(string $key, $value, $member = null): bool 'primary_key' => $this->prefix.$key, 'secondary_key' => $member, 'score' => $value, + 'expired_at' => null, ]) instanceof Model; } else { return $this->model->updateOrCreate([ 'primary_key' => $this->prefix.$key, 'score' => $value, + 'expired_at' => null, ]) instanceof Model; } } @@ -191,14 +193,14 @@ public function timeLeft(string $key): int public function setExpiration(string $key, int $time): bool { - $time = \Carbon\Carbon::now()->addSeconds($time); + // $time = \Carbon\Carbon::now()->addSeconds($time); return $this->model->where(['primary_key' => $this->prefix.$key]) - ->where(function($q) { - return $q->where('expired_at', '>', \Carbon\Carbon::now())->orWhereNull('expired_at'); - }) + ->where(function($q) { + return $q->where('expired_at', '>', \Carbon\Carbon::now())->orWhereNull('expired_at'); + }) ->update([ - 'expired_at' => $time + 'expired_at' => \Carbon\Carbon::now()->addSeconds($time) ]); } } \ No newline at end of file diff --git a/src/Keys.php b/src/Keys.php index 6634afc..2faafab 100755 --- a/src/Keys.php +++ b/src/Keys.php @@ -66,7 +66,7 @@ public function cache($limit = '*', $isLow = false, $constraints = []) } //it might not be that unique but it does the job since not many lists - //will be generated to one key.eloquent + //will be generated to one key. $constraintsPart = count($constraints) ? ':'.substr(sha1(serialize($constraints)), 0, 7) : ''; return "{$key}:".($isLow ? 'low' : 'top').$constraintsPart.$limit;