-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (26 loc) · 836 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const express = require('express')
const app = express()
const port = 8081
var redis = require('redis')
var client = redis.createClient(9000,'redis')
client.set('counter',0,function(err) {
if (err) {
throw err; /* in production, handle errors more gracefully */
}})
app.get('/', (req, res) => res.send('Hello World!'))
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
app.get('/redischeck', (req, res) => {
let counter = client.get('counter', function(err,value) {
if (err) {
throw err;
} else {
console.log(value)
value = parseInt(value)+1
client.set('counter',value,function(err) {
if (err) {
throw err; /* in production, handle errors more gracefully */
}})
res.send('Counter:'+value)
}
})
})