UserCache.php 890 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Cache\User;
  3. use App\Libs\Utils;
  4. use Illuminate\Support\Facades\Redis;
  5. class UserCache
  6. {
  7. /**
  8. * 获取用户信息
  9. * @param $uid
  10. * @return mixed
  11. */
  12. public static function getUserInfo($uid)
  13. {
  14. $cacheKey = Utils::getCacheKey('user.info', [$uid]);
  15. return Redis::hgetAll($cacheKey);
  16. }
  17. /**
  18. * @param $uid
  19. * @param $field
  20. * @return mixed
  21. */
  22. public static function getUserInfoByField($uid, $field)
  23. {
  24. $cacheKey = Utils::getCacheKey('user.info', [$uid]);
  25. return Redis::hmget($cacheKey, $field);
  26. }
  27. /**
  28. * 修改用户信息
  29. * @param $uid
  30. * @param $data
  31. * @return mixed
  32. */
  33. public static function setUserInfo($uid, $data)
  34. {
  35. $cacheKey = Utils::getCacheKey('user.info', [$uid]);
  36. return Redis::hmset($cacheKey, $data);
  37. }
  38. }