LoginSignup
20
19

More than 5 years have passed since last update.

【PHP】phpredisでredisの操作

Last updated at Posted at 2016-07-21

参考
CentOSにRedisをインストールしてみる
PHPでRedisを使ってみる

Redisインストール

※OSはCentOS6

yumリポジトリのepelの追加

rpm -ivh http://ftp-srv2.kddilabs.jp/Linux/distributions/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm

Redisインストール

yum -y install redis --enablerepo=epel

起動/自動起動設定

service redis start
chkconfig redis on

phpredisのインストール

補足

PHPでは、Predisとphpredisが有力。PredisはPHPのみで記載されたライブラリで、phpredisはC言語のエクステンションとのこと。phpredisの方が高速。

phpredisインストール

yum -y install php-pecl-redis --enablerepo=epel

Apacheを再起動して反映

service httpd restart

phpredisの使い方

String型

$redis = new Redis();
$redis->connect("127.0.0.1",6379);

//クリア
$redis->delete('key');

//値のセット
$redis->set('key', 'value');

//値の取得
$value = $redis->get('key');
20
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
19