Redis 데이터 타입 - Hash
· Version : Redis 3.2.100 (Windows)
Redis 에서 데이터를 저장할때, 하나의 key 에 여러 개의 Value를 저장할때에는 Hash 데이터 타입을 사용할 수 있다. Hash 데이터 타입은 하나의 key 에 하나 이상의 value 값을 콜론(:)으로 구분하여 데이터를 저장할 수 있다. 기본적으로 필드의 갯수는 제한이 없으며, Value 값에 문자열을 사용할 때는 “string”를 사용한다.
|
order_date:20190426, order_name:”sungwook”:”kang” |
[hmset / hget / hmget]
Hash 타입의 데이터를 입력할때 hmset 명령어를 사용한다. 데이터를 검색할 때에는 hget 명령어를 사용한다.
|
hmset key field value field value ex) hmset order:20190426 customer_name “sungwook” item_name “redis server” item_detail “redis 3.2.100 (windows)” ex) hget order:20190426 customer_name |

Key에 정의된 특정 필드의 value만 출력할 때에는 hmget 을 사용한다.
|
hmget order:20190426 customer_name item_detail |

[hgetall]
특정 key 값의 모든 필드와 value를 검색할 때에는 hgetall 명령을 사용한다.
|
hgetall 20190426 |

[hkeys / hvals]
Key에 대한 모든 field 명을 출력할 때에는 hkeys 명령어를 사용하고, key에 대한 모든 value만 출력할 때에는 hvals 를 사용한다.
|
hkeys order:20190426 hvals order:20190426 |

[hexists]
Key 와 field값으로 필드의 존재 유무를 확인할 때는 hexists 명령어를 사용한다. 반환되는 값이 1이면 검색한 필드가 존재하며 0이면 존재하지 않는 필드이다.
|
hexists order:20190426 customer_name |

[hdel]
Key에 대한 특정 필드를 삭제 하려면 hdel 명령을 사용한다. Item_name의 필드와value가 삭제된 것을 확인할 수 있다다.
|
hdel order:20190426 item_name |

[참고자료]
2019-04-25 / Sungwook Kang / http://sungwookkang.com
Redis, Redis 입력, hget, hmset, hmget, redis 데이터 타입, redis hash 데이터 타입, 레디스 데이터 타입, 레디스 해시
'NoSql, MemoryDB' 카테고리의 다른 글
| Redis 데이터 타입 - Set (0) | 2019.04.30 |
|---|---|
| Redis 데이터 타입 - List (0) | 2019.04.27 |
| Redis 데이터 입력, 수정, 삭제, 조회 (1) | 2019.04.25 |
| Redis - redis-cli를 사용한 Redis Server접속 (0) | 2019.04.24 |
| Redis 설치 (Windows) (1) | 2019.04.23 |