MCPcopy
hub / github.com/marmotedu/iam / DeleteScanMatch

Method DeleteScanMatch

pkg/storage/redis_cluster.go:784–854  ·  view source on GitHub ↗

DeleteScanMatch will remove a group of keys in bulk.

(pattern string)

Source from the content-addressed store, hash-verified

782
783// DeleteScanMatch will remove a group of keys in bulk.
784func (r *RedisCluster) DeleteScanMatch(pattern string) bool {
785 if err := r.up(); err != nil {
786 return false
787 }
788 client := r.singleton()
789 log.Debugf("Deleting: %s", pattern)
790
791 fnScan := func(client *redis.Client) ([]string, error) {
792 values := make([]string, 0)
793
794 iter := client.Scan(0, pattern, 0).Iterator()
795 for iter.Next() {
796 values = append(values, iter.Val())
797 }
798
799 if err := iter.Err(); err != nil {
800 return nil, err
801 }
802
803 return values, nil
804 }
805
806 var err error
807 var keys []string
808 var values []string
809
810 switch v := client.(type) {
811 case *redis.ClusterClient:
812 ch := make(chan []string)
813 go func() {
814 err = v.ForEachMaster(func(client *redis.Client) error {
815 values, err = fnScan(client)
816 if err != nil {
817 return err
818 }
819
820 ch <- values
821
822 return nil
823 })
824 close(ch)
825 }()
826
827 for vals := range ch {
828 keys = append(keys, vals...)
829 }
830 case *redis.Client:
831 keys, err = fnScan(v)
832 }
833
834 if err != nil {
835 log.Errorf("SCAN command field with err: %s", err.Error())
836
837 return false
838 }
839
840 if len(keys) > 0 {
841 for _, name := range keys {

Callers

nothing calls this directly

Calls 8

upMethod · 0.95
singletonMethod · 0.95
DebugfFunction · 0.92
ErrorfFunction · 0.92
InfofFunction · 0.92
DebugFunction · 0.92
NextMethod · 0.80
ErrorMethod · 0.65

Tested by

no test coverage detected