PHP code example of hongxunpan / simple-redis
1. Go to this page and download the library: Download hongxunpan/simple-redis 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/ */
hongxunpan / simple-redis example snippets
return [
'connections' => [
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'port' => (int) env('REDIS_PORT', 6379),
'auth' => null,
'database' => 0,
'scheme' => 'tcp',
],
],
];
use HongXunPan\DB\Redis\Redis;
$redis = app(Redis::class);
$redis->getConnection()->set('key', 'value');
$redis->getConnection('cache')->get('key');
Redis::connection()->set('key', 'value');
$redis->reconnect('cache');
use HongXunPan\Framework\Core\Application;
use HongXunPan\Framework\Provider\ServiceProvider;
use HongXunPan\SimpleRedis\Config\RedisConfig;
final class ProjectRedisProvider extends ServiceProvider
{
public function register(Application $app): void
{
$app->instance(RedisConfig::class, RedisConfig::fromArray([
'connections' => [
'default' => [
'host' => 'redis.internal',
'port' => 6379,
],
],
]));
}
}
bash
composer le module:enable redis
bash
php bin/simple module:publish redis config