AllTableNameCache.Class.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace JinDouYun\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. * @return null
  30. */
  31. static function allTableNameCache($databaseName, $allTableNameData)
  32. {
  33. if(empty($allTableNameData)){
  34. return false;
  35. }
  36. $pipe = Factory::cache('default')->multi();
  37. foreach ($allTableNameData as $key => $value){
  38. $writeCache = Factory::cache('default')->sadd(self::$allTableName.'::'.$databaseName, $value['TABLE_NAME']);
  39. }
  40. $pipe->exec();
  41. }
  42. /**
  43. * 判断是否存在这张表
  44. *
  45. * @param string $dataBaseName 当前数据库库名
  46. * @param string $tableName 表名
  47. *
  48. * @return bool
  49. */
  50. static function TableIsExists($databaseName, $tableName)
  51. {
  52. $result = Factory::cache('default')->sismember(self::$allTableName.'::'.$databaseName, $tableName);
  53. return $result;
  54. }
  55. /**
  56. * 添加新表到表名缓存中
  57. * @param string $dataBaseName 当前数据库库名
  58. * @param string $tableName 表名
  59. *
  60. * @return bool
  61. */
  62. static function addNewTableName($databaseName, $tableName){
  63. $writeCache = Factory::cache('default')->sadd(self::$allTableName.'::'.$databaseName, $tableName);
  64. return $writeCache;
  65. }
  66. /**
  67. * 获取指定库下所有表
  68. */
  69. static function getAllTableNameByDatabaseName($databaseName)
  70. {
  71. return Factory::cache('default')->smembers(self::$allTableName.'::'.$databaseName);
  72. }
  73. }