Created
November 1, 2021 22:56
-
-
Save pbrumblay/6e3bc34f34cb19734e81ab12b2a6102a 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
import Redis from 'ioredis'; | |
const redis = new Redis({ | |
keyPrefix: "hereIsAPrefixToNamespaceThings:", | |
port: 6379, | |
host: 'localhost', | |
db: 0, | |
connectTimeout: 10000, | |
}); | |
const x = await redis.get('zzz'); | |
console.log(`X FOO: ${JSON.stringify(x)}`); | |
await redis.set('zzz', JSON.stringify({payload: {blargh: 'qqq'}})); | |
const y = await redis.get('foo'); | |
const z = await redis.get('zzz'); | |
console.log(`Y FOO: ${JSON.stringify(y)}`); | |
console.log(`Z FOO: ${JSON.stringify(z)}`); | |
//Redis client leaves connection open. Super. I love old school connection management. | |
redis.disconnect(); | |
const redis2 = new Redis({ | |
port: 6379, | |
host: 'localhost', | |
db: 0, | |
connectTimeout: 10000, | |
}); | |
// ioredis is not applying any magic. It's just a prefix for convenience. | |
const zzz = await redis2.get('hereIsAPrefixToNamespaceThings:foo'); | |
console.log(zzz); | |
redis2.disconnect(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment