Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/RediSearch/redisearch-go

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/RediSearch/redisearch-go

  • v1.1.1
  • Source
  • Go
  • Socket score

Version published
Created
Source

license CircleCI GitHub issues Codecov Go Report Card GoDoc Total alerts

RediSearch Go Client

Forum Discord

Go client for RediSearch, based on redigo.

Installing

go get github.com/RediSearch/redisearch-go/redisearch

Usage Example

package main 
import (
	"fmt"
	"log"
	"time"

	"github.com/RediSearch/redisearch-go/redisearch"
)

func ExampleClient() {

	// Create a client. By default a client is schemaless
	// unless a schema is provided when creating the index
	c := redisearch.NewClient("localhost:6379", "myIndex")

	// Create a schema
	sc := redisearch.NewSchema(redisearch.DefaultOptions).
		AddField(redisearch.NewTextField("body")).
		AddField(redisearch.NewTextFieldOptions("title", redisearch.TextFieldOptions{Weight: 5.0, Sortable: true})).
		AddField(redisearch.NewNumericField("date"))

	// Drop an existing index. If the index does not exist an error is returned
	c.Drop()

	// Create the index with the given schema
	if err := c.CreateIndex(sc); err != nil {
		log.Fatal(err)
	}

	// Create a document with an id and given score
	doc := redisearch.NewDocument("doc1", 1.0)
	doc.Set("title", "Hello world").
		Set("body", "foo bar").
		Set("date", time.Now().Unix())

	// Index the document. The API accepts multiple documents at a time
	if err := c.Index([]redisearch.Document{doc}...); err != nil {
		log.Fatal(err)
	}

	// Searching with limit and sorting
	docs, total, err := c.Search(redisearch.NewQuery("hello world").
		Limit(0, 2).
		SetReturnFields("title"))

	fmt.Println(docs[0].Id, docs[0].Properties["title"], total, err)
	// Output: doc1 Hello world 1 <nil>
}

Supported RediSearch Commands

CommandRecommended API and godoc
FT.CREATECreateIndex
FT.ADDIndexOptions
FT.ALTERAddField
FT.ALIASADDAliasAdd
FT.ALIASUPDATEAliasUpdate
FT.ALIASDELAliasDel
FT.INFOInfo
FT.SEARCHSearch
FT.AGGREGATEAggregate
FT.CURSORAggregate + (*WithCursor option set to True)
FT.EXPLAINExplain
FT.DELDeleteDocument
FT.GETGet
FT.MGETMultiGet
FT.DROPDrop
FT.TAGVALSGetTagVals
FT.SUGADDAddTerms
FT.SUGGETSuggestOpts
FT.SUGDELDeleteTerms
FT.SUGLENAutocompleter.Length
FT.SYNUPDATESynUpdate
FT.SYNDUMPSynDump
FT.SPELLCHECKSpellCheck
FT.DICTADDDictAdd
FT.DICTDELDictDel
FT.DICTDUMPDictDump
FT.CONFIGSetConfigGetConfig

FAQs

Package last updated on 22 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc