Connect to the Redis server:
var redis = ConnectionMultiplexer.Connect("localhost");
Get a reference to the database and for search and json commands:
var db = redis.GetDatabase();
var ft = db.FT();
var json = db.JSON();
Create a search index with a JSON field:
ft.Create("test", new FTCreateParams().On(IndexDataType.JSON).Prefix("doc:"),
new Schema().AddTagField(new FieldName("$.name", "name")));
Insert 10 JSON documents into the index:
for (int i = 0; i < 10; i++)
{
json.Set("doc:" + i, "$", "{\"name\":\"foo\"}");
}
Execute a search query and convert the results to JSON:
var res = ft.Search("test", new Query("@name:{foo}"));
var docs = res.ToJson();
Now the docs
variable contains a JSON list (IEnumerable) of the search results.