feat: KeyStoreStringToBinary
This commit is contained in:
1 parent
1d08501b51
commit
72a6625c14
5 files changed
+94
-1
No files matched your search
@@ -0,0 +1,74 @@
|
||||
package universe_key_value
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
type KeyStoreStringToBinary struct {
|
||||
binaryStore KeyValueStoreBinary
|
||||
}
|
||||
|
||||
func (k *KeyStoreStringToBinary) Has(ctx context.Context, key string) (bool, error) {
|
||||
value, err := k.binaryStore.Has(ctx, key)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return value, nil
|
||||
}
|
||||
|
||||
func (k *KeyStoreStringToBinary) SetIfNotExist(ctx context.Context, key string, value string) (bool, error) {
|
||||
valueBytes := []byte(value)
|
||||
set, err := k.binaryStore.SetIfNotExist(ctx, key, valueBytes)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return set, nil
|
||||
}
|
||||
|
||||
func (k *KeyStoreStringToBinary) SetIfNotExistWithExpiration(ctx context.Context, key string, value string, expiration time.Time) (bool, error) {
|
||||
valueBytes := []byte(value)
|
||||
set, err := k.binaryStore.SetIfNotExistWithExpiration(ctx, key, valueBytes, expiration)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return set, nil
|
||||
}
|
||||
|
||||
func (k *KeyStoreStringToBinary) ExpireAt(ctx context.Context, key string, expiration time.Time) error {
|
||||
return k.binaryStore.ExpireAt(ctx, key, expiration)
|
||||
}
|
||||
|
||||
func (k *KeyStoreStringToBinary) HasCapability(capability Capability) bool {
|
||||
return k.binaryStore.HasCapability(capability)
|
||||
}
|
||||
|
||||
func (k *KeyStoreStringToBinary) Get(ctx context.Context, key string) (string, error) {
|
||||
value, err := k.binaryStore.Get(ctx, key)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(value), nil
|
||||
}
|
||||
|
||||
func (k *KeyStoreStringToBinary) Set(ctx context.Context, key string, value string) error {
|
||||
return k.binaryStore.Set(ctx, key, []byte(value))
|
||||
}
|
||||
|
||||
func (k *KeyStoreStringToBinary) SetWithExpiration(ctx context.Context, key string, value string, expiresAt time.Time) error {
|
||||
return k.binaryStore.SetWithExpiration(ctx, key, []byte(value), expiresAt)
|
||||
}
|
||||
|
||||
func (k *KeyStoreStringToBinary) Remove(ctx context.Context, key string) error {
|
||||
return k.binaryStore.Remove(ctx, key)
|
||||
}
|
||||
|
||||
func WrapStringToBinary(binaryStore KeyValueStoreBinary) KeyValueStoreString {
|
||||
if binaryStore == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &KeyStoreStringToBinary{
|
||||
binaryStore: binaryStore,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user