REST
Redis Service provides an easy-to-use and powerful way to create REST
API calls to the Redis server.
1 What Are RESTful Web Services
REST
, or REpresentational State Transfer, is an architectural style for providing standards between computer systems on the web, making it easier for systems to communicate with each other.
- Resource identification through URI: A RESTful web service exposes a set of resources that identify the targets of the interaction with its clients. Resources are identified by URIs, which provide a global addressing space for resource and service discovery
- Uniform interface: Resources are manipulated using a fixed set of four create, read, update, delete operations: PUT, GET, POST, and DELETE. POST creates a new resource, which can be then deleted by using DELETE. GET retrieves the current state of a resource in some representation. PUT transfers a new state onto a resource
- Self-descriptive messages: Resources are decoupled from their representation so that their content can be accessed in a variety of formats, such as HTML, XML, plain text, PDF, XLS, JSON, and others.
- Stateful interactions through hyperlinks: Every interaction with a resource is stateless; that is, request messages are self-contained. Stateful interactions are based on the concept of explicit state transfer.
REST
requires that a client make a request to the server in order to retrieve or modify data on the server. A request generally consists of:
- an HTTP verb, which defines what kind of operation to perform
- a header, which allows the client to pass along information about the request
- a path or URI to a resource
- an optional message body containing data
2 What is Redis and RedisSearch
2.1 Redis
Redis (Remote Dictionary Server) is an in-memory data structure project implementing a distributed, in-memory key-value database with optional durability. Redis supports different kinds of abstract data structures, such as strings, lists, maps, sets, sorted sets, HyperLogLogs, bitmaps, streams, and spatial indexes.
You can read more in redis:
2.2 RediSearch
RediSearch is a powerful text search and secondary indexing engine, built on top of Redis as a Redis module.
Unlike Redis search libraries, it does not use Redis’ internal data structures. Using its own highly optimized data structures and algorithms, RediSearch allows for advanced search features, with high performance and a small memory footprint. It can perform simple text searches as well as complex structured queries, filtering by numeric properties and geographical distances
You can read more in RediSearch:
2.3 Available Redis endpoints
RediSearch documentation explain a los of comands that can be used in here
Some of this comands have been implementated to be easily used from a REST
API Endpoint:
2.3.1 FT.SUGGET
FT.SUGGET command is used to get completion suggestions for a prefix.
Redis FT.SUGGET documentation
The available endpoint to do a FT.SUGGET query is: "/sugget/{key}/{prefix}".
key the suggestion dictionary KEY.
prefix the prefix to complete on.
QueryParams
Param | Param type | Required | Default | Description |
---|---|---|---|---|
fuzzy | Boolean | false | If set, a fuzzy prefix search will be done, including prefixes at Levenshtein distance of 1 from the prefix sent | |
max | Integer | 5 | Limit the results to a maximum of | |
withscores | Boolean | false | If set, redis will also return the score of each suggestion. this can be used to merge results from multiple instances | |
withpayloads | Boolean | false | If set, redis will return optional payloads saved along with the suggestions. If no payload is present for an entry, return will be null |
2.3.2 FT.SEARCH
FT.SEARCH command is used to search the index with a textual query and can return either documents or just ids.
Redis FT.SEARCH documentation
The available endpoint to do a FT.SEARCH query is: "/search/{index}"
index is telling the INDEX where the query will be applied.
QueryParams
Param | Param type | Required | Default | Description |
---|---|---|---|---|
q | String | the text query to search. Info here | ||
limit | Integer | 10 | Limit the number of results to return | |
offset | Integer | 0 | Apply an offset ove the results to return | |
nocontent | Boolean | false | If set, only the document ids will be returned and not the content. This is useful if RediSearch is only an index on an external document collection | |
verbatim | Boolean | false | if set, redis will not try to use stemming for query expansion but search the query terms verbatim. | |
nostop | Boolean | false | If set, redis will not filter stopwords from the query | |
withscores | Boolean | false | If set, the response will have the relative internal score of each document. this can be used to merge results from multiple instances | |
withpayloads | Boolean | false | If set, the rsponse will have the optional document payloads (see FT.ADD). | |
sort | String |
Define how to sort the resuts. Sentence will be defined like: {COLUMN_NAME}={SORT_DIRECTION}
|
2.3.3 FT.AGGREGATE
FT.AGGREGATE command runs a search query on an index, and performs aggregate transformations on the results, extracting statistics and other data from them.
Redis FT.AGGREGATE documentation
The available endpoint to do a FT.AGGREGATE query is: "/aggregate/{index}".
index is telling the INDEX where the query will be applied.
Pipeline
QueryParams
Param | Param type | Required | Default | Description |
---|---|---|---|---|
q | String | the text query to search. Info here | ||
fields[] | List<String> |
Define the columns of the GROUPBY to define the groups Array with the column names of the columns that will be in the GROUPBY list |
||
reducers[] | List<String> |
Reduce the matching results in each group into a single record, using a reduction function Sentence will be defined like: {NEW_COLUMN_NAME}={REDUCE_TYPE} [{COLUMN_NAME} [{ARG} [{SORT_DIRECTION}]]]
|
||
apply[] | List<String> |
Apply a 1-to-1 transformation on one or more properties, and either store the result as a new property down the pipeline, or replace any property using this transformation Sentence will be defined like: {COLUMN_NAME}={APPLY_SENTENCE}
|
||
sorters[] | List<String> |
Define how to sort the resuts. Sentence will be defined like: {COLUMN_NAME}={SORT_DIRECTION}
|
||
sortmax | Integer | Used within the sorters to optimize the query sorting only for the n-largest elements. If not defined will sort all the elements | ||
filter | String | Filter the results using predicate expressions relating to values in each result | ||
limit | Integer | 10 | Limit the number of results to return | |
offset | Integer | 0 | Apply an offset ove the results to return |