diff --git a/apps/server/package.json b/apps/server/package.json index 236abee..3e448e7 100644 --- a/apps/server/package.json +++ b/apps/server/package.json @@ -20,15 +20,16 @@ "test:e2e": "jest --config ./test/jest-e2e.json" }, "dependencies": { - "@nestjs/common": "^10.0.0", + "@nestjs/common": "^10.3.10", "@nestjs/core": "^10.0.0", "@nestjs/platform-express": "^10.0.0", + "@nicestack/common": "workspace:^", "@trpc/server": "11.0.0-rc.456", + "ioredis": "^5.4.1", "reflect-metadata": "^0.2.0", "rxjs": "^7.8.1", "superjson-cjs": "^2.2.3", - "zod": "^3.23.8", - "@nicestack/common": "workspace:^" + "zod": "^3.23.8" }, "devDependencies": { "@nestjs/cli": "^10.0.0", diff --git a/apps/server/src/app.module.ts b/apps/server/src/app.module.ts index abe041e..cd35472 100644 --- a/apps/server/src/app.module.ts +++ b/apps/server/src/app.module.ts @@ -2,10 +2,13 @@ import { Module } from '@nestjs/common'; import { AppController } from './app.controller'; import { AppService } from './app.service'; import { TrpcModule } from './trpc/trpc.module'; +import { RedisService } from './redis/redis.service'; + +import { RedisModule } from './redis/redis.module'; @Module({ - imports: [TrpcModule], + imports: [TrpcModule, RedisModule], controllers: [AppController], - providers: [AppService], + providers: [AppService, RedisService], }) export class AppModule { } diff --git a/apps/server/src/redis/redis.module.ts b/apps/server/src/redis/redis.module.ts new file mode 100644 index 0000000..3558eec --- /dev/null +++ b/apps/server/src/redis/redis.module.ts @@ -0,0 +1,10 @@ +// redis.module.ts +import { Module } from '@nestjs/common'; +import { RedisService } from './redis.service'; + +@Module({ + providers: [RedisService], // 注册 RedisService 作为提供者 + exports: [RedisService], // 导出 RedisService + +}) +export class RedisModule { } diff --git a/apps/server/src/redis/redis.service.ts b/apps/server/src/redis/redis.service.ts new file mode 100644 index 0000000..7b12de6 --- /dev/null +++ b/apps/server/src/redis/redis.service.ts @@ -0,0 +1,23 @@ +import { Injectable } from '@nestjs/common'; +import Redis from 'ioredis'; + +@Injectable() +export class RedisService { + private readonly redisClient: Redis; + + constructor() { + this.redisClient = new Redis({ + host: process.env.REDIS_HOST, + port: parseInt(process.env.REDIS_PORT!), // Redis 服务器的端口 + }); + } + + setValue(key: string, value: string) { + return this.redisClient.set(key, value); + } + + getValue(key: string) { + return this.redisClient.get(key); + } +} + diff --git a/docker-compose.exmaple.yml b/docker-compose.exmaple.yml index 3805e70..6a4fe71 100755 --- a/docker-compose.exmaple.yml +++ b/docker-compose.exmaple.yml @@ -33,45 +33,45 @@ services: interval: 30s timeout: 20s retries: 3 - etcd: - container_name: milvus-etcd - image: quay.io/coreos/etcd:v3.5.5 - environment: - - ETCD_AUTO_COMPACTION_MODE=revision - - ETCD_AUTO_COMPACTION_RETENTION=1000 - - ETCD_QUOTA_BACKEND_BYTES=4294967296 - - ETCD_SNAPSHOT_COUNT=50000 - volumes: - - ${DOCKER_VOLUME_DIRECTORY:-.}/volumes/etcd:/etcd - command: etcd -advertise-client-urls=http://127.0.0.1:2379 -listen-client-urls http://0.0.0.0:2379 --data-dir /etcd - healthcheck: - test: [ "CMD", "etcdctl", "endpoint", "health" ] - interval: 30s - timeout: 20s - retries: 3 - standalone: - container_name: milvus-standalone - image: milvusdb/milvus:v2.4.4 - command: [ "milvus", "run", "standalone" ] - security_opt: - - seccomp:unconfined - environment: - ETCD_ENDPOINTS: etcd:2379 - MINIO_ADDRESS: minio:9000 - volumes: - - ${DOCKER_VOLUME_DIRECTORY:-.}/volumes/milvus:/var/lib/milvus - healthcheck: - test: [ "CMD", "curl", "-f", "http://localhost:9091/healthz" ] - interval: 30s - start_period: 90s - timeout: 20s - retries: 3 - ports: - - "19530:19530" - - "9091:9091" - depends_on: - - "etcd" - - "minio" + # etcd: + # container_name: milvus-etcd + # image: quay.io/coreos/etcd:v3.5.5 + # environment: + # - ETCD_AUTO_COMPACTION_MODE=revision + # - ETCD_AUTO_COMPACTION_RETENTION=1000 + # - ETCD_QUOTA_BACKEND_BYTES=4294967296 + # - ETCD_SNAPSHOT_COUNT=50000 + # volumes: + # - ${DOCKER_VOLUME_DIRECTORY:-.}/volumes/etcd:/etcd + # command: etcd -advertise-client-urls=http://127.0.0.1:2379 -listen-client-urls http://0.0.0.0:2379 --data-dir /etcd + # healthcheck: + # test: [ "CMD", "etcdctl", "endpoint", "health" ] + # interval: 30s + # timeout: 20s + # retries: 3 + # standalone: + # container_name: milvus-standalone + # image: milvusdb/milvus:v2.4.4 + # command: [ "milvus", "run", "standalone" ] + # security_opt: + # - seccomp:unconfined + # environment: + # ETCD_ENDPOINTS: etcd:2379 + # MINIO_ADDRESS: minio:9000 + # volumes: + # - ${DOCKER_VOLUME_DIRECTORY:-.}/volumes/milvus:/var/lib/milvus + # healthcheck: + # test: [ "CMD", "curl", "-f", "http://localhost:9091/healthz" ] + # interval: 30s + # start_period: 90s + # timeout: 20s + # retries: 3 + # ports: + # - "19530:19530" + # - "9091:9091" + # depends_on: + # - "etcd" + # - "minio" pgadmin: image: dpage/pgadmin4 ports: @@ -91,6 +91,12 @@ services: command: -verbose -s3-bucket lxminiapp -s3-endpoint http://minio:9000 volumes: - ./volumes/tusd:/data + redis: + image: redis:latest + ports: + - "6379:6379" + volumes: + - ./volumes/redis:/data # app: # image: lxminiapp # ports: @@ -133,4 +139,4 @@ volumes: worker-data: networks: default: - name: lxminiapp + name: nice-library