Skip to content

Commit

Permalink
更新K线最新的点
Browse files Browse the repository at this point in the history
  • Loading branch information
Queenie authored and Queenie committed Oct 29, 2019
1 parent a43690d commit f7185e4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions workers/sneakerWorkers/kLineWorker.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func calculateInDB(marketId int, period, begin, end int64) (k KLine) {
}
backupDB.Save(&k)
backupDB.DbCommit()
synToRedis(&k)
return
}

Expand Down Expand Up @@ -102,6 +103,7 @@ func calculateInBackupDB(marketId int, period, begin, end int64) (k KLine) {
backupDB.Model(KLine{}).Where("market_id = ?", marketId).Where("period = ?", lastPeriod).Where("? <= timestamp AND timestamp < ?", begin, end).Order("timestamp DESC").Limit(1).Select("close as close").Scan(&k)
backupDB.Save(&k)
backupDB.DbCommit()
synToRedis(&k)
return
}

Expand Down Expand Up @@ -148,3 +150,13 @@ func synFromRedis(marketId int, period, begin, end int64) (k KLine) {
}
return
}

func synToRedis(k *KLine) {
kRedis := utils.GetRedisConn("k")
defer kRedis.Close()

b, _ := json.Marshal((*k).Data())
kRedis.Send("ZREMRANGEBYSCORE", (*k).RedisKey(), (*k).Timestamp)
kRedis.Do("ZADD", k.RedisKey(), (*k).Timestamp, string(b))

}
2 changes: 1 addition & 1 deletion workers/sneakerWorkers/rebuildkLineToRedisWorker.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (worker *Worker) RebuildKLineToRedisWorker(payloadJson *[]byte) (queueName
if mainDB.Where("market_id = ?", payload.MarketId).Where("period = ?", payload.Period).Find(&ks).RecordNotFound() {
return
}

mainDB.DbRollback()
kRedis := utils.GetRedisConn("k")
defer kRedis.Close()
for i, k := range ks {
Expand Down

0 comments on commit f7185e4

Please sign in to comment.