To store data in Redis, we first define a key and then set the value. For example, to add a Redis Hash:
hset participant-id:0001 name satya
If we know the key ahead of time, this works great for retrieving a value.
However, what about scenarios where there’s data in the cache that needs to be searched or aggregated? For example, a product, stores or transactions by a particular vendor?
Typically this is where a key/value model starts to show its limitations. To search or carry out processing, large transfers of data may be required by a client application.
RediSearch adds search capabilities to Redis and includes many other powerful features, and it does so right where your data lives. This means you can process much larger volumes of data and at greater speed.
Quickstart: Create a Redis Enterprise cache
Please note: When creating your Redis Enterprise cache, in the Advanced tab, select the “RedisJson” and “RediSearch” modules. This will force you to select the “Enterprise” Clustering Policy.
[
{
"id": 15970,
"gender": "Men",
"season":["Fall", "Winter"],
"description": "Turtle Check Men Navy Blue Shirt",
"price": 34.95,
"city": "Boston",
"location": "42.361145, -71.057083"
},
{
"id": 59263,
"gender": "Women",
"season": ["Fall", "Winter", "Spring", "Summer"],
"description": "Titan Women Silver Watch",
"price": 129.99,
"city": "Dallas",
"location": "32.779167, -96.808891"
},
{
"id": 46885,
"gender": "Boys",
"season": ["Fall"],
"description": "Ben 10 Boys Navy Blue Slippers",
"price": 45.99,
"city": "Denver",
"location": "39.742043, -104.991531"
}
]
JSON.SET product:15970 $ '{"id": 15970, "gender": "Men", "season":["Fall", "Winter"], "description": "Turtle Check Men Navy Blue Shirt", "price": 34.95, "city": "Boston", "coords": "-71.057083, 42.361145"}'
JSON.SET product:59263 $ '{"id": 59263, "gender": "Women", "season":["Fall", "Winter", "Spring", "Summer"],"description": "Titan Women Silver Watch", "price": 129.99, "city": "Dallas", "coords": "-96.808891, 32.779167"}'
JSON.SET product:46885 $ '{"id": 46885, "gender": "Boys", "season":["Fall"], "description": "Ben 10 Boys Navy Blue Slippers", "price": 45.99, "city": "Denver", "coords": "-104.991531, 39.742043"}'
FT.CREATE idx1 ON JSON PREFIX 1 product: SCHEMA $.id as id NUMERIC $.gender as gender TAG $.season.* AS season TAG $.description AS description TEXT $.price AS price NUMERIC $.city AS city TEXT $.coords AS coords GEO
"OK"
Find all documents for a given index.
FT.SEARCH idx1 *
1) "3"
2) "product:46885"
3) 1) "$"
2) "{\"id\":46885,\"gender\":\"Boys\",\"season\":[\"Fall\"],\"description\":\"Ben 10 Boys Navy Blue Slippers\",\"price\":45.99,\"city\":\"Denver\",\"coords\":\"-104.991531, 39.742043\"}"
4) "product:59263"
5) 1) "$"
2) "{\"id\":59263,\"gender\":\"Women\",\"season\":[\"Fall\",\"Winter\",\"Spring\",\"Summer\"],\"description\":\"Titan Women Silver Watch\",\"price\":129.99,\"city\":\"Dallas\",\"coords\":\"-96.808891, 32.779167\"}"
6) "product:15970"
7) 1) "$"
2) "{\"id\":15970,\"gender\":\"Men\",\"season\":[\"Fall\",\"Winter\"],\"description\":\"Turtle Check Men Navy Blue Shirt\",\"price\":34.95,\"city\":\"Boston\",\"coords\":\"-71.057083, 42.361145\"}"
Find all documents with a given word in a text field.
FT.SEARCH idx1 '@description:Slippers'
1) "1"
2) "product:46885"
3) 1) "$"
2) "{\"id\":46885,\"gender\":\"Boys\",\"season\":[\"Fall\"],\"description\":\"Ben 10 Boys Navy Blue Slippers\",\"price\":45.99,\"city\":\"Denver\",\"coords\":\"-104.991531, 39.742043\"}"
Find all documents with a given phrase in a text field.
FT.SEARCH idx1 '@description:("Blue Shirt")'
1) "1"
2) "product:15970"
3) 1) "$"
2) "{\"id\":15970,\"gender\":\"Men\",\"season\":[\"Fall\",\"Winter\"],\"description\":\"Turtle Check Men Navy Blue Shirt\",\"price\":34.95,\"city\":\"Boston\",\"coords\":\"-71.057083, 42.361145\"}"
Find all documents with a numeric field in a given range.
FT.SEARCH idx1 '@price:[40,130]'
1) "2"
2) "product:46885"
3) 1) "$"
2) "{\"id\":46885,\"gender\":\"Boys\",\"season\":[\"Fall\"],\"description\":\"Ben 10 Boys Navy Blue Slippers\",\"price\":45.99,\"city\":\"Denver\",\"coords\":\"-104.991531, 39.742043\"}"
4) "product:59263"
5) 1) "$"
2) "{\"id\":59263,\"gender\":\"Women\",\"season\":[\"Fall\",\"Winter\",\"Spring\",\"Summer\"],\"description\":\"Titan Women Silver Watch\",\"price\":129.99,\"city\":\"Dallas\",\"coords\":\"-96.808891, 32.779167\"}"
Find all documents that contain a given value in an array field (tag).
FT.SEARCH idx1 '@season:{Spring}'
1) "1"
2) "product:59263"
3) 1) "$"
2) "{\"id\":59263,\"gender\":\"Women\",\"season\":[\"Fall\",\"Winter\",\"Spring\",\"Summer\"],\"description\":\"Titan Women Silver Watch\",\"price\":129.99,\"city\":\"Dallas\",\"coords\":\"-96.808891, 32.779167\"}"
Find all documents contain both a numeric field in a range and a word in a text field.
FT.SEARCH idx1 '@price:[40, 100] @description:Blue'
1) "1"
2) "product:46885"
3) 1) "$"
2) "{\"id\":46885,\"gender\":\"Boys\",\"season\":[\"Fall\"],\"description\":\"Ben 10 Boys Navy Blue Slippers\",\"price\":45.99,\"city\":\"Denver\",\"coords\":\"-104.991531, 39.742043\"}"
Find all documents that either match tag value or text value.
FT.SEARCH idx1 '(@gender:{Women})|(@city:Boston)'
1) "2"
2) "product:59263"
3) 1) "$"
2) "{\"id\":59263,\"gender\":\"Women\",\"season\":[\"Fall\",\"Winter\",\"Spring\",\"Summer\"],\"description\":\"Titan Women Silver Watch\",\"price\":129.99,\"city\":\"Dallas\",\"coords\":\"-96.808891, 32.779167\"}"
4) "product:15970"
5) 1) "$"
2) "{\"id\":15970,\"gender\":\"Men\",\"season\":[\"Fall\",\"Winter\"],\"description\":\"Turtle Check Men Navy Blue Shirt\",\"price\":34.95,\"city\":\"Boston\",\"coords\":\"-71.057083, 42.361145\"}"
Find all documents that do not contain a given word in a text field.
FT.SEARCH idx1 '-(@description:Shirt)'
1) "2"
2) "product:46885"
3) 1) "$"
2) "{\"id\":46885,\"gender\":\"Boys\",\"season\":[\"Fall\"],\"description\":\"Ben 10 Boys Navy Blue Slippers\",\"price\":45.99,\"city\":\"Denver\",\"coords\":\"-104.991531, 39.742043\"}"
4) "product:59263"
5) 1) "$"
2) "{\"id\":59263,\"gender\":\"Women\",\"season\":[\"Fall\",\"Winter\",\"Spring\",\"Summer\"],\"description\":\"Titan Women Silver Watch\",\"price\":129.99,\"city\":\"Dallas\",\"coords\":\"-96.808891, 32.779167\"}"
Find all documents that have a word that begins with a given prefix value.
FT.SEARCH idx1 '@description:Nav*'
1) "2"
2) "product:46885"
3) 1) "$"
2) "{\"id\":46885,\"gender\":\"Boys\",\"season\":[\"Fall\"],\"description\":\"Ben 10 Boys Navy Blue Slippers\",\"price\":45.99,\"city\":\"Denver\",\"coords\":\"-104.991531, 39.742043\"}"
4) "product:15970"
5) 1) "$"
2) "{\"id\":15970,\"gender\":\"Men\",\"season\":[\"Fall\",\"Winter\"],\"description\":\"Turtle Check Men Navy Blue Shirt\",\"price\":34.95,\"city\":\"Boston\",\"coords\":\"-71.057083, 42.361145\"}"
Find all documents that contain a word that ends with a given suffix value.
FT.SEARCH idx1 '@description:*Watch'
1) "1"
2) "product:59263"
3) 1) "$"
2) "{\"id\":59263,\"gender\":\"Women\",\"season\":[\"Fall\",\"Winter\",\"Spring\",\"Summer\"],\"description\":\"Titan Women Silver Watch\",\"price\":129.99,\"city\":\"Dallas\",\"coords\":\"-96.808891, 32.779167\"}"
Find all documents that contain a word that is within 1 Levenshtein distance of a given word.
FT.SEARCH idx1 '@description:%wavy%'
1) "2"
2) "product:46885"
3) 1) "$"
2) "{\"id\":46885,\"gender\":\"Boys\",\"season\":[\"Fall\"],\"description\":\"Ben 10 Boys Navy Blue Slippers\",\"price\":45.99,\"city\":\"Denver\",\"coords\":\"-104.991531, 39.742043\"}"
4) "product:15970"
5) 1) "$"
2) "{\"id\":15970,\"gender\":\"Men\",\"season\":[\"Fall\",\"Winter\"],\"description\":\"Turtle Check Men Navy Blue Shirt\",\"price\":34.95,\"city\":\"Boston\",\"coords\":\"-71.057083, 42.361145\"}"
Find all documents that have geographic coordinates within a given range of a given coordinate. Colorado Springs coords (long, lat) = -104.800644, 38.846127
FT.SEARCH idx1 '@coords:[-104.800644 38.846127 100 mi]'
1) "1"
2) "product:46885"
3) 1) "$"
2) "{\"id\":46885,\"gender\":\"Boys\",\"season\":[\"Fall\"],\"description\":\"Ben 10 Boys Navy Blue Slippers\",\"price\":45.99,\"city\":\"Denver\",\"coords\":\"-104.991531, 39.742043\"}"