Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add firstTimestamp field to the keyInfo struct. #160

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,34 @@ func TestClientInfo(t *testing.T) {
res, err := client.Info(key)
assert.Nil(t, err)
expected := KeyInfo{ChunkCount: 1,
ChunkSize: 4096, LastTimestamp: 0, RetentionTime: 3600000,
ChunkSize: 4096, FirstTimestamp: 0, LastTimestamp: 0, RetentionTime: 3600000,
Rules: []Rule{{DestKey: destKey, BucketSizeSec: 100, AggType: AvgAggregation}},
Labels: map[string]string{},
}
assert.Equal(t, expected, res)
}

func TestClientInfoRange(t *testing.T) {
err := client.FlushAll()
assert.Nil(t, err)
key := "test_INFORANGE"
now := time.Now().Unix()
PI := 3.14159265359
err = client.CreateKey(key, defaultDuration)
assert.Nil(t, err)
var i, n int64
n = 10

for i = 0; i <= n; i++ {
_, err = client.Add(key, now+i, PI)
assert.Nil(t, err)
}

info, _ := client.Info(key)
assert.Equal(t, now, info.FirstTimestamp)
assert.Equal(t, now+n, info.LastTimestamp)
}

func TestDeleteRule(t *testing.T) {
err := client.FlushAll()
assert.Nil(t, err)
Expand Down Expand Up @@ -313,6 +334,7 @@ func TestAdd(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, now, storedTimestamp)
info, _ := client.Info(key)
assert.Equal(t, now, info.FirstTimestamp)
assert.Equal(t, now, info.LastTimestamp)

// Test with auto timestamp
Expand Down Expand Up @@ -382,6 +404,7 @@ func TestAddWithRetention(t *testing.T) {
_, err = client.AddWithRetention(key, now, PI, 1000000)
assert.Nil(t, err)
info, _ := client.Info(key)
assert.Equal(t, now, info.FirstTimestamp)
assert.Equal(t, now, info.LastTimestamp)
}

Expand Down
1 change: 1 addition & 0 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ type KeyInfo struct {
ChunkCount int64
MaxSamplesPerChunk int64 // As of RedisTimeseries >= v1.4 MaxSamplesPerChunk is deprecated in favor of ChunkSize
ChunkSize int64
FirstTimestamp int64
LastTimestamp int64
RetentionTime int64
Rules []Rule
Expand Down
8 changes: 6 additions & 2 deletions example_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package redis_timeseries_go_test

import (
"fmt"
redistimeseries "github.com/RedisTimeSeries/redistimeseries-go"
"github.com/gomodule/redigo/redis"
redistimeseries "github.com/temphiza/redistimeseries-go"
"log"
"time"
)

// exemplifies the NewClientFromPool function
//
//nolint:errcheck
func ExampleNewClientFromPool() {
host := "localhost:6379"
Expand Down Expand Up @@ -767,8 +768,9 @@ func ExampleClient_MultiReverseRangeWithOptions_selectedLabels() {
// Ranges: [{selected-labels-ex-time-serie-1 map[az:us-east-1 location:SF] [{4 2} {2 1}]} {selected-labels-ex-time-serie-2 map[az:us-east-1 location:NY] [{4 15} {1 10}]}]
}

//nolint:errcheck
// Exemplifies the usage of MultiGetWithOptions function while using the default MultiGetOptions and while using user defined MultiGetOptions.
//
//nolint:errcheck
func ExampleClient_MultiGetWithOptions() {
host := "localhost:6379"
password := ""
Expand Down Expand Up @@ -859,6 +861,7 @@ func ExampleClient_MultiAdd() {
}

// exemplifies the usage of DeleteSerie function
//
//nolint:errcheck
func ExampleClient_DeleteSerie() {
host := "localhost:6379"
Expand All @@ -882,6 +885,7 @@ func ExampleClient_DeleteSerie() {
}

// exemplifies the usage of DeleteRange function
//
//nolint:errcheck
func ExampleClient_DeleteRange() {
host := "localhost:6379"
Expand Down
16 changes: 11 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
module github.com/RedisTimeSeries/redistimeseries-go
module github.com/temphiza/redistimeseries-go

go 1.12
go 1.20

require (
github.com/gomodule/redigo v1.8.2
github.com/google/go-cmp v0.5.1
github.com/stretchr/testify v1.6.1
github.com/gomodule/redigo v1.8.9
github.com/google/go-cmp v0.5.9
github.com/stretchr/testify v1.8.4
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
23 changes: 11 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gomodule/redigo v1.8.2 h1:H5XSIre1MB5NbPYFp+i1NBbb5qN1W8Y8YAQoAYbkm8k=
github.com/gomodule/redigo v1.8.2/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0=
github.com/google/go-cmp v0.5.1 h1:JFrFEBb2xKufg6XkJsJr+WbKb4FQlURi5RUcBveYu9k=
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gomodule/redigo v1.8.9 h1:Sl3u+2BI/kk+VEatbj0scLdrFhjPmbxOc1myhDP41ws=
github.com/gomodule/redigo v1.8.9/go.mod h1:7ArFNvsTjH8GMMzB4uy1snslv2BwmginuMs06a1uzZE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 2 additions & 0 deletions reply_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ func ParseInfo(result interface{}, err error) (info KeyInfo, outErr error) {
info.ChunkSize = 16 * v
case "chunkSize":
info.ChunkSize, outErr = redis.Int64(values[i+1], nil)
case "firstTimestamp":
info.FirstTimestamp, outErr = redis.Int64(values[i+1], nil)
case "lastTimestamp":
info.LastTimestamp, outErr = redis.Int64(values[i+1], nil)
case "labels":
Expand Down