SMembers gets all members of a set identified by the provided key. If the set does not exist or the key belongs to a different data type, the function will return an error. It returns a slice of strings which are the members of the set.
(key string)
| 103 | // the function will return an error. |
| 104 | // It returns a slice of strings which are the members of the set. |
| 105 | func (s *SetStructure) SMembers(key string) ([]string, error) { |
| 106 | fs, err := s.checkAndGetSet(key, false) |
| 107 | if err != nil { |
| 108 | return nil, err |
| 109 | } |
| 110 | // type of fs is map[string]struct{} |
| 111 | // we need to take the keys and make them a slice |
| 112 | var members []string |
| 113 | for k := range *fs { |
| 114 | members = append(members, k) |
| 115 | } |
| 116 | |
| 117 | return members, nil |
| 118 | } |
| 119 | |
| 120 | // SIsMember checks if a member exists in a set |
| 121 | func (s *SetStructure) SIsMember(key, member string) (bool, error) { |