Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"ClientClosedError: The client is closed" error in my TypeScript application redis usage #2722

Open
simaybocu opened this issue Mar 20, 2024 · 0 comments
Labels

Comments

@simaybocu
Copy link

Description

In redisUtils file, I created the following code with redis and util package

import * as redis from 'redis';
import { promisify } from 'util';

const redisClient = redis.createClient();

redisClient.on('connect', () => {
    console.log('\x1b[36m', `userapp-redis:`, '\x1b[0m', 'ready');
});

redisClient.on('error', (err) => {
    console.log('\x1b[36m', `userapp-redis:`, '\x1b[0m', 'not connected');
    console.log(`Something went wrong  ${err}`);
});

const setAsync = promisify(redisClient.set).bind(redisClient);
const expireAsync = promisify(redisClient.expire).bind(redisClient);
const getAsync = promisify(redisClient.get).bind(redisClient);
const delAsync = promisify(redisClient.del).bind(redisClient);


export const redisUtils = {
    get: getAsync,
    set: setAsync,
    expire: expireAsync,
    del: delAsync,
}; 

but as an example

import {redisUtils} from '../redis/redisUtils';
const usersData = await redisUtils.get('users');

When I use as return Promise.reject(new errors_1.ClientClosedError());
^
ClientClosedError: The client is closed error.

I want to have a file that I create for common use in this way, but what is it that I wrote that is unnecessary, wrong or incorrect?
Or can you please help me with the redisUtils.ts codes in a better way?

Node.js Version

v20.11.1

Redis Server Version

6.2.1

Node Redis Version

No response

Platform

macOS

Logs

No response

@simaybocu simaybocu added the Bug label Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant