From f7185e493060e62655575d694fec30cd28d0f4ef Mon Sep 17 00:00:00 2001 From: Queenie Date: Tue, 29 Oct 2019 14:54:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0K=E7=BA=BF=E6=9C=80=E6=96=B0?= =?UTF-8?q?=E7=9A=84=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- workers/sneakerWorkers/kLineWorker.go | 12 ++++++++++++ workers/sneakerWorkers/rebuildkLineToRedisWorker.go | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/workers/sneakerWorkers/kLineWorker.go b/workers/sneakerWorkers/kLineWorker.go index debbdc6..bd22ae2 100644 --- a/workers/sneakerWorkers/kLineWorker.go +++ b/workers/sneakerWorkers/kLineWorker.go @@ -73,6 +73,7 @@ func calculateInDB(marketId int, period, begin, end int64) (k KLine) { } backupDB.Save(&k) backupDB.DbCommit() + synToRedis(&k) return } @@ -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 } @@ -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)) + +} diff --git a/workers/sneakerWorkers/rebuildkLineToRedisWorker.go b/workers/sneakerWorkers/rebuildkLineToRedisWorker.go index db813ae..cec4253 100644 --- a/workers/sneakerWorkers/rebuildkLineToRedisWorker.go +++ b/workers/sneakerWorkers/rebuildkLineToRedisWorker.go @@ -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 {