Created
January 20, 2023 12:07
-
-
Save somerongit/424aaec69eac618ada7308c28a4c5ed0 to your computer and use it in GitHub Desktop.
This file contains 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") | |
async function main() { | |
const client = redis.createClient({ | |
socket: { | |
host: "redis.com", | |
port: 1338 | |
}, | |
password: "password" | |
}) | |
await client.connect().then(res => console.log(res)).catch(err => console.log(err)) | |
// Changing the server configuration to receiving all kind of events | |
await client.sendCommand(['config', 'set', 'notify-keyspace-events', 'KEA']).then(res => console.log(res)).catch(err => console.log(err)) | |
// Setting Key for testing | |
await client.setEx("test10Sec", 10, "10").then(res => console.log(res)).catch(err => console.log(err)) | |
// Subscribing on key event channels | |
await client.subscribe('__keyevent@0__:expired', async (msg, _chnl) => { | |
console.log("Event received from(", _chnl, "):", msg); | |
}).then(res => console.log(res)).catch(err => console.log(err)) | |
await client.subscribe('__keyevent@0__:set', async (msg, _chnl) => { | |
console.log("Event received from(", _chnl, "):", msg); | |
}).then(res => console.log(res)).catch(err => console.log(err)) | |
await client.subscribe('__keyevent@0__:hset', async (msg, _chnl) => { | |
console.log("Event received from(", _chnl, "):", msg); | |
}).then(res => console.log(res)).catch(err => console.log(err)) | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment