RedisCache.class.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace Common\Cache;
  3. use Think\Cache\Driver\Redis;
  4. /**
  5. * redis
  6. */
  7. class RedisCache extends Redis {
  8. public static $_Redis = array();
  9. public function __construct($options = array('host' => REDIS_HOST, 'port' => REDIS_PORT, 'auth' => REDIS_AUTH)) {
  10. parent::__construct($options);
  11. }
  12. public function getkey() {
  13. $res = $this->keys('*');
  14. return $res;
  15. }
  16. /**
  17. * 获取app用户的token
  18. * @author: huangch
  19. * @return mixed
  20. */
  21. public function get_user_token($uid) {
  22. return $this->get('x_user_token:'.$uid);
  23. }
  24. /**
  25. * 获取app用户的refresh_token
  26. * @author: huangch
  27. * @return mixed
  28. */
  29. public function get_user_refresh_token($uid) {
  30. return $this->get('x_user_refresh_token:'.$uid);
  31. }
  32. /**
  33. * 设置用户token
  34. * @author: huangch
  35. */
  36. public function set_user_token($user) {
  37. $this->set('x_user_token:'.$user['id'], $user['token'],86400);
  38. $this->set('x_user_refresh_token:'.$user['id'], $user['refresh_token'],86400 * 180);
  39. }
  40. /**
  41. * 刷新用户token
  42. * @param $uid
  43. * @param $token
  44. * @param $refresh_token
  45. * @author: huangch
  46. */
  47. public function refresh_user_token($uid,$token,$refresh_token) {
  48. $this->set('x_user_token:'.$uid, $token,86400);
  49. $this->set('x_user_refresh_token:'.$uid, $refresh_token,86400 * 180);
  50. }
  51. /**
  52. * 小程序用户设置token
  53. * @param $user
  54. * @author: linch
  55. */
  56. public function set_mini_app_user_token($user) {
  57. $this->set('mini_app_user_token:' . $user['uid'], $user['token'], 3600);
  58. }
  59. /**
  60. * 小程序用户获取token
  61. * @param $uid
  62. * @author: linch
  63. */
  64. public function get_mini_app_user_token($uid) {
  65. return $this->get('mini_app_user_token:' . $uid);
  66. }
  67. }