>  기사  >  웹 프론트엔드  >  레디스 2

레디스 2

WBOY
WBOY원래의
2024-08-14 17:28:31348검색

Redis 2

Redis - 목록, 세트 및 HashMap

이전 블로그 포스팅에 이어집니다

키-값 쌍 외에 사용 가능한 다른 데이터 유형이 3개 있습니다

기울기

이 데이터 구조는 Python의 목록이나 Javascript 또는 C#의 배열과 유사합니다. 최근에 사용한 항목을 보관하는 데 사용할 수 있습니다. 일반적인 작업은 다음과 같습니다.

Operations Explanations Examples Further Explanation
LPUSH Adds an Item to the beginning of the list LPUSH friends "Sophia" similar to Array.unshift in javascript
LRANGE Get all the items in a list LRANGE friends 0 -1 similiarly a list in python 0 is the first item and -1 is the last item
RPUSH Adds an item to the end of the list RPUSH friends "Poe" similar to Array.push in javascript
LPOP Removes an item from the start of the list LPOP friends "Poe" Will return 1 if Poe exists in the list and 0 otherwise
RPOP Removes an item from the end of the list RPOP friends "Sophia" Will return 1 if Sophia exists in the list and 0 otherwise

세트

고유한 항목만 있는 데이터 구조입니다. Python의 집합, Javascript의 집합 및 C#의 HashSet과 유사합니다. 일반적인 작업은 다음과 같습니다.

Operations Explanations Examples Further Explanation
SADD Adds a value to the set SADD colors "pink"
SMEMBERS returns the members of the set SMEMBERS colors will return all the items in the set colors
SREM Removes members of the set SREM colors "pink" Will return 1 if pink exists in the list and 0 otherwise

해시맵

해시맵은 키 값 쌍의 그룹입니다. 그러나 해시맵은 중첩될 수 없습니다. 이름, 이메일, 전화번호가 있는 사람의 사례 시나리오를 살펴보겠습니다

HSET person name "Joe" # Adds the key-value pair {name : joe} to the hashmap
HSET person email "Joe@joe.com" # Adds the key-value pair {email : Joe@joe.com} to the hashmap
HSET person phone_number "+2345656655413" # Adds the key-value pair {number : ....} to the hashmap

HGET 명령을 사용하여 해시맵의 특정 키 값을 가져올 수 있습니다

HGET person name # returns "Joe"

HGETALL 명령은 해시맵의 모든 키-값 쌍을 명령합니다

HGETALL person 

1) "name"
2) "Joe"
3) "email"
4) "Joe@joe.com"
5) "phone_number"
6) "+2345656655413"

HDEL 명령은 해당 키를 기준으로 키-값 쌍을 삭제합니다

HDEL person name # removes {name : joe}

HEXISTS 명령은 해시세트에 키가 있는지 확인합니다

HEXISTS person name # returns 0 because we've deleted it before

개발자가 알아야 할 기본 명령어 중 대부분입니다.


일반적인 면접 질문

  1. Redis의 정식 의미는 무엇인가요?: Redis는 REmote Dictionary Server

  2. 의 약자입니다.

    데이터 크기 및 유형과 관련하여 Redis의 제한 사항은 무엇입니까?: Redis는 시스템 메모리에 맞는 값을 보유하도록 설계되었습니다. 조인이 있는 복잡한 관계형 모델이나 큰 blob을 구성하는 데는 적합하지 않습니다
  3. Redis를 사용하여 분산 환경에서 캐싱을 어떻게 처리합니까?
  4. : 데이터베이스 앞에 Redis 인스턴스를 캐싱 계층으로 설정하여 캐싱을 처리합니다. 캐시 노드에 따라 키를 배포하기 위해 일관된 해싱을 사용하면 로드가 고르게 분산되고 캐시 누락이 줄어듭니다
  5. Redis에서 목록 데이터 유형은 언제 사용해야 합니까?
  6. : 목록은 내구성 있는 원자 대기열, 작업 대기열, 로그, 버퍼 및 기타 여러 사용 사례에 적합합니다

위 내용은 레디스 2의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
이전 기사:useCallback VS useMemo다음 기사:useCallback VS useMemo