github.com/RedisTimeSeries/redistimeseries-go

module github.com/RedisTimeSeries/redistimeseries-go

v1.2.0
Latest Go to latest
Published: Jan 27, 2020 | License: Apache-2.0

README

license CircleCI GitHub issues Codecov GoDoc

redis-timeseries-go

Go client for RedisTimeSeries (https://github.com/RedisLabsModules/redis-timeseries), based on redigo.

Client and ConnPool based on the work of dvirsky and mnunberg on https://github.com/RediSearch/redisearch-go

Installing

$ go get github.com/RedisTimeSeries/redistimeseries-go

Running tests

A simple test suite is provided, and can be run with:

$ REDISTIMESERIES_TEST_PASSWORD="" go test

The tests expect a Redis server with the RedisTimeSeries module loaded to be available at localhost:6379

Example Code

package main 

import (
        "fmt"
        redistimeseries "github.com/RedisTimeSeries/redistimeseries-go"
)

func main() {
		// Connect to localhost with no password
        var client = redistimeseries.NewClient("localhost:6379", "nohelp", nil)
        var keyname = "mytest"
        _, haveit := client.Info(keyname)
        if haveit != nil {
			client.CreateKeyWithOptions(keyname, redistimeseries.DefaultCreateOptions)
			client.CreateKeyWithOptions(keyname+"_avg", redistimeseries.DefaultCreateOptions)
			client.CreateRule(keyname, redistimeseries.AvgAggregation, 60, keyname+"_avg")
        }
		// Add sample with timestamp from server time and value 100
        // TS.ADD mytest * 100 
        _, err := client.AddAutoTs(keyname, 100)
        if err != nil {
                fmt.Println("Error:", err)
        }
}

Supported RedisTimeSeries Commands

Command Recommended API and godoc
TS.CREATE CreateKeyWithOptions
TS.ALTER N/A
TS.ADD
TS.MADD N/A
TS.INCRBY/TS.DECRBY N/A
TS.CREATERULE CreateRule
TS.DELETERULE DeleteRule
TS.RANGE RangeWithOptions
TS.MRANGE MultiRangeWithOptions
TS.GET Get
TS.MGET MultiGet
TS.INFO Info
TS.QUERYINDEX N/A

License

redistimeseries-go is distributed under the Apache-2 license - see LICENSE

Source: github.com/RedisTimeSeries/redistimeseries-go@v1.2.0/README.md