Skip to content

mologie/hapredis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hapredis

A simple adapter to use go-redis as storage backend for brutella/hap.

Usage

Download the library within the context of your project:

go get github.com/brutella/hap
go get github.com/go-redis/redis/v8
go get github.com/mologie/hapredis

Integrate it by creating a Redis client and wrapping into a Store interface.

It is important to give your client a unique prefix to allow multiple different instances to connect to use a single Redis database.

package main

import (
	"context"
	"github.com/brutella/hap"
	"github.com/brutella/hap/accessory"
	"github.com/go-redis/redis/v8"
	"github.com/mologie/hapredis"
	"log"
)

func main() {
	ctx := context.Background()

	// create storage backend using this library
	redisClient := redis.NewClient(&redis.Options{Addr: "localhost:6379"})
	store := hapredis.NewStore(ctx, redisClient, "unique-instance-prefix:")

	// create accessory and its server
	acc := accessory.NewSwitch(accessory.Info{Name: "Lamp"})
	server, err := hap.NewServer(store, acc.A)
	if err != nil {
		// Redis errors can get you here, e.g. when the server cannot load its
		// UUID due to connection or permission problems.
		log.Panic(err)
	}

	// run accessory server forever
	server.ListenAndServe(ctx)
}

About

Redis storage adapter for https://github.com/brutella/hap

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages