1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

Add connection status check example and documentation. (#2340)

* Adds example for transactions with arbitrary commands.

* Formatting.

* Adds isReady doc and example for isReady and isOpen.

* Improved example.

* Added isOpen explanation.

* Removed example from a different PR.
This commit is contained in:
Simon Prickett
2022-12-13 20:19:45 +00:00
committed by GitHub
parent 118dc11191
commit da3face951
3 changed files with 57 additions and 25 deletions

View File

@@ -0,0 +1,28 @@
// 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}`);
await client.quit();