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

Method GetKeysAndValuesWithFilter

pkg/storage/redis_cluster.go:664–730  ·  view source on GitHub ↗

GetKeysAndValuesWithFilter will return all keys and their values with a filter.

(filter string)

Source from the content-addressed store, hash-verified

662
663// GetKeysAndValuesWithFilter will return all keys and their values with a filter.
664func (r *RedisCluster) GetKeysAndValuesWithFilter(filter string) map[string]string {
665 if err := r.up(); err != nil {
666 return nil
667 }
668 keys := r.GetKeys(filter)
669 if keys == nil {
670 log.Error("Error trying to get filtered client keys")
671
672 return nil
673 }
674
675 if len(keys) == 0 {
676 return nil
677 }
678
679 for i, v := range keys {
680 keys[i] = r.KeyPrefix + v
681 }
682
683 client := r.singleton()
684 values := make([]string, 0)
685
686 switch v := client.(type) {
687 case *redis.ClusterClient:
688 {
689 getCmds := make([]*redis.StringCmd, 0)
690 pipe := v.Pipeline()
691 for _, key := range keys {
692 getCmds = append(getCmds, pipe.Get(key))
693 }
694 _, err := pipe.Exec()
695 if err != nil && !errors.Is(err, redis.Nil) {
696 log.Errorf("Error trying to get client keys: %s", err.Error())
697
698 return nil
699 }
700
701 for _, cmd := range getCmds {
702 values = append(values, cmd.Val())
703 }
704 }
705 case *redis.Client:
706 {
707 result, err := v.MGet(keys...).Result()
708 if err != nil {
709 log.Errorf("Error trying to get client keys: %s", err.Error())
710
711 return nil
712 }
713
714 for _, val := range result {
715 strVal := fmt.Sprint(val)
716 if strVal == "<nil>" {
717 strVal = ""
718 }
719 values = append(values, strVal)
720 }
721 }

Callers 1

GetKeysAndValuesMethod · 0.95

Calls 8

upMethod · 0.95
GetKeysMethod · 0.95
singletonMethod · 0.95
cleanKeyMethod · 0.95
ErrorFunction · 0.92
ErrorfFunction · 0.92
GetMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected