diff --git a/.env.sample b/.env.sample index 28a08ee..a619acc 100644 --- a/.env.sample +++ b/.env.sample @@ -5,6 +5,8 @@ DB_USERNAME="" DB_PASSWORD="" DB_HOST="" REDIS_HOST="" +REDIS_PORT="" +REDIS_PASSWORD="" DB_PORT="" DB_NAME="" PUBLIC_VAPID_KEY="" diff --git a/app.js b/app.js index 769d6b7..7904f46 100644 --- a/app.js +++ b/app.js @@ -69,8 +69,8 @@ app.use("/web-subscription", webSubscriptionRoutes); app.use("/line-notify-callback", lineNotifyRoutes); app.use("/telegram-updates", telegramBotRoutes); -// 更新redis資料庫 -updateSymbolData.initialUpdate(); +// // 更新redis資料庫 +// updateSymbolData.initialUpdate(); // 建立webSocket連線 trackPrices(); diff --git a/docker-compose.yml b/docker-compose.yml index 341165f..5aa7973 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,3 @@ -version: '3' services: app: build: . @@ -6,10 +5,13 @@ services: - "8000:8000" depends_on: - mongodb - - redis + # - redis env_file: - ./.env restart: unless-stopped + networks: + - cryptosniper-network + mongodb: image: mongo @@ -21,12 +23,20 @@ services: volumes: - mongodb_data:/data/db restart: unless-stopped + networks: + - cryptosniper-network + + # redis: + # image: redis + # ports: + # - "6379:6379" + # restart: unless-stopped - redis: - image: redis - ports: - - "6379:6379" - restart: unless-stopped volumes: - mongodb_data: \ No newline at end of file + mongodb_data: + +networks: + cryptosniper-network: + external: + name: binance-sync-service_cryptosniper-network diff --git a/models/redis.js b/models/redis.js index f13f3ed..3c02a58 100644 --- a/models/redis.js +++ b/models/redis.js @@ -3,8 +3,22 @@ require("dotenv").config(); const Redis = require("ioredis"); const REDIS_HOST = process.env.REDIS_HOST; -const REDIS_PORT = 6379; -const redis = new Redis(REDIS_PORT, REDIS_HOST); +const REDIS_PORT = process.env.REDIS_PORT; +const REDIS_PASSWORD = process.env.REDIS_PASSWORD; + +const redis = new Redis({ + port: REDIS_PORT, + host: REDIS_HOST, + password: REDIS_PASSWORD, +}); + +redis.set("key", "value", function (err, result) { + if (err) { + console.log("Redis connection error:", err); + } else { + console.log("Redis set result:", result); + } +}); const time_intervals = { "5m": 5, diff --git a/services/updateSymbolData.js b/services/updateSymbolData.js index 8605d12..9a5ce60 100644 --- a/services/updateSymbolData.js +++ b/services/updateSymbolData.js @@ -16,24 +16,24 @@ const timeIntervals = { "1M": 24 * 60 * 60 * 1000, }; -async function initialUpdate() { - try { - setInterval(async () => { - await updateSymbolQuoteVolumeData(); - }, 5 * 60 * 1000); - // 24hr Data - await updateSymbolQuoteVolumeData(); +// async function initialUpdate() { +// try { +// setInterval(async () => { +// await updateSymbolQuoteVolumeData(); +// }, 5 * 60 * 1000); +// // 24hr Data +// await updateSymbolQuoteVolumeData(); - // Klines Data - for (const [timeInterval, intervalMs] of Object.entries(timeIntervals)) { - setInterval(async () => { - await updateSymbolKlinesData(timeInterval); - }, intervalMs); - updateSymbolKlinesData(timeInterval); - } - } catch (error) { - console.error(`Initial update failed: ${error}`); - } -} +// // Klines Data +// for (const [timeInterval, intervalMs] of Object.entries(timeIntervals)) { +// setInterval(async () => { +// await updateSymbolKlinesData(timeInterval); +// }, intervalMs); +// updateSymbolKlinesData(timeInterval); +// } +// } catch (error) { +// console.error(`Initial update failed: ${error}`); +// } +// } -module.exports = { initialUpdate }; +// module.exports = { initialUpdate };