I have an error for this line of code
<code>const RedisStore = connectRedis(session);
</code>
<code>const RedisStore = connectRedis(session);
</code>
const RedisStore = connectRedis(session);
My error
<code>This expression is not callable.
Type 'typeof import("e:/farhad/my projects/New folder (2)/poker-game/node_modules/connect-redis/dist/connect-redis")' has no call signatures.ts
</code>
<code>This expression is not callable.
Type 'typeof import("e:/farhad/my projects/New folder (2)/poker-game/node_modules/connect-redis/dist/connect-redis")' has no call signatures.ts
</code>
This expression is not callable.
Type 'typeof import("e:/farhad/my projects/New folder (2)/poker-game/node_modules/connect-redis/dist/connect-redis")' has no call signatures.ts
My code :
<code>import { injectable, inject } from 'inversify';
import Redis from 'ioredis';
import { ILogger } from './../interfaces/ILogger';
import { COMMON_TYPES } from "../types/types";
import session from 'express-session';
import connectRedis from 'connect-redis';
const RedisStore = connectRedis(session);
@injectable()
class RedisManager {
private redisMaster: Redis;
private redisSlave: Redis;
private redisStore: RedisStore;
constructor(
@inject(COMMON_TYPES.iLogger) private logger: ILogger
) {
this.redisMaster = new Redis({
host: 'master-redis-host',
port: 6379,
db: 0,
});
this.redisSlave = new Redis({
host: 'slave-redis-host',
port: 6379,
db: 0,
});
this.redisStore = new RedisStore({
client: this.redisMaster,
ttl: 3600,
});
this.redisMaster.on('connect', () => {
this.logger.info('Connected to Redis Master successfully');
});
this.redisSlave.on('connect', () => {
this.logger.info('Connected to Redis Slave successfully');
});
this.redisMaster.on('error', (err) => {
this.handleError(err, 'Master');
});
this.redisSlave.on('error', (err) => {
this.handleError(err, 'Slave');
});
}
private handleError(error: unknown, source: string): void {
if (error instanceof Error) {
this.logger.error(`${source} Redis error: ${error.message}`);
} else {
this.logger.error(`${source} Redis error: Unknown error`);
}
}
public configureSession() {
return session({
store: this.redisStore,
secret: 'your-secret-key',
resave: false,
saveUninitialized: false,
cookie: { secure: false },
});
}
async setMaster(key: string, value: any): Promise<void> {
try {
await this.redisMaster.set(key, JSON.stringify(value));
this.logger.info(`Data stored in Redis Master: ${key}`);
} catch (error) {
this.handleError(error, 'Master');
}
}
async getSlave(key: string): Promise<any | null> {
try {
const data = await this.redisSlave.get(key);
if (data) {
this.logger.info(`Data retrieved from Redis Slave: ${key}`);
return JSON.parse(data);
} else {
this.logger.warn(`No data found for key in Redis Slave: ${key}`);
return null;
}
} catch (error) {
this.handleError(error, 'Slave');
return null;
}
}
async getMaster(key: string): Promise<any | null> {
try {
const data = await this.redisMaster.get(key);
if (data) {
this.logger.info(`Data retrieved from Redis Master: ${key}`);
return JSON.parse(data);
} else {
this.logger.warn(`No data found for key in Redis Master: ${key}`);
return null;
}
} catch (error) {
this.handleError(error, 'Master');
return null;
}
}
async deleteMaster(key: string): Promise<void> {
try {
await this.redisMaster.del(key);
this.logger.info(`Data deleted from Redis Master: ${key}`);
} catch (error) {
this.handleError(error, 'Master');
}
}
async deleteSlave(key: string): Promise<void> {
try {
await this.redisSlave.del(key);
this.logger.info(`Data deleted from Redis Slave: ${key}`);
} catch (error) {
this.handleError(error, 'Slave');
}
}
}
export default RedisManager;
</code>
<code>import { injectable, inject } from 'inversify';
import Redis from 'ioredis';
import { ILogger } from './../interfaces/ILogger';
import { COMMON_TYPES } from "../types/types";
import session from 'express-session';
import connectRedis from 'connect-redis';
const RedisStore = connectRedis(session);
@injectable()
class RedisManager {
private redisMaster: Redis;
private redisSlave: Redis;
private redisStore: RedisStore;
constructor(
@inject(COMMON_TYPES.iLogger) private logger: ILogger
) {
this.redisMaster = new Redis({
host: 'master-redis-host',
port: 6379,
db: 0,
});
this.redisSlave = new Redis({
host: 'slave-redis-host',
port: 6379,
db: 0,
});
this.redisStore = new RedisStore({
client: this.redisMaster,
ttl: 3600,
});
this.redisMaster.on('connect', () => {
this.logger.info('Connected to Redis Master successfully');
});
this.redisSlave.on('connect', () => {
this.logger.info('Connected to Redis Slave successfully');
});
this.redisMaster.on('error', (err) => {
this.handleError(err, 'Master');
});
this.redisSlave.on('error', (err) => {
this.handleError(err, 'Slave');
});
}
private handleError(error: unknown, source: string): void {
if (error instanceof Error) {
this.logger.error(`${source} Redis error: ${error.message}`);
} else {
this.logger.error(`${source} Redis error: Unknown error`);
}
}
public configureSession() {
return session({
store: this.redisStore,
secret: 'your-secret-key',
resave: false,
saveUninitialized: false,
cookie: { secure: false },
});
}
async setMaster(key: string, value: any): Promise<void> {
try {
await this.redisMaster.set(key, JSON.stringify(value));
this.logger.info(`Data stored in Redis Master: ${key}`);
} catch (error) {
this.handleError(error, 'Master');
}
}
async getSlave(key: string): Promise<any | null> {
try {
const data = await this.redisSlave.get(key);
if (data) {
this.logger.info(`Data retrieved from Redis Slave: ${key}`);
return JSON.parse(data);
} else {
this.logger.warn(`No data found for key in Redis Slave: ${key}`);
return null;
}
} catch (error) {
this.handleError(error, 'Slave');
return null;
}
}
async getMaster(key: string): Promise<any | null> {
try {
const data = await this.redisMaster.get(key);
if (data) {
this.logger.info(`Data retrieved from Redis Master: ${key}`);
return JSON.parse(data);
} else {
this.logger.warn(`No data found for key in Redis Master: ${key}`);
return null;
}
} catch (error) {
this.handleError(error, 'Master');
return null;
}
}
async deleteMaster(key: string): Promise<void> {
try {
await this.redisMaster.del(key);
this.logger.info(`Data deleted from Redis Master: ${key}`);
} catch (error) {
this.handleError(error, 'Master');
}
}
async deleteSlave(key: string): Promise<void> {
try {
await this.redisSlave.del(key);
this.logger.info(`Data deleted from Redis Slave: ${key}`);
} catch (error) {
this.handleError(error, 'Slave');
}
}
}
export default RedisManager;
</code>
import { injectable, inject } from 'inversify';
import Redis from 'ioredis';
import { ILogger } from './../interfaces/ILogger';
import { COMMON_TYPES } from "../types/types";
import session from 'express-session';
import connectRedis from 'connect-redis';
const RedisStore = connectRedis(session);
@injectable()
class RedisManager {
private redisMaster: Redis;
private redisSlave: Redis;
private redisStore: RedisStore;
constructor(
@inject(COMMON_TYPES.iLogger) private logger: ILogger
) {
this.redisMaster = new Redis({
host: 'master-redis-host',
port: 6379,
db: 0,
});
this.redisSlave = new Redis({
host: 'slave-redis-host',
port: 6379,
db: 0,
});
this.redisStore = new RedisStore({
client: this.redisMaster,
ttl: 3600,
});
this.redisMaster.on('connect', () => {
this.logger.info('Connected to Redis Master successfully');
});
this.redisSlave.on('connect', () => {
this.logger.info('Connected to Redis Slave successfully');
});
this.redisMaster.on('error', (err) => {
this.handleError(err, 'Master');
});
this.redisSlave.on('error', (err) => {
this.handleError(err, 'Slave');
});
}
private handleError(error: unknown, source: string): void {
if (error instanceof Error) {
this.logger.error(`${source} Redis error: ${error.message}`);
} else {
this.logger.error(`${source} Redis error: Unknown error`);
}
}
public configureSession() {
return session({
store: this.redisStore,
secret: 'your-secret-key',
resave: false,
saveUninitialized: false,
cookie: { secure: false },
});
}
async setMaster(key: string, value: any): Promise<void> {
try {
await this.redisMaster.set(key, JSON.stringify(value));
this.logger.info(`Data stored in Redis Master: ${key}`);
} catch (error) {
this.handleError(error, 'Master');
}
}
async getSlave(key: string): Promise<any | null> {
try {
const data = await this.redisSlave.get(key);
if (data) {
this.logger.info(`Data retrieved from Redis Slave: ${key}`);
return JSON.parse(data);
} else {
this.logger.warn(`No data found for key in Redis Slave: ${key}`);
return null;
}
} catch (error) {
this.handleError(error, 'Slave');
return null;
}
}
async getMaster(key: string): Promise<any | null> {
try {
const data = await this.redisMaster.get(key);
if (data) {
this.logger.info(`Data retrieved from Redis Master: ${key}`);
return JSON.parse(data);
} else {
this.logger.warn(`No data found for key in Redis Master: ${key}`);
return null;
}
} catch (error) {
this.handleError(error, 'Master');
return null;
}
}
async deleteMaster(key: string): Promise<void> {
try {
await this.redisMaster.del(key);
this.logger.info(`Data deleted from Redis Master: ${key}`);
} catch (error) {
this.handleError(error, 'Master');
}
}
async deleteSlave(key: string): Promise<void> {
try {
await this.redisSlave.del(key);
this.logger.info(`Data deleted from Redis Slave: ${key}`);
} catch (error) {
this.handleError(error, 'Slave');
}
}
}
export default RedisManager;
New contributor
NoBody is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.