Browse Source

优化数据刷新

longyu 2 years ago
parent
commit
2a0f5c4e03
4 changed files with 13 additions and 4 deletions
  1. 8 3
      cache/index_cache.go
  2. 1 1
      controller/index/index.go
  3. 2 0
      core/run_server.go
  4. 2 0
      init_serve/redis.go

+ 8 - 3
cache/index_cache.go

@@ -9,9 +9,14 @@ import (
 //record more information
 func IndexAutoRefresh(filePath string) bool {
 	if global.Re == nil {
-		err := global.Rc.LPush(utils.REFRESH_INDEX, filePath)
-		if err != nil {
-			fmt.Println("RecordNewLogs LPush Err:" + err.Error())
+		if global.Rc != nil {
+			if global.Rc.SetNX(filePath,filePath,utils.GetTodayLastSecond()){
+				err := global.Rc.LPush(utils.REFRESH_INDEX, filePath)
+				if err != nil {
+					fmt.Println("RecordNewLogs LPush Err:" + err.Error())
+				}
+				return true
+			}
 		}
 		return true
 	}

+ 1 - 1
controller/index/index.go

@@ -229,4 +229,4 @@ func (s *IndexController) Refresh(c *gin.Context) {
 //		return
 //	}
 //	return
-//}
+//}

+ 2 - 0
core/run_server.go

@@ -12,6 +12,8 @@ func RunServe() {
 	//初始化mysql数据库
 	init_serve.Mysql()
 	//如果配置了redis,那么链接redis
+	fmt.Println("redis")
+	fmt.Println(global.CONFIG.Serve.UseRedis)
 	if global.CONFIG.Serve.UseRedis {
 		//初始化redis
 		init_serve.RedisTool()

+ 2 - 0
init_serve/redis.go

@@ -28,9 +28,11 @@ func Redis() {
 }
 
 func RedisTool() {
+	fmt.Println("init RedisTool")
 	redisConf := global.CONFIG.Redis
 	fmt.Println(redisConf)
 	REDIS_CACHE := fmt.Sprintf(`{"key":"redis","conn":"%s","password":"%s"}`, redisConf.Address, redisConf.Password)
+	fmt.Println("REDIS_CACHE:"+REDIS_CACHE)
 	global.Rc, global.Re = cache.NewCache(REDIS_CACHE) //初始化缓存
 	if global.Re != nil {
 		fmt.Println(global.Re)