1
0
mirror of https://github.com/redis/node-redis.git synced 2025-07-31 05:44:24 +03:00
Files
node-redis/examples/check-connection-status.js
Shaya Potter b2d35c5286 V5 bringing RESP3, Sentinel and TypeMapping to node-redis
RESP3 Support
   - Some commands responses in RESP3 aren't stable yet and therefore return an "untyped" ReplyUnion.
 
Sentinel

TypeMapping

Correctly types Multi commands

Note: some API changes to be further documented in v4-to-v5.md
2024-10-15 17:46:52 +03:00

29 lines
1.0 KiB
JavaScript

// Check the connection status of the Redis client instance.
import { createClient } from 'redis';
const client = createClient();
console.log('Before client.connect()...');
// isOpen will return False here as the client's socket is not open yet.
// isReady will return False here, client is not yet ready to use.
console.log(`client.isOpen: ${client.isOpen}, client.isReady: ${client.isReady}`);
// Begin connection process...
const connectPromise = client.connect();
console.log('After client.connect()...');
// isOpen will return True here as the client's socket is open now.
// isReady will return False here as the promise hasn't resolved yet.
console.log(`client.isOpen: ${client.isOpen}, client.isReady: ${client.isReady}`);
await connectPromise;
console.log('Afer connectPromise has resolved...');
// isOpen will return True here as the client's socket is open now.
// isReady will return True here, client is ready to use.
console.log(`client.isOpen: ${client.isOpen}, client.isReady: ${client.isReady}`);
client.destroy();