Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mologie/hapredis
Redis storage adapter for https://github.com/brutella/hap
https://github.com/mologie/hapredis
Last synced: about 2 months ago
JSON representation
Redis storage adapter for https://github.com/brutella/hap
- Host: GitHub
- URL: https://github.com/mologie/hapredis
- Owner: mologie
- License: mit
- Created: 2023-01-01T18:52:07.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2023-08-23T09:54:22.000Z (over 1 year ago)
- Last Synced: 2024-06-20T01:55:48.939Z (7 months ago)
- Language: Go
- Size: 12.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hapredis
A simple adapter to use [go-redis](https://github.com/go-redis/redis) as storage backend for [brutella/hap](https://github.com/brutella/hap).
## Usage
Download the library within the context of your project:
```sh
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.```go
package mainimport (
"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)
}
```