hacklee / laravel5-php-redis by hacklee

Use The Redis PHP-Extention In The Laravel Framework With Facde Pattern.
721
3
1
Package Data
Maintainer Username: hacklee
Maintainer Contact: 517184100@qq.com (liguoyi)
Package Create Date: 2015-08-13
Package Last Update: 2016-01-08
Language: PHP
License: MIT
Last Refreshed: 2024-11-19 03:05:20
Package Statistics
Total Downloads: 721
Monthly Downloads: 2
Daily Downloads: 0
Total Stars: 3
Total Watchers: 1
Total Forks: 1
Total Open Issues: 0

laravel5-php-redis License

在laravel中用外观模式操作php的redis扩展类

安装php的redis扩展

  • 使用pecl安装
pecl install redis
  • 由于pecl的版本不一定是最新的,可以clone源码安装

phpredis扩展的github地址:https://github.com/phpredis/phpredis

此依赖读的redis配置跟laravel保持一样,在database.php中的redis节点

'redis' => [
        'default' => [
            'host' => '127.0.0.1',
            'port' => 6379,
        	'password' => '',
            'database' => 0,
        ],
    ]

使用步骤

  • 使用composer加载依赖
composer require hacklee/laravel5-php-redis

或修改composer.json,在require加上 "hacklee/laravel5-php-redis": "dev-master" 然后执行composer update

  • 在app.php的providers节点下增加以下代码
Hacklee\PRedisServiceProvider::class

'Hacklee\PRedisServiceProvider'
  • 在app.php的aliases节点下增加以下代码
'PRedis' => Hacklee\PRedisFacade::class

'PRedis' => 'Hacklee\PRedisFacade'

使用示例

  • 直接使用
$val = \PRedis::get('key');
  • 或命名空间
use PRedis;

$val = PRedis::get('key');

redis扩展的更多操作,请参考官网文档phpredis