Vapor Trail

明るく楽しく元気よく

はじめてのRedis

・開発環境 CentOS7 PHP 7.1 Apache OS標準 MySQL 5.7

・Redisインストール $ sudo yum install redis $ sudo systemctl enable redis $ sudo yum install --enablerepo=remi,remi-php71 php-pecl-redis

・redis.conf //LRU 最も参照されていないものを削除する maxmemory-policy allkeys-lru

・Redis コマンド

//Cli redis-cli

//接続確認 127.0.0.1:6379> ping PONG

//キーをすべて参照する keys "*"

//キーをすべて消す flushall

//SET キー 値 127.0.0.1:6379> SET hoge huga

//GET 127.0.0.1:6379> get hoge "huga"

//SET 127.0.0.1:6379> SET hoge:fuga foo OK 127.0.0.1:6379> GET hoge "huga" 127.0.0.1:6379> GET hoge:fuga "foo"

PHPで使用する

$redis = new \Redis();
$redis->connect("127.0.0.1",6379);
$redis->set('hoge', 'huga');
echo $redis->get("hoge");

$ huga