Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

license CircleCI GitHub issues Codecov Go Report Card GoDoc

RedisAI Go Client

Forum Discord

Go client for RedisAI, based on redigo.

Installing

go get github.com/RedisAI/redisai-go/redisai

Supported RedisAI Commands

Command Recommended API and godoc
AI.TENSORSET TensorSet and TensorSetFromTensor
AI.TENSORGET TensorGet and TensorGetToTensor
AI.MODELSET ModelSet and ModelSetFromModel
AI.MODELGET ModelGet and ModelGetToModel
AI.MODELDEL ModelDel
AI.MODELRUN ModelRun
AI._MODELSCAN
AI.SCRIPTSET ScriptSet
AI.SCRIPTGET ScriptGet
AI.SCRIPTDEL ScriptDel
AI.SCRIPTRUN ScriptRun
AI._SCRIPTSCAN
AI.DAGRUN DagRun
AI.DAGRUN_RO DagRunRO
AI.INFO Info
AI.CONFIG * LoadBackend

Usage Examples

See the examples folder for further feature samples:

Simple Client

(sample code here)

package main

import (
	"fmt"
	"github.com/RedisAI/redisai-go/redisai"
	"log"
)

func main() {

	// Create a client.
	client := redisai.Connect("redis://localhost:6379", nil)

	// Set a tensor
	// AI.TENSORSET foo FLOAT 2 2 VALUES 1.1 2.2 3.3 4.4
	_ = client.TensorSet("foo", redisai.TypeFloat, []int64{2, 2}, []float32{1.1, 2.2, 3.3, 4.4})

	// Get a tensor content as a slice of values
	// dt DataType, shape []int, data interface{}, err error
	// AI.TENSORGET foo VALUES
	_, _, fooTensorValues, err := client.TensorGetValues("foo")

	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(fooTensorValues)
	// Output: [1.1 2.2 3.3 4.4]
}

Pipelined Client

(sample code here)

package main

import (
	"fmt"
	"github.com/RedisAI/redisai-go/redisai"
	"log"
)

func main() {

	// Create a client.
	client := redisai.Connect("redis://localhost:6379", nil)

	// Enable pipeline of commands on the client.
	client.Pipeline(3)

	// Set a tensor
	// AI.TENSORSET foo FLOAT 2 2 VALUES 1.1 2.2 3.3 4.4
	err := client.TensorSet("foo1", redisai.TypeFloat, []int64{2, 2}, []float32{1.1, 2.2, 3.3, 4.4})
	if err != nil {
		log.Fatal(err)
	}
	// AI.TENSORSET foo2 FLOAT 1" 1 VALUES 1.1
	err = client.TensorSet("foo2", redisai.TypeFloat, []int64{1, 1}, []float32{1.1})
	if err != nil {
		log.Fatal(err)
	}
	// AI.TENSORGET foo2 META
	_, err = client.TensorGet("foo2", redisai.TensorContentTypeMeta)
	if err != nil {
		log.Fatal(err)
	}
	// Ignore the AI.TENSORSET Reply
	_, err = client.Receive()
	if err != nil {
		log.Fatal(err)
	}
	// Ignore the AI.TENSORSET Reply
	_, err = client.Receive()
	if err != nil {
		log.Fatal(err)
	}
	foo2TensorMeta, err := client.Receive()
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(foo2TensorMeta)
	// Output: [FLOAT [1 1]]
}