75 lines
2.0 KiB
Go
75 lines
2.0 KiB
Go
package 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,
|
|
}
|
|
}
|