You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
843 B

  1. package redis2
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/redis/go-redis/v9"
  6. "github.com/seaweedfs/seaweedfs/weed/filer"
  7. )
  8. func (store *UniversalRedis2Store) KvPut(ctx context.Context, key []byte, value []byte) (err error) {
  9. _, err = store.Client.Set(ctx, string(key), value, 0).Result()
  10. if err != nil {
  11. return fmt.Errorf("kv put: %v", err)
  12. }
  13. return nil
  14. }
  15. func (store *UniversalRedis2Store) KvGet(ctx context.Context, key []byte) (value []byte, err error) {
  16. data, err := store.Client.Get(ctx, string(key)).Result()
  17. if err == redis.Nil {
  18. return nil, filer.ErrKvNotFound
  19. }
  20. return []byte(data), err
  21. }
  22. func (store *UniversalRedis2Store) KvDelete(ctx context.Context, key []byte) (err error) {
  23. _, err = store.Client.Del(ctx, string(key)).Result()
  24. if err != nil {
  25. return fmt.Errorf("kv delete: %v", err)
  26. }
  27. return nil
  28. }