728x90
geo.module.ts
0.00MB
geo.service.ts
0.00MB
sub-achievement.service.ts
0.01MB
pinkmong-appear-location.service.ts
0.00MB
서브업적.서비스
async fillGeo() {
// 1. DB에서 모든 서브업적 가져오기
const dbSub: SubAchievement[] = await this.repository.getAll();
if (!dbSub || dbSub.length === 0) {
throw new NotFoundException('DB에 서브업적 데이터가 없습니다.');
}
// 2. GeoService를 활용하여 파이프라인 생성
//const pipeline = this.geoService.multi();
for (const sub of dbSub) {
const key = `sub-achievement:${sub.id}`;
const image =
typeof sub.sub_achievement_images === 'string'
? [sub.sub_achievement_images] // 문자열이면 배열로 변환
: sub.sub_achievement_images;
const subData = {
id: sub.id,
achievement_id: sub.achievement_id,
title: sub.title,
content: sub.content,
longitude: sub.longitude,
latitude: sub.latitude,
sub_achievement_images: image,
mission_type: sub.mission_type as SubAchievementMissionType,
expiration_at: new Date(sub.expiration_at).toISOString(),
created_at: sub.created_at?.toISOString() || '',
updated_at: sub.updated_at?.toISOString() || '',
};
await this.geoService.geoAddBookmarkS(key, subData);
}
return {
message: `✅ ${dbSub.length}개의 서브업적이 GeoService에 저장되었습니다.`,
};
}
Geo 서비스
/**
* Redis에 여러 작업을 일괄 처리하는 파이프라인 생성
*/
multi() {
return this.client.multi(); // multi()는 Redis의 파이프라인 메서드
}
/**
* Redis Geo 데이터에 위치 정보를 추가하고, 추가 속성은 Hash에 저장
* @param key Redis 키
* @param data 북마크 데이터 객체
*/
async geoAddBookmarkS(
key: string,
data: {
id: number;
achievement_id: number;
title: string;
content: string;
longitude: number;
latitude: number;
sub_achievement_images: string[];
mission_type: string;
expiration_at: string | '';
created_at: string | '';
updated_at: string | '';
},
) {
const member = data.id.toString(); // 멤버는 고유 식별자로 사용 (문자열 필요)
// GEO에 위치 데이터 저장
await this.client.geoadd(key, data.longitude, data.latitude, member);
// Hash에 추가 속성 저장
const hashKey = `bookmarkS:${data.id}`;
await this.client.hset(hashKey, {
achievement_id: data.achievement_id,
title: data.title,
content: data.content,
sub_achievement_images: data.sub_achievement_images,
mission_type: data.mission_type,
expiration_at: data.expiration_at,
created_at: data.created_at,
updated_at: data.updated_at,
});
}
'게임서버-스파르타코딩NodeJs_7기 > CH6 최종 프로젝트' 카테고리의 다른 글
도커 핑퐁 (0) | 2025.03.04 |
---|---|
GEO 발키 사용 (0) | 2025.03.04 |
Geo 로 거리 비교 (0) | 2025.03.03 |
MVP 중간발표 회고록 (0) | 2025.03.03 |
흥미유발 요소 추가하기 (0) | 2025.03.03 |