cakephp3 redis not configured properly - caching

I am having a super hard time getting redis to be configured. It was working, but I upgraded my servers and composer updated- now I getting "redis is not configured correctly"
define('_CACHE_SERVER', '*********.cache.amazonaws.com:6379');
'_cake_core_' => [
'className' => 'Redis',
'servers'=> [ _CACHE_SERVER ],
'prefix' => 'mrg_cake_core_',
'serialize' => 'php',
'duration' => '+2 minutes',
],
I have written a blank php and connected to redis with just simple $redis = new Redis(); and got $redis->lastSave(); Seems like something changed in CAKE. Very confused.

Thank you ndm, I changed the config to:
define('_CACHE_SERVER', '************.cache.amazonaws.com');
'_cake_core_' => [
'className' => 'Redis',
'host' => _CACHE_SERVER,
'port' => 6379,
'prefix' => 'myapp_cake_core_',
'duration' => '+1 years',
'url' => env('CACHE_CAKECORE_URL', null),
],

Related

I am trying to access database name in model relationshipt by config using laravel 8

Hi i am trying to access database name by using config but unfortunately it's not working please help me how can i resolve that thanks.
Property model
public function editedBy()
{
return $this->belongsToMany('App\User',config('database.connections.web.database'), 'property_id', 'user_id')->withTimestamps();
}
app/config/database/
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
],
'web' => [
'driver' => 'mysql',
'host' => env('DB_WEB_HOST'),
'port' => env('DB_WEB_PORT'),
'database' => env('DB_WEB_DATABASE'),
'username' => env('DB_WEB_USERNAME'),
'password' => env('DB_WEB_PASSWORD'),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
],
You can try using to database name using env('DB_DATABASE'). Its displaying that you have change the default variables so, it may be like this in your case.
public function editedBy()
{
return $this->belongsToMany('App\User',env('DB_WEB_DATABASE'), 'property_id', 'user_id')->withTimestamps();
}
or if you really want to use config this is the example.
public function getDatabaseName()
{
$databaseName = Config::get('database.connections.'.Config::get('database.default'));
dd($databaseName['database']);
}

Configure Redis Sentinel in Laravel 5.5

How to configure the Redis sentinel? Redis can be configured in stand alone easily using laravel configs but when using sentinel how to configure is not documented anywhere?
There is one similar question asked on redit: but no help.
In Laravel 5.5 one can do it like this:
Reference: https://github.com/laravel/framework/pull/18850#issue-116339448
database.php:
'redis' => [
'client' => 'predis',
// Keep Default as is you want to use both redis and sentinel for different service(cache, queue)'
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
// Create a custom connection to use redis sentinel
'cache_sentinel' => [
// Set the Sentinel Host from Environment (optinal you can hardcode if want to use in prod only)
env('CACHE_REDIS_SENTINEL_1'),
env('CACHE_REDIS_SENTINEL_2'),
env('CACHE_REDIS_SENTINEL_3'),
'options' => [
'replication' => 'sentinel',
'service' => 'cachemaster'),
'parameters' => [
'password' => env('REDIS_PASSWORD', null),
'database' => 0,
],
],
],
],
```
Specify the redis connection in your service where you want to use. example if cache needs redis sentinal can create new cache connection to use the above sentinal connection like this:
'stores' = [
//Keep default too as is
'redis' => [
'driver' => 'redis',
'connection' => 'default',
],
// create own cache connection
'sentinel_redis' => [
'driver' => 'redis',
'connection' => 'cache_sentinel',
],
And in Laravel app you can easily use via Cache Facade:
Cache::store('sentinel_redis')->get('key');

Work with mysql database in Laravel 4.2

I am new to Laravel used this https://github.com/msurguy/laravel-facebook-login link to work with facebook login in Laravel. I have setup all the things but i
got following errors when establishing database connection :
Type error: Argument 1 passed to
Illuminate\Redis\Database::__construct() must be of the type array,
null given, called in
C:\wamp64\www\laravel-facebook-login-master\vendor\laravel\framework\src\Illuminate\Redis\RedisServiceProvider.php
on line 23
I want to run simple mysql database. Below is my database.php code:
return array(
'fetch' => PDO::FETCH_CLASS,
'connections' => array(
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'facebookdb',
'username' => 'root',
'password' => '',
'port' => '3603',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
)
),
'migrations' => 'migrations',
);
Any suggestion/help will be highly appreciated.
You are missing the definition for your redis connection in that connections array, something like this will help:
'redis' => array(
'host' => env('REDIS_HOST', 127.0.0.1),
'port' => env('REDIS_PORT', 6379),
'password' => env('REDIS_PASSWORD', null),
'database' => env('REDIS_DATABASE', 0)
)
Make sure that you add the corresponding entries in your .env file if your redis connection settings differ from the default values above.

Google Cloud app engine with Laravel: unix_socket issue

I am using Laravel version 5.1.*. Here is my db config file...
'mysql' => [
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'database',
'username' => 'username',
'password' => 'password',
'unix_socket' => '/cloudsql/zoho-portal-159018:us-central1:zoho-portal',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
it gives error No such file or directory. It seems, unix_socket is the issue. But exact same config works when I use normal PDO connect without laravel....
$DBH_SOCKET = '/cloudsql/zoho-portal-159018:us-central1:zoho-portal';
$DBH_NAME = 'DBH_NAME';
$cns="mysql:unix_socket=".$DBH_SOCKET.";dbname=".$DBH_NAME.";charset=utf8";
$user='user';
$password='password';
try{
$DBH = new PDO($cns,$user,$password);
$DBH->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
If It works in normal single php file without laravel... then it must should work in laravel way. But not not working.. Any comments highly appreciated. Thanks

How to use the CLI Options for Artisan to execute on a different Laravel Environment

I am installing the migrate scripts for the first time on my application.
What I wish to do is use the configuration under /config/test/database.php to run my migrate installation scripts.
My entry on paths.php is the following
$environments = array(
'test' => array('http://test.*'),
'local' => array('http://localhost.*')
);
My entry on /application/config/test/database.php
return array(
'connections' => array(
'mysql' => array('driver' => 'mysql',
'host' => 'localhost',
'database' => 'new_db',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'prefix' => '')
),
);
and /application/config/database.php
return array(
'connections' => array(
'mysql' => array('driver' => 'mysql',
'host' => 'localhost',
'database' => 'default_db',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'prefix' => '')
),
);
Every time I run php artisan migrate:install --env=test it always installs on the DB defined on /application/config/database.php and not using the configuration from /application/config/test/database.php.
Appreciate if someone could help me fix this issue.
I figured it out myself. Am not sure if this is something that has been documented in Laravel for multiple environment. An additional parameter was required on the environment definition on the paths.php
$environments = array(
'test' => array('http://test.*','MY_COMPUTER_NAME'),
'local' => array('http://localhost.*')
);
Now, running php artisan migrate:install --env=test correctly executes the migration scripts on the DB configuration defined on /application/config/test/database.php.
Hope this helps others

Resources