2020-09-02 12:58:57 +08:00
|
|
|
package redis
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/filer"
|
2021-01-08 17:08:44 +08:00
|
|
|
"github.com/go-redis/redis/v8"
|
2020-09-02 12:58:57 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func (store *UniversalRedisStore) KvPut(ctx context.Context, key []byte, value []byte) (err error) {
|
|
|
|
|
2021-01-08 17:08:44 +08:00
|
|
|
_, err = store.Client.Set(ctx, string(key), value, 0).Result()
|
2020-09-02 12:58:57 +08:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("kv put: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (store *UniversalRedisStore) KvGet(ctx context.Context, key []byte) (value []byte, err error) {
|
|
|
|
|
2021-01-08 17:08:44 +08:00
|
|
|
data, err := store.Client.Get(ctx, string(key)).Result()
|
2020-09-02 12:58:57 +08:00
|
|
|
|
|
|
|
if err == redis.Nil {
|
|
|
|
return nil, filer.ErrKvNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
return []byte(data), err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (store *UniversalRedisStore) KvDelete(ctx context.Context, key []byte) (err error) {
|
|
|
|
|
2021-01-08 17:08:44 +08:00
|
|
|
_, err = store.Client.Del(ctx, string(key)).Result()
|
2020-09-02 12:58:57 +08:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("kv delete: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|