2021-09-19 05:04:30 +08:00
|
|
|
package redis3
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
2023-06-13 13:27:38 +08:00
|
|
|
"github.com/go-redis/redis/v8"
|
2022-07-29 15:17:28 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/filer"
|
2021-09-19 05:04:30 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func (store *UniversalRedis3Store) KvPut(ctx context.Context, key []byte, value []byte) (err error) {
|
|
|
|
|
|
|
|
_, err = store.Client.Set(ctx, string(key), value, 0).Result()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("kv put: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (store *UniversalRedis3Store) KvGet(ctx context.Context, key []byte) (value []byte, err error) {
|
|
|
|
|
|
|
|
data, err := store.Client.Get(ctx, string(key)).Result()
|
|
|
|
|
|
|
|
if err == redis.Nil {
|
|
|
|
return nil, filer.ErrKvNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
return []byte(data), err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (store *UniversalRedis3Store) KvDelete(ctx context.Context, key []byte) (err error) {
|
|
|
|
|
|
|
|
_, err = store.Client.Del(ctx, string(key)).Result()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("kv delete: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|