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.

49 lines
1.4 KiB

3 years ago
  1. package redis3
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/chrislusf/seaweedfs/weed/util/bptree"
  6. "github.com/go-redis/redis/v8"
  7. "github.com/golang/protobuf/proto"
  8. )
  9. func insertChild(ctx context.Context, client redis.UniversalClient, key string, name string) error {
  10. data, err := client.Get(ctx, key).Result()
  11. if err != nil {
  12. if err != redis.Nil {
  13. return fmt.Errorf("read %s: %v", key, err)
  14. }
  15. }
  16. rootNode := &bptree.ProtoNode{}
  17. if err := proto.UnmarshalMerge([]byte(data), rootNode); err != nil {
  18. return fmt.Errorf("decoding root for %s: %v", key, err)
  19. }
  20. tree := rootNode.ToBpTree()
  21. tree.Add(bptree.String(name), nil)
  22. return nil
  23. }
  24. func removeChild(ctx context.Context, client redis.UniversalClient, key string, name string) error {
  25. data, err := client.Get(ctx, key).Result()
  26. if err != nil {
  27. if err != redis.Nil {
  28. return fmt.Errorf("read %s: %v", key, err)
  29. }
  30. }
  31. rootNode := &bptree.ProtoNode{}
  32. if err := proto.UnmarshalMerge([]byte(data), rootNode); err != nil {
  33. return fmt.Errorf("decoding root for %s: %v", key, err)
  34. }
  35. tree := rootNode.ToBpTree()
  36. tree.Add(bptree.String(name), nil)
  37. return nil
  38. }
  39. func removeChildren(ctx context.Context, client redis.UniversalClient, key string, onDeleteFn func(name string) error) error {
  40. return nil
  41. }
  42. func iterateChildren(ctx context.Context, client redis.UniversalClient, key string, eachFn func(name string) error) error {
  43. return nil
  44. }