AllTableNameCache.Class.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace Jobs\Cache;
  3. use Mall\Framework\Factory;
  4. class AllTableNameCache
  5. {
  6. /**
  7. * 所有表名缓存
  8. *
  9. * @var
  10. */
  11. static $allTableName = 'all_tablename';
  12. /**
  13. * 判断所有表名缓存是否存在
  14. *
  15. * @param string $databaseName 库名
  16. *
  17. * @return bool
  18. */
  19. static function allTableNameCacheIsExists($databaseName){
  20. $result = Factory::cache('default')->has(self::$allTableName.'::'.$databaseName);
  21. return $result;
  22. }
  23. /**
  24. * 缓存制定库下的所有表名
  25. *
  26. * @param string $dataBaseName 当前数据库库名
  27. * @param array $allTableNameData 当前库中所有表名数据
  28. */
  29. static function allTableNameCache($databaseName, $allTableNameData)
  30. {
  31. if(empty($allTableNameData)){
  32. return false;
  33. }
  34. $pipe = Factory::cache('default')->multi();
  35. foreach ($allTableNameData as $key => $value){
  36. $writeCache = Factory::cache('default')->sadd(self::$allTableName.'::'.$databaseName, $value['TABLE_NAME']);
  37. }
  38. $pipe->exec();
  39. }
  40. /**
  41. * 判断是否存在这张表
  42. *
  43. * @param string $dataBaseName 当前数据库库名
  44. * @param string $tableName 表名
  45. *
  46. * @return bool
  47. */
  48. static function TableIsExists($databaseName, $tableName)
  49. {
  50. $result = Factory::cache('default')->sismember(self::$allTableName.'::'.$databaseName, $tableName);
  51. return $result;
  52. }
  53. /**
  54. * 添加新表到表名缓存中
  55. * @param string $dataBaseName 当前数据库库名
  56. * @param string $tableName 表名
  57. *
  58. * @return bool
  59. */
  60. static function addNewTableName($databaseName, $tableName){
  61. $writeCache = Factory::cache('default')->sadd(self::$allTableName.'::'.$databaseName, $tableName);
  62. return $writeCache;
  63. }
  64. }