Last active
July 7, 2020 09:19
-
-
Save vihoangson/a00d5bafac1f15c13022c087195b19b3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const redis = require("redis"); | |
| const express = require("express"); | |
| console.log(redis); | |
| const port_redis = 6379; | |
| const redis_client = redis.createClient(port_redis); | |
| const app = express() | |
| var io = require('socket.io-client') ; | |
| const socket = io('http://localhost:3000'); | |
| var mysql = require('mysql'); | |
| var connection = mysql.createConnection({ | |
| host: 'localhost', | |
| user: 'root', | |
| password: '111111', | |
| database: 'sns' | |
| }); | |
| connection.connect(); | |
| checkCache = (rep, res, next) => { | |
| console.log(1); | |
| next(); | |
| console.log(11); | |
| } | |
| app.get('/', checkCache, async (req, res) => { | |
| socket.emit('join_channel','channnel1'); | |
| socket.emit('send',{channel:'channel1',event:'mmm',data:'asdasd'}); | |
| socket.on('mmm',(data)=>{ | |
| alert(data); | |
| }); | |
| return res.sendfile("index.html", {a: 1}); | |
| }); | |
| app.get('/mysql', checkCache, async (req, res) => { | |
| connection.query('select * from users', function (error, results, fields) { | |
| if (error) throw error; | |
| return res.json(results); | |
| return res.send('The solution is: ' + JSON.stringify(results)); | |
| }); | |
| }) | |
| app.get('/redis', function (req, res, next) { | |
| next() | |
| }, function (req, res) { | |
| redis_client.get("MESSAGE_0000000095_90_0000000010", (e, data) => { | |
| console.log(2); | |
| return res.json({a: data.toString()}); | |
| }); | |
| }) | |
| app.listen(6544, () => { | |
| console.log('ok port:6544') | |
| }) | |
| // =========================== | |
| // const io = require('socket.io-client'); | |
| // const socket = io.connect('http://',(err)=>{ | |
| // console.log(err); | |
| // }); | |
| // | |
| // socket.on('connect_error', (err) => { | |
| // console.log(err); | |
| // }); | |
| // | |
| // socket.on('connect', () => { | |
| // console.log('Successfully connected!'); | |
| // }); | |
| // | |
| // socket.emit('join_channel',''); | |
| // socket.emit('send',{a:1}); | |
| const redis = require("redis"); | |
| // const express = require("express"); | |
| // console.log(redis); | |
| const port_redis = { | |
| port : 6379, // replace with your port | |
| host : '', // replace with your hostanme or IP address | |
| password : '', | |
| }; | |
| const redis_client = redis.createClient(port_redis); | |
| let returndb = []; | |
| redis_client.keys("*", (e, data) => { | |
| // console.log(data); | |
| data.forEach((v,k)=>{ | |
| // console.log('v:'); | |
| // console.log(v); | |
| // console.log('k:'); | |
| // console.log(k); | |
| redis_client.get(v, (e, data1) => { | |
| //console.log(v+": "); | |
| returndb.push(data1); | |
| }); | |
| }) | |
| console.log(returndb); | |
| }); | |
| // redis_client.get("MESSAGE_0000000138_90_0000000015", (e, data) => { | |
| // console.log(data); | |
| // }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment