You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

37 lines
843 B

import { InternalServerErrorException } from '@nestjs/common';
import Redis from 'ioredis'
export default class RedisService {
public redis: any
constructor(redisPort: number | null, redisHost: string | null) {
this.redis = new Redis({
port: redisPort || 6379,
host: redisHost || 'localhost',
});
}
async setex(key: string, expiry: number, value: string) {
try {
this.redis.setex(key, expiry, value);
} catch (err) {
throw new InternalServerErrorException(err)
}
}
async set(key: string, value: string) {
try {
this.redis.set(key, value);
} catch (err) {
throw new InternalServerErrorException(err)
}
}
async get(key: string) {
try {
return this.redis.get(key);
} catch (err) {
throw new InternalServerErrorException(err)
}
}
};