mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-19 10:54:08 +01:00
* filer.redis3: prefix every key via getKey, honoring keyPrefix Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * filer.redis3: read username and keyPrefix options into client config Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * filer.redis3: reject a username configured without a password go-redis only sends AUTH when a password is set, so a configured username with an empty password silently connects as the default user instead of the intended ACL user. Fail loudly at initialize instead. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * filer.redis3: cover keyPrefix scoping in the store tests Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> * filer.redis3: derive the test prefix and kv key from the per-run directory --------- Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
43 lines
885 B
Go
43 lines
885 B
Go
package redis3
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/redis/go-redis/v9"
|
|
"github.com/seaweedfs/seaweedfs/weed/filer"
|
|
)
|
|
|
|
func (store *UniversalRedis3Store) KvPut(ctx context.Context, key []byte, value []byte) (err error) {
|
|
|
|
_, err = store.Client.Set(ctx, store.getKey(string(key)), value, 0).Result()
|
|
|
|
if err != nil {
|
|
return fmt.Errorf("kv put: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (store *UniversalRedis3Store) KvGet(ctx context.Context, key []byte) (value []byte, err error) {
|
|
|
|
data, err := store.Client.Get(ctx, store.getKey(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, store.getKey(string(key))).Result()
|
|
|
|
if err != nil {
|
|
return fmt.Errorf("kv delete: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|