mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
43 lines
852 B
Go
43 lines
852 B
Go
|
package redis_lua
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
|
||
|
"github.com/chrislusf/seaweedfs/weed/filer"
|
||
|
"github.com/go-redis/redis/v8"
|
||
|
)
|
||
|
|
||
|
func (store *UniversalRedisLuaStore) 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 *UniversalRedisLuaStore) 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 *UniversalRedisLuaStore) 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
|
||
|
}
|