Skip to content

Commit

Permalink
add new command EXPIRE
Browse files Browse the repository at this point in the history
Signed-off-by: Issif <[email protected]>
  • Loading branch information
Issif committed Jun 29, 2022
1 parent 36a153e commit 10538e4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions redisearch/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Document struct {
Id string
Score float32
Payload []byte
TTL int
Properties map[string]interface{}
}

Expand Down Expand Up @@ -70,6 +71,12 @@ func (d Document) Set(name string, value interface{}) Document {
return d
}

// SetTTL sets the ttl and its option in the document
func (d Document) SetTTL(ttl int) Document {
d.TTL = ttl
return d
}

// All punctuation marks and whitespaces (besides underscores) separate the document and queries into tokens.
// e.g. any character of `,.<>{}[]"':;!@#$%^&*()-+=~` will break the text into terms.
// So the text `foo-bar.baz...bag` will be tokenized into `[foo, bar, baz, bag]`
Expand Down
12 changes: 12 additions & 0 deletions redisearch/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,18 @@ func (i *Client) IndexOptions(opts IndexingOptions, docs ...Document) error {

return merr
}
if doc.TTL > 0 {
argsttl := make(redis.Args, 0, 2)
argsttl = append(argsttl, doc.Id, doc.TTL)
if err := conn.Send("EXPIRE", argsttl...); err != nil {
if merr == nil {
merr = NewMultiError(len(docs))
}
merr[ii] = err

return merr
}
}
n++
}

Expand Down

0 comments on commit 10538e4

Please sign in to comment.