24 lines
912 B
TypeScript
24 lines
912 B
TypeScript
import { Comment } from "../../rdrama/models/Comment";
|
|
import RedisSessionManager from "../session/SessionManager";
|
|
|
|
class RedisCommentService {
|
|
|
|
static async storeComment(comment: Comment): Promise<void> {
|
|
const redisManager = RedisSessionManager.getInstance();
|
|
await redisManager.storeObject('comment', comment.id.toString(), comment);
|
|
}
|
|
|
|
static async retrieveComment(commentId: string): Promise<Comment | null> {
|
|
const redisManager = RedisSessionManager.getInstance();
|
|
const result = await redisManager.retrieveObject('comment', commentId);
|
|
if (result) return result as Comment;
|
|
return null;
|
|
}
|
|
|
|
static async publishComment(comment: Comment): Promise<number> {
|
|
const redisManager = RedisSessionManager.getInstance();
|
|
return redisManager.publishObject('newCommentsChannel', comment);
|
|
}
|
|
}
|
|
|
|
export default RedisCommentService |