[feature] basic redis implementation
This commit is contained in:
parent
1f2648d50a
commit
f763117422
20
internal/cache/redis.go
vendored
20
internal/cache/redis.go
vendored
@ -2,12 +2,15 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
func Init() *redis.Client {
|
||||
client := redis.NewClient(&redis.Options{
|
||||
Addr: "localhost:8050",
|
||||
Addr: "localhost:6379",
|
||||
Password: "", // No password set
|
||||
DB: 0, // Use default DB
|
||||
Protocol: 2, // Connection protocol
|
||||
@ -15,3 +18,18 @@ func Init() *redis.Client {
|
||||
|
||||
return client
|
||||
}
|
||||
|
||||
func StoreLocal(client *redis.Client) {
|
||||
ctx := context.Background()
|
||||
err := client.Set(ctx, "temperature", "44", 0).Err()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
val, err := client.Get(ctx, "temperature").Result()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(val)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user