Redis cache

This commit is contained in:
2025-03-29 02:24:15 +08:00
parent f3f9ebb5af
commit 1651328a74
26 changed files with 786 additions and 636 deletions

View File

@@ -2,14 +2,17 @@ package nex
import (
"context"
"git.solsynth.dev/hypernet/nexus/pkg/proto"
"github.com/redis/go-redis/v9"
)
type AllocatableResourceType = string
const (
AllocatableResourceMq = AllocatableResourceType("mq")
AllocatableResourceKv = AllocatableResourceType("kv")
AllocatableResourceMq = AllocatableResourceType("mq")
AllocatableResourceKv = AllocatableResourceType("kv")
AllocatableResourceCache = AllocatableResourceType("cache")
)
func (v *Conn) AllocResource(t AllocatableResourceType) any {
@@ -28,6 +31,17 @@ func (v *Conn) AllocResource(t AllocatableResourceType) any {
return nil
}
return resp.Endpoints
case AllocatableResourceCache:
conn := v.GetNexusGrpcConn()
resp, err := proto.NewAllocatorServiceClient(conn).AllocCache(context.Background(), &proto.AllocCacheRequest{})
if err != nil || !resp.IsSuccess {
return nil
}
return redis.NewClient(&redis.Options{
Addr: resp.GetAddr(),
Password: resp.GetPassword(),
DB: int(resp.GetDb()),
})
default:
return nil
}