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

BC-6040 - Redis Packages Update for Server and legacy client #4641

Merged
merged 14 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions apps/server/src/infra/cache/cache.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@ import { Configuration } from '@hpi-schul-cloud/commons/lib';
import { CacheModule, CacheModuleOptions } from '@nestjs/cache-manager';
import { Module } from '@nestjs/common';
import { LegacyLogger, LoggerModule } from '@src/core/logger';
import { create } from 'cache-manager-redis-store';
import { RedisClient } from 'redis';
import { redisStore } from 'cache-manager-redis-yet';
import { CacheStoreType } from './interface';
import { CacheService } from './service/cache.service';

@Module({
imports: [
CacheModule.registerAsync({
useFactory: (cacheService: CacheService, logger: LegacyLogger): CacheModuleOptions => {
useFactory: async (cacheService: CacheService, logger: LegacyLogger): Promise<CacheModuleOptions> => {
if (cacheService.getStoreType() === CacheStoreType.REDIS) {
const redisUrl: string = Configuration.get('REDIS_URI') as string;
const store = create({ url: redisUrl });
const client: RedisClient = store.getClient();
const store = await redisStore({ url: redisUrl });
const { client } = store;

client.on('error', (error) => logger.error(error));
client.on('connect', (msg) => logger.log(msg));
Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/infra/redis/redis.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Configuration } from '@hpi-schul-cloud/commons/lib';
import { Module } from '@nestjs/common';
import { LegacyLogger, LoggerModule } from '@src/core/logger';
import { createClient, RedisClient } from 'redis';
import { createClient, RedisClientType } from 'redis';
import { REDIS_CLIENT } from './interface/redis.constants';

@Module({
Expand All @@ -14,7 +14,7 @@ import { REDIS_CLIENT } from './interface/redis.constants';

if (Configuration.has('REDIS_URI')) {
const redisUrl: string = Configuration.get('REDIS_URI') as string;
const client: RedisClient = createClient({ url: redisUrl });
const client: RedisClientType = createClient({ url: redisUrl });

client.on('error', (error) => logger.error(error));
client.on('connect', (msg) => logger.log(msg));
Expand Down
19 changes: 11 additions & 8 deletions apps/server/src/modules/server/server.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Configuration } from '@hpi-schul-cloud/commons';
import { MongoDatabaseModuleOptions, MongoMemoryDatabaseModule } from '@infra/database';
import { MailModule } from '@infra/mail';
import { RabbitMQWrapperModule, RabbitMQWrapperTestModule } from '@infra/rabbitmq';
import { REDIS_CLIENT, RedisModule } from '@infra/redis';
import { RedisModule, REDIS_CLIENT } from '@infra/redis';
import { Dictionary, IPrimaryKey } from '@mikro-orm/core';
import { MikroOrmModule, MikroOrmModuleSyncOptions } from '@mikro-orm/nestjs';
import { AccountApiModule } from '@modules/account/account-api.module';
Expand Down Expand Up @@ -36,9 +36,9 @@ import { ALL_ENTITIES } from '@shared/domain/entity';
import { createConfigModuleOptions, DB_PASSWORD, DB_URL, DB_USERNAME } from '@src/config';
import { CoreModule } from '@src/core';
import { LegacyLogger, LoggerModule } from '@src/core/logger';
import connectRedis from 'connect-redis';
import RedisStore from 'connect-redis';
import session from 'express-session';
import { RedisClient } from 'redis';
import { RedisClientType } from 'redis';
import { ServerController } from './controller/server.controller';
import { serverConfig } from './server.config';

Expand Down Expand Up @@ -89,12 +89,15 @@ export const defaultMikroOrmOptions: MikroOrmModuleSyncOptions = {
new NotFoundException(`The requested ${entityName}: ${where} has not been found.`),
};

const setupSessions = (consumer: MiddlewareConsumer, redisClient: RedisClient | undefined, logger: LegacyLogger) => {
const setupSessions = (
consumer: MiddlewareConsumer,
redisClient: RedisClientType | undefined,
logger: LegacyLogger
) => {
const sessionDuration: number = Configuration.get('SESSION__EXPIRES_SECONDS') as number;

let store: connectRedis.RedisStore | undefined;
let store: RedisStore | undefined;
if (redisClient) {
const RedisStore: connectRedis.RedisStore = connectRedis(session);
store = new RedisStore({
client: redisClient,
ttl: sessionDuration,
Expand Down Expand Up @@ -150,7 +153,7 @@ const setupSessions = (consumer: MiddlewareConsumer, redisClient: RedisClient |
})
export class ServerModule implements NestModule {
constructor(
@Inject(REDIS_CLIENT) private readonly redisClient: RedisClient | undefined,
@Inject(REDIS_CLIENT) private readonly redisClient: RedisClientType | undefined,
private readonly logger: LegacyLogger
) {
logger.setContext(ServerModule.name);
Expand Down Expand Up @@ -181,7 +184,7 @@ export class ServerModule implements NestModule {
})
export class ServerTestModule implements NestModule {
constructor(
@Inject(REDIS_CLIENT) private readonly redisClient: RedisClient | undefined,
@Inject(REDIS_CLIENT) private readonly redisClient: RedisClientType | undefined,
private readonly logger: LegacyLogger
) {
logger.setContext(ServerTestModule.name);
Expand Down
Loading
Loading