PHP Redis client : Predis, PhpRedis 사용법

-------------------------------------------------------------------------------
< Predis >
https://github.com/predis/predis - 7.8k
    - v3.4.2 , 2026-03
     - php 로 작성됨. 속도 느림

     - 설치
- Predis는 순수 PHP 라이브러리라서 php 확장 설치 필요없음

     - Laravel 패키지 설치
composer require predis/predis

     - Laravel 설정(.env) 수정
REDIS_CLIENT=predis


-------------------------------------------------------------------------------
< PhpRedis >
     - PHP extension for Redis 
https://github.com/phpredis/phpredis - 10.2k
     - v6.3.0 , 2025-11
     - C로 작성됨. 속도 빠름
     - 라라벨에서 공식적으로 권장, 라라벨 v6(2019)정도부터 기본으로 설정됨

     - 우분투 재부팅시 다음 에러 로그가 생기는 것 막을 수 있는 가능성이 조금 높음?
Error while reading line from the server. [tcp://127.0.0.1:6379] {"exception":"[object] (Predis\\Connection\\ConnectionException(code: 0): Error while reading line from the server. [tcp://127.0.0.1:6379] at /var/www/exam/vendor/predis/predis/src/Connection/AbstractConnection.php:144)


---------------------------------------
* Ubuntu 에 PhpRedis 설치 방법
     - php 정보 확인
php -i | egrep "PHP Version|Thread|Architecture|Compiler"

     - 패키지 설치
sudo apt install php-redis

 

     - 버전 지정시 : sudo apt install php8.4-redis

     - ubuntu에서는 php.ini 설정 필요없음
          - 패키지 설치시 /etc/php/<버전>/mods-available/redis.ini 가 자동 생성

     - 설치 확인
sudo phpenmod redis          # redis 확장 모듈을 활성 설정
php -m | grep redis          # 'redis' 보이면 로딩됨

sudo systemctl restart nginx php8.4-fpm 

---
     - Laravel 설정 수정
REDIS_CLIENT=phpredis

     - 테스트
php artisan config:clear
php artisan cache:clear

php artisan tinker 
// Tinker에서 코드 실행:
use Illuminate\Support\Facades\Redis;
config('database.redis.client'); // 
Redis::set('test_key', 'hello');
Redis::get('test_key'); // "hello" 나오면 OK


---------------------------------------
* 윈도우에 PhpRedis 설치 방법
     - php 정보 확인
php -i | find "PHP Version" & php -i | find "Thread" & php -i | find "Architecture" & php -i | find "Compiler"

     - 파일 다운로드
https://pecl.php.net/package/redis

     - php.ini 파일 수정
extension=php_redis.dll

---
     - Laravel 설정 수정과 Redis 테스트 코드는 위 Ubuntu와 동일

 

반응형
Posted by codens