Skip to content

dengliming/redisai-go

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

license CircleCI GitHub issues Codecov Go Report Card GoDoc

RedisAI Go Client

Forum Gitter

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 ModelScan
AI.SCRIPTSET ScriptSet
AI.SCRIPTGET ScriptGet
AI.SCRIPTDEL ScriptDel
AI.SCRIPTRUN ScriptRun
AI._SCRIPTSCAN 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, []int{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, []int{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, []int{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]]
}

About

A Golang client for RedisAI

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 95.9%
  • Python 3.1%
  • Other 1.0%