Programming/PHP2014. 9. 16. 12:42

Memcached는 써보았는데 Redis는 아직 테스트를 안해봐서 아래 설명만 우선링크


phpredis 설치방법은 아래 글 참조

http://opens.kr/53


세션 서버 사용 설명- https://github.com/nicolasff/phpredis#php-session-handler


phpredis can be used to store PHP sessions. To do this, configure session.save_handler andsession.save_path in your php.ini to tell phpredis where to store the sessions:


session.save_handler = redis
session.save_path = "tcp://host1:6379?weight=1, tcp://host2:6379?weight=2&timeout=2.5, tcp://host3:6379?weight=2"


php.ini에서 위에 처럼 config 수정하는 방법도 있고 소스상에서 ini_set 으로 하는 방법도 있다.


Sessions have a lifetime expressed in seconds and stored in the INI variable "session.gc_maxlifetime". You can change it with ini_set(). The session handler requires a version of Redis with the SETEXcommand (at least 2.0). phpredis can also connect to a unix domain socket: session.save_path = "unix:///var/run/redis/redis.sock?persistent=1&weight=1&database=0.


아래 처럼 테스트 하니까 잘 된다. 


  1. <?php
  2. ini_set('session.save_handler', 'redis');
  3. ini_set('session.save_path', 'tcp://127.0.0.1:6379');
  4. //unix sock의 경우 아래처럼 그리고 & 파라미터로 database등 지정할수있는듯함
  5. //ini_set('session.save_path', 'unix:///var/run/redis/redis.sock?persistent=1&weight=1&database=0');
  6. ?>


Posted by 시니^^
Programming/PHP2014. 9. 16. 12:32


http://redis.io/clients 

=> 공식 사이트 들어가보면  아래 두가지를 추천하는 듯함

Predis ☺ ★ Repository JoL1hAHN Mature and supported

phpredis ☺ ★ Repository yowgi This is a client written in C as a PHP module.


아무래도 C로 작성된 PHP 모듈이 성능이 더 좋지 않을가?? 라는 생각에 아래 phpredis 하기로함
테스트는 해봐야겠지만.............
그리고 보니까...  https://github.com/nicolasff/phpredis#php-session-handler 도 지원함 좋다!!

설치방법 아래 참조

$ wget https://github.com/nicolasff/phpredis/zipball/master -O phpredis.zip
$ unzip phpredis.zip 
$ ll
drwxr-xr-x  5 root root   4096 Sep  3 04:27 nicolasff-phpredis-4c1f1bc

$ cd nicolasff-phpredis-4c1f1bc/
$ phpize 
Can't find PHP headers in /usr/include/php
The php-devel package is required for use of this command.

$ yum install php-devel #PHP devel 미설치시 설치하기!
$ phpize
Configuring for:
PHP Api Version:         20121113
Zend Module Api No:      20121212
Zend Extension Api No:   220121212

$ ./configure
$ make && make install
Installing shared extensions:     /usr/lib64/php/modules/

$ cd /usr/lib64/php/modules/
$ ll | grep redis
-rwxr-xr-x 1 root root  942112 Sep 16 12:11 redis.so

##### php.conf 디렉토리에 맞게 ini 에 extension 등록하기! 안되면 php.ini등록해도됨
$ echo extension=redis.so > /etc/php.d/redis.ini 


##### 웹서버종류에 따라서 Apache Restart 또는 php-fpm restart
$ /etc/init.d/php-fpm restart

##### 최종확인
$ php -i | grep 'Redis Version'
Redis Version => 2.2.5

<?php phpinfo() ?> 
redis
Redis Support => enabled
Redis Version => 2.2.5


Posted by 시니^^
DB/NoSQL/Redis2014. 9. 15. 19:08

$ wget http://download.redis.io/releases/redis-2.8.15.tar.gz $ tar xvfz redis-2.8.15.tar.gz $ cd redis-2.8.15 $ make -j4 $ make install -j4 ###### /etc/init.d/ 추가되도록 install############################# ###### vi /etc/init.d/redis_6379 열어보면 실행방식 자세히 알 수 있음 $ cd utils/ $ ./install_server.sh Welcome to the redis service installer This script will help you easily set up a running redis server Please select the redis port for this instance: [6379] ###포트지정하면됨 Selecting default: 6379 Please select the redis config file name [/etc/redis/6379.conf] Selected default - /etc/redis/6379.conf Please select the redis log file name [/var/log/redis_6379.log] Selected default - /var/log/redis_6379.log Please select the data directory for this instance [/var/lib/redis/6379] Selected default - /var/lib/redis/6379 Please select the redis executable path [/usr/local/bin/redis-server] Selected config: Port : 6379 Config file : /etc/redis/6379.conf ##설정파일 Log file : /var/log/redis_6379.log ##로그파일 Data dir : /var/lib/redis/6379 Executable : /usr/local/bin/redis-server Cli Executable : /usr/local/bin/redis-cli Is this ok? Then press ENTER to go on or Ctrl-C to abort. Copied /tmp/6379.conf => /etc/init.d/redis_6379 Installing service... Successfully added to chkconfig! Successfully added to runlevels 345! Starting Redis server... Installation successful! ###################################################### ### redis 실행######################################## $ /etc/init.d/redis_6379 start Starting Redis server... ### redis 중지######################################## $ /etc/init.d/redis_6379 stop Stopping ... Redis stopped ### 커맨드라인 콘솔모드 접속 ######################### $ redis-cli 127.0.0.1:6379>


Posted by 시니^^