MCPcopy
hub / github.com/redis/go-redis / Watch

Method Watch

ring.go:892–924  ·  view source on GitHub ↗
(ctx context.Context, fn func(*Tx) error, keys ...string)

Source from the content-addressed store, hash-verified

890}
891
892func (c *Ring) Watch(ctx context.Context, fn func(*Tx) error, keys ...string) error {
893 if len(keys) == 0 {
894 return fmt.Errorf("redis: Watch requires at least one key")
895 }
896
897 var shards []*ringShard
898
899 for _, key := range keys {
900 if key != "" {
901 shard, err := c.sharding.GetByKey(key)
902 if err != nil {
903 return err
904 }
905
906 shards = append(shards, shard)
907 }
908 }
909
910 if len(shards) == 0 {
911 return fmt.Errorf("redis: Watch requires at least one shard")
912 }
913
914 if len(shards) > 1 {
915 for _, shard := range shards[1:] {
916 if shard.Client != shards[0].Client {
917 err := fmt.Errorf("redis: Watch requires all keys to be in the same shard")
918 return err
919 }
920 }
921 }
922
923 return shards[0].Client.Watch(ctx, fn, keys...)
924}
925
926// Close closes the ring client, releasing any open resources.
927//

Callers

nothing calls this directly

Calls 2

GetByKeyMethod · 0.80
WatchMethod · 0.65

Tested by

no test coverage detected