Skip to content

Commit

Permalink
fixes #58
Browse files Browse the repository at this point in the history
  • Loading branch information
abdumu committed Sep 19, 2020
1 parent 328ecaa commit a3f109e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/DataEngines/DataEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 7 additions & 5 deletions src/DataEngines/EloquentEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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)
]);
}
}
2 changes: 1 addition & 1 deletion src/Keys.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a3f109e

Please sign in to comment.