Skip to content

Commit 89fc3a2

Browse files
committed
add new command EXPIRE
Signed-off-by: Issif <[email protected]>
1 parent 36a153e commit 89fc3a2

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

redisearch/document.go

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type Document struct {
1717
Id string
1818
Score float32
1919
Payload []byte
20+
TTL int
2021
Properties map[string]interface{}
2122
}
2223

@@ -70,6 +71,12 @@ func (d Document) Set(name string, value interface{}) Document {
7071
return d
7172
}
7273

74+
// SetTTL sets the ttl in the document
75+
func (d Document) SetTTL(ttl int) Document {
76+
d.TTL = ttl
77+
return d
78+
}
79+
7380
// All punctuation marks and whitespaces (besides underscores) separate the document and queries into tokens.
7481
// e.g. any character of `,.<>{}[]"':;!@#$%^&*()-+=~` will break the text into terms.
7582
// So the text `foo-bar.baz...bag` will be tokenized into `[foo, bar, baz, bag]`

redisearch/query.go

+12
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,18 @@ func (i *Client) IndexOptions(opts IndexingOptions, docs ...Document) error {
445445

446446
return merr
447447
}
448+
if doc.TTL > 0 {
449+
argsttl := make(redis.Args, 0, 2)
450+
argsttl = append(argsttl, doc.Id, doc.TTL)
451+
if err := conn.Send("EXPIRE", argsttl...); err != nil {
452+
if merr == nil {
453+
merr = NewMultiError(len(docs))
454+
}
455+
merr[ii] = err
456+
457+
return merr
458+
}
459+
}
448460
n++
449461
}
450462

0 commit comments

Comments
 (0)