Document 형태로 데이터를 저장하기 위해 FT.CREATE 명령어를 사용해야 합니다.
FT.CREATE는 RedisSearch모듈을 통해 전문 검색 인덱스를 생성하는데 사용됩니다.
구체적으로는
FT.CREATE [인덱스 키 값] ON [데이터 형식] PREFIX [접두어 길이][접두어] SCORE [가중치] SCHEMA $.[경로] AS [이름][타입] [가중치][숫자] ... TAG SEPARATOR [구분자]
형식입니다.
FT.CREATE idx:bicycle ON JSON PREFIX 1 bicycle: SCORE 1.0 SCHEMA $.brand AS brand TEXT WEIGHT 1.0 $.model AS model TEXT WEIGHT 1.0 $.description AS description TEXT WEIGHT 1.0 $.price AS price NUMERIC $.condition AS condition TAG SEPARATOR
JSON.SET 명령어를 통해 JSON 데이터를 추가할 수 있습니다.
구체적으로는
JSON.SET [데이터 키][JSON 경로] [{객체}]
형태입니다.
> JSON.SET "bicycle:0" "." "{\"brand\": \"Velorim\", \"model\": \"Jigger\", \"price\": 270, \"description\": \"Small and powerful, the Jigger is the best ride for the smallest of tikes! This is the tiniest kids\\u2019 pedal bike on the market available without a coaster brake, the Jigger is the vehicle of choice for the rare tenacious little rider raring to go.\", \"condition\": \"new\"}"
FT.SEARCH 명령어를 통해 데이터를 가져올 수 있습니다.
구체적으로는
FT.SEARCH [인덱스][조건] LIMIT [시작 인덱스][최대 갯수]
입니다.
1. 모든 튜플 쿼리
> FT.SEARCH "idx:bicycle" "*" LIMIT 0 10
FT.SEARCH "idx:bicycle" "@model:Jigger" LIMIT 0 10
FT.SEARCH "idx:bicycle" "@brand:\"Noka Bikes\"" LIMIT 0 10