Skip to content

Commit

Permalink
Revert "BC-6040 - Redis Packages Update for Server and legacy client (#…
Browse files Browse the repository at this point in the history
…4641)"

This reverts commit 272bffe.
  • Loading branch information
virgilchiriac committed Jan 19, 2024
1 parent 1571d13 commit 1e78721
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 397 deletions.
9 changes: 5 additions & 4 deletions apps/server/src/infra/cache/cache.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ 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 { redisStore } from 'cache-manager-redis-yet';
import { create } from 'cache-manager-redis-store';
import { RedisClient } from 'redis';
import { CacheStoreType } from './interface';
import { CacheService } from './service/cache.service';

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

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, RedisClientType } from 'redis';
import { createClient, RedisClient } 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: RedisClientType = createClient({ url: redisUrl });
const client: RedisClient = createClient({ url: redisUrl });

client.on('error', (error) => logger.error(error));
client.on('connect', (msg) => logger.log(msg));
Expand Down
19 changes: 8 additions & 11 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 { RedisModule, REDIS_CLIENT } from '@infra/redis';
import { REDIS_CLIENT, RedisModule } 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 RedisStore from 'connect-redis';
import connectRedis from 'connect-redis';
import session from 'express-session';
import { RedisClientType } from 'redis';
import { RedisClient } from 'redis';
import { ServerController } from './controller/server.controller';
import { serverConfig } from './server.config';

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

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

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

0 comments on commit 1e78721

Please sign in to comment.