R
R
Roman Mirilaczvili2021-10-13 00:54:53
Node.js
Roman Mirilaczvili, 2021-10-13 00:54:53

Why is the process not ending?

Just started learning Node.js. I'm trying to work with Redis.

I do not understand why the process is not completed. What's wrong?

Took the example from https://github.com/NodeRedis/node-redis and added error handling.

the code

import { createClient } from 'redis';

const redis_url = process.env.REDIS_URL;
console.log('redis: ' + redis_url);

(async () => {
  const client = createClient({ url: redis_url });

  client.on('error', err => console.log('Redis Client Error', err));

  client.on('error', err => {
    console.log('Redis Client Error', err);
    throw new Error('Redis error occurred.');
  });

  await client.connect().catch(err => {
    console.error(err);
    throw new Error('connect error');
  });

  await client.set('key', 'zzz').catch(err => {
    console.error(err);
    throw new Error('set error');
  });

  const value = await client.get('key').catch(err => {
    console.error(err);
    throw new Error('get error');
  });

  console.log('value: ' + value);
})();



Node 16.10
npm [email protected]

If anyone wants to check it out for themselves, they can run it with docker-compose up.
https://github.com/romiras/nodejs-playground/tree/...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2021-10-13
@2ord

On the merits of your question:
What do you think, if you dialed a number on the phone, and the receiver was picked up on the other side, when will the call end?

if you haven't figured it out yet

звонок завершиться не раньше чем вы или тот кому вы звоните повесит трубку. Поэтому погуглите
redis client.quit

и
redis client.end

ну или почитайте тут
ну и напоследок напомню, что иногда полезно читать документацию https://www.npmjs.com/package/redis

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question