분류 전체보기
-
15. 제너레이터 사용하기Python/Grammar 2023. 3. 11. 11:00
💡 제너레이터(generator)란? 이터레이터를 생성해주는 함수로 "발생자"라고 부르기도 한다. 함수 안에서 yield 키워드를 사용함으로써 제너레이터로 동작하는 함수를 만들 수 있다. 제너레이터 객체는 __iter__, __next__ 메소드를 가지고 있으며, 제너레이터 객체에서 __next__ 메소드를 호출할 때마다 함수 안의 마지막 yield까지 코드를 실행하며 yield에서 값을 발생(generate)시킨다. 따라서 이름을 제너레이터라고 한다. 정리해보면 이터레이터를 만드는 방법은 다음 네 가지가 있다. 1. iterable.__iter__() 2. __iter__, __next__ 메소드를 구현한 클래스의 객체 생성 3. __getitem__ 메소드를 구현한 클래스의 객체 생성 4. yield..
-
12. elif를 사용하여 여러 방향으로 분기하기Python/Grammar 2023. 3. 10. 22:14
# 1. elif 사용하기 elif는 "else if"라는 뜻으로 if 조건식이 참이 아닌 상태에서 조건식을 지정할 때 사용한다. elif 여러 개를 사용해 다수 개의 조건을 지정할 수 있으며 적용 예시로는 자판기가 있다. if, else와 같이 조건식 끝에 콜론을 붙이고 다음줄은 들여쓰기를 해야 한다. 단독으로는 사용할 수 없어 if-elif 형태로 사용하거나 if-elif-else 형태로 사용한다. else와 함께 사용할 때는 반드시 elif가 else보다 먼저 와야한다. else는 선행된 모든 조건을 만족하지 않는 조건을 가지기 때문이다. 1-1. if, elif, else 모두 사용하기 모든 상황을 처리하기 위해 if-elif / if-else 형태의 두 가지 분기로는 부족할 때 if-elif-e..
-
11. else를 사용하여 두 방향으로 분기하기Python/Grammar 2023. 3. 9. 23:23
# 1. else 사용하기 1-1. if와 else의 기본 형태와 실행 흐름 알아보기 else의 코드는 if 조건식을 만족하지 않을 때 실행한다. 즉, if 조건식이 True이면 if 본문(if의 코드)이 실행되고 False이면 else 본문(else의 코드)이 실행된다. else 조건문은 단독으로 사용할 수 없으며, 조건식 뒤에 콜론을 붙이는 형식과 실행할 코드를 조건식 다음줄에 들여쓰기 후 작성하는 규칙은 if 조건문과 같다. ❗️ False로 취급하는 것들 - None - False - 0인 숫자들 -> 0, 0.0, 0j - 비어있는 문자열 -> '', "" - 비어있는 리스트 -> [] - 비어있는 튜플 -> () - 비어있는 딕셔너리 -> {} - 비어있는 세트 -> set() - 클래스 인스..
-
[Redis] Sentinel을 이용한 자동 장애조치DataBase/NoSQL 2023. 2. 19. 16:30
1. master-replica-sentinel 구성을 위해 아래와 같이 docker-compose.yml 파일을 작성한다. 2. docker-compose yml파일을 build한다. 3. master, replica, sentinel 3대가 떠 있는 것을 확인한다. 4. sentinel1의 컨테이너에서 redis에 진입해서 바라보고 있는 master의 정보를 확인한다. $ info sentinel 다른 prompt에서 master의 ip주소를 확인한다. $ docker inspect redis-master sentinel1에서 조회한 master의 ip가 실제 master ip와 일치하는 것을 확인할 수 있다. 5. master를 stop한다. sentinel1, sentinel2, senti..
-
[Redis] 서비스 고가용성을 위한 ReplicaDataBase/NoSQL 2023. 2. 19. 15:24
RDB를 사용하거나 AOF를 사용하는 백업방식은 disk에 있는 파일로부터 Redis를 복구하는 방법인데, 백업만으로는 백업 실패 가능성도 있고 복구에 시간도 꽤 소요되는 등 장애 대비에 부족한 측면이 있다. 하지만 Redis 복제를 하면 가용성을 확보할 수 있을 뿐만 아니라 빠른 장애조치가 가능하다. master가 죽었을 경우 복제본(replica)중 하나를 master로 승격시켜 즉시 서비스 정상화가 가능하기 때문이다. replica는 read-only 모드로 사용하는 것이 권장된다. 입력/수정/삭제가 가능하다면 데이터 무결성이 보장되지 않기 때문이다. 또, 하드웨어적인 문제 발생을 대처하기 위해 master와 replica는 물리적으로 다른 머신에 두어야 한다. 아래는 docker를 이용해서 ..
-
에러 해결 - docker: invalid reference format: repository name must be lowercase.Trouble Shooting/Syntax Error 2023. 2. 19. 12:48
나의 경우는 -v 옵션과 argument를 빠뜨려서 에러가 발생했었다. 아래는 에러 해결 과정이다. $ docker run --network host /Users/an_yoojin/Downloads/redis.conf:/redis.conf redis redis-server /redis.conf 명령으로 host의 네트워크를 사용할 수 있도록 --network 옵션을 줘서 컨테이너를 생성하는데 invalid reference format: repository name must be lowercase 에러를 만났다. repository name이 lowercase여야 한다...? 스택오버플로우에서 해결의 실마리가 될 것 같은 질문과 답변을 발견했지만 해결할 수 없었고 https://stackoverflow...
-
새로운 글쓰기 여정의 시작Extracurricular Activites/글또 2023. 1. 30. 22:14
글또 OT 때 알게 되었던 big5검사를 해봤다. 예술적 감각, 성취욕, 지적 호기심 등이 높은 반면 신중함, 계획성등은 부족하다는 결과가 나왔다. 예상했던 대로다. 이 블로그는 2022년 1월 19일에 국비교육을 들으며 야심찬 마음으로 개설했다. 공부한 내용을 정리하기 위해 블로그 운영에 도전했지만 새로운 분야에서 학습한 내용을 보기 좋게 글로 쓸 수 있는 수준까지 이해하는 것은 정말 쉽지 않았다. 작년 7월 입사하며 또다시 마음을 다잡았다. 10월, 11월에는 그래도 열심히 파이썬 기초 문법에 대해 포스팅을 했지만 현재 내 수준보다 높은 업무 난이도와 연말 마감에 치여 또 흐지부지되었다. 글로써 공부한 내용을 출력하는 행위는 공부한 내용을 진짜 내 것으로 만드는 과정임을 잘 알기에(잘 아는 ..
-
사라진 commit을 찾아 push 하기DevOps/Git 2023. 1. 4. 20:55
1. commit의 hash값을 찾는다 $ git reflog 2. 현재 HEAD를 해당 commit의 hash값으로 옮긴다. $ git checkout 76ca7d01 3. commit의 hash값 위에 있는 HEAD를 작업하던 branch에 붙인다. $ git branch master fatal: A branch named 'master' already exists. 위와 같은 에러가 뜨면 강제로 실행! $ git branch master -f 4. 작업하던 branch로 checkout한다. $ git checkout master 5. commit 이력이 원하는대로 변경되었는지 확인한다. $ git log 6. 원격에 commit을 push해서 작업을 마무리한다. $ git push origin m..