1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace App;
- use Illuminate\Database\Eloquent\Model;
- use Redis;
- class RedisModel extends Model
- {
- public static $redis;
- private static function _init(){
- if( empty(self::$redis ) ){
- self::$redis = new Redis();
- self::$redis->connect(env('REDIS_IP'),env('REDIS_PORT'));//链接
- self::$redis->auth(env('REDIS_PASSWORD'));//密码
- }
- return self::$redis ;
- }
- public static function get( $key ){
- $redis = self::_init();
- return $redis->get($key);
- }
- public static function set( $key, $data){
- $redis = self::_init();
- return $redis->set( $key, $data);
- }
- public static function expire( $key, $time = 60 ){
- $redis = self::_init();
- return $redis->expire( $key, $time );
- }
- public static function setnx( $key, $data){
- $redis = self::_init();
- return $redis->setnx( $key, $data);
- }
- public static function rpush( $key, $data){
- $redis = self::_init();
- return $redis->rpush( $key, $data);
- }
- public static function lpop( $key ){
- $redis = self::_init();
- return $redis->lpop( $key );
- }
- public static function hSet( $table, $column, $value ){
- $redis = self::_init();
- return $redis->hSet( $table, $column, $value );
- }
- public static function hGet( $table, $column ){
- $redis = self::_init();
- return $redis->hGet( $table, $column );
- }
- public static function hDel( $table, $column ){
- $redis = self::_init();
- return $redis->hDel( $table, $column );
- }
- }
|