Categories
Laravel

Cài đặt và sử dụng Redis

composer require predis/predis

config/database.php

'redis' => [

		//'client' => env('REDIS_CLIENT', 'phpredis'),
		'client' => 'predis',

		'options' => [
			'cluster' => 'redis',
		],

		'clusters' => [
			'default' => [
				[
					'host' => env('REDIS_HOST', 'localhost'),
					'password' => env('REDIS_PASSWORD', null),
					'port' => env('REDIS_PORT', 6379),
					'database' => 0,
				],
			],
		],

	],

Cách dùng:

$redis = Redis::connection();
		$redis->set('name','Nguyễn Thân', 'EX', 30); // set theo giay
		$response = $redis->get('name');
		echo $response;

Cách kiểm tra

$ redis-cli
127.0.0.1:6379> GET name
Output:
"Nguyễn Thân"

Khởi động lại Redis

sudo systemctl restart redis.service

18 replies on “Cài đặt và sử dụng Redis”

I quite like looking through an article that can make people think. Also, many thanks for allowing for me to comment. Jesselyn Fletch Schwab

Undeniably believe that which you said. Your favorite justification seemed to be on the web the simplest thing tobe aware of. Alexandra David Levin

It is perfect time to make a few plans for the longer term and it is time to be happy. I have learn this submit and if I may just I desire to suggest you few attention-grabbing issues or advice. Perhaps you can write next articles regarding this article. I desire to read more things about it! Rochette Maurise Quin

Do you think you would use honey or maple syrup as a sweetener and if so how much? And how about coconut oil or avocado oil? Are those neutral? I love morning glory muffins. The cake idea is smart. Thanks! Daniela Monty Slavin

Leave a Reply

Your email address will not be published. Required fields are marked *