PHP code example of ginnerpeace / illuminate-cache-database
1. Go to this page and download the library: Download ginnerpeace/illuminate-cache-database library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ginnerpeace / illuminate-cache-database example snippets
namespace DataRepository;
use App\Models\User;
use Zeigo\Illuminate\CacheDatabase\Contracts\RedisHashRepository;
class Users implements RedisHashRepository
{
public function version(): string
{
return '1.0';
}
/** TTL (seconds). */
public function ttl(): int
{
return 60;
}
public function fetch(array $ids, string $scope = null): array
{
// The $scope param is design for data sharding.
// Use or not is up to u.
// User::{$scope}()->find($ids)
$result = User::whereType($scope)->find($ids, [
'id',
'username',
]);
if ($result->isEmpty()) {
return [];
}
return $result->keyBy('id')->toArray();
}
}