-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.js
37 lines (30 loc) · 1016 Bytes
/
demo.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
34
35
36
37
const redisClient = require('./redis');
const redisDemo = async () => {
// Add a new user...
const user = {
username: 'demo',
firstname: 'Demo',
lastname: 'User',
city: 'Demoville',
country: 'Demoland',
};
await redisClient.sadd('usernames', user.username);
await redisClient.hset('user:demo', user);
console.log(`Created user:demo.`);
const userInfo = await redisClient.hgetall('user:demo');
console.log('Read user:demo from Redis:');
console.log(userInfo);
// Create a new chat message in 'tech', creating that channel if necessary and adding its
// name to the global "channels" set.
await redisClient.sadd('channels', 'tech');
const messageId = await redisClient.xadd('channel:tech', '*', 'type', 'message');
const message = {
channel: 'tech',
username: 'demo',
message: 'Hello, glad to be here!',
};
await redisClient.hset(`message:${messageId}`, message);
console.log(`Added message:${messageId}`);
redisClient.quit();
};
redisDemo();