Açıklama Yok

RedisModel.php 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Redis;
  5. class RedisModel extends Model
  6. {
  7. public static $redis;
  8. private static function _init(){
  9. if( empty(self::$redis ) ){
  10. self::$redis = new Redis();
  11. self::$redis->connect(env('REDIS_IP'),env('REDIS_PORT'));//链接
  12. self::$redis->auth(env('REDIS_PASSWORD'));//密码
  13. }
  14. return self::$redis ;
  15. }
  16. public static function get( $key ){
  17. $redis = self::_init();
  18. return $redis->get($key);
  19. }
  20. public static function set( $key, $data){
  21. $redis = self::_init();
  22. return $redis->set( $key, $data);
  23. }
  24. public static function expire( $key, $time = 60 ){
  25. $redis = self::_init();
  26. return $redis->expire( $key, $time );
  27. }
  28. public static function setnx( $key, $data){
  29. $redis = self::_init();
  30. return $redis->setnx( $key, $data);
  31. }
  32. public static function rpush( $key, $data){
  33. $redis = self::_init();
  34. return $redis->rpush( $key, $data);
  35. }
  36. public static function lpop( $key ){
  37. $redis = self::_init();
  38. return $redis->lpop( $key );
  39. }
  40. public static function hSet( $table, $column, $value ){
  41. $redis = self::_init();
  42. return $redis->hSet( $table, $column, $value );
  43. }
  44. public static function hGet( $table, $column ){
  45. $redis = self::_init();
  46. return $redis->hGet( $table, $column );
  47. }
  48. public static function hDel( $table, $column ){
  49. $redis = self::_init();
  50. return $redis->hDel( $table, $column );
  51. }
  52. }