<?php
class RedisService {
private $redis;
/**
*
*/
public function __construct() {
$hostname = '127.0.0.1';
$port = 6379;
$this->redis = new Redis();
if (!$this->redis->connect($hostname, $port)) {
throw new Exception('fail connect redis server.');
}
}
/**
*
*/
public function __destruct() {
$this->redis->close();
}
public function setValue($key, $value) {
$this->redis->set($key, $value);
}
public function getValue($key) {
return $this->redis->get($key);
}
}
PHPからRedisを使うPhpredisライブラリ | プログラミング初心者の勉強方法