Selaa lähdekoodia

refactor: update Redis cache SetNX method to use CBOR encoding

Yeuoly 5 kuukautta sitten
vanhempi
commit
541050b9da

+ 0 - 9
internal/core/plugin_manager/debugging_runtime/connection_key.go

@@ -7,7 +7,6 @@ import (
 	"github.com/google/uuid"
 	"github.com/langgenius/dify-plugin-daemon/internal/utils/cache"
 	"github.com/langgenius/dify-plugin-daemon/internal/utils/log"
-	"github.com/langgenius/dify-plugin-daemon/internal/utils/parser"
 	"github.com/redis/go-redis/v9"
 )
 
@@ -25,18 +24,10 @@ type ConnectionInfo struct {
 	TenantId string `json:"tenant_id" validate:"required"`
 }
 
-func (c ConnectionInfo) MarshalBinary() ([]byte, error) {
-	return parser.MarshalJsonBytes(c), nil
-}
-
 type Key struct {
 	Key string `json:"key" validate:"required"`
 }
 
-func (k Key) MarshalBinary() ([]byte, error) {
-	return parser.MarshalJsonBytes(k), nil
-}
-
 const (
 	CONNECTION_KEY_MANAGER_KEY2ID_PREFIX = "remote:key:manager:key2id"
 	CONNECTION_KEY_MANAGER_ID2KEY_PREFIX = "remote:key:manager:id2key"

+ 7 - 1
internal/utils/cache/redis.go

@@ -387,7 +387,13 @@ func SetNX[T any](key string, value T, expire time.Duration, context ...redis.Cm
 		return false, ErrDBNotInit
 	}
 
-	return getCmdable(context...).SetNX(ctx, serialKey(key), value, expire).Result()
+	// marshal the value
+	bytes, err := parser.MarshalCBOR(value)
+	if err != nil {
+		return false, err
+	}
+
+	return getCmdable(context...).SetNX(ctx, serialKey(key), bytes, expire).Result()
 }
 
 var (