RedisFlush deletes all keys from redis except specific task queues.
()
| 137 | |
| 138 | // RedisFlush deletes all keys from redis except specific task queues. |
| 139 | func (Dev) RedisFlush() error { |
| 140 | if mg.Verbose() { |
| 141 | fmt.Println("Deleting keys from redis (preserving task queues)") |
| 142 | } |
| 143 | |
| 144 | keys, err := sh.Output("docker", dockerComposeFlags("exec", "-T", "redis", "redis-cli", "keys", "ttn:v3:*")...) |
| 145 | if err != nil { |
| 146 | return err |
| 147 | } |
| 148 | |
| 149 | ks := strings.Split(keys, "\n") |
| 150 | if len(ks) == 0 { |
| 151 | return nil |
| 152 | } |
| 153 | |
| 154 | // Delete all keys except preserved ones |
| 155 | baseArgs := []string{"exec", "-T", "redis", "redis-cli", "del"} |
| 156 | keysToDelete := make([]string, 0, len(ks)) |
| 157 | |
| 158 | for _, k := range ks { |
| 159 | if k != "ttn:v3:ns:tasks:downlink:ready" && |
| 160 | k != "ttn:v3:ns:tasks:downlink:input" && |
| 161 | k != "ttn:v3:ns:application-uplinks:uplinks" { |
| 162 | keysToDelete = append(keysToDelete, k) |
| 163 | } |
| 164 | } |
| 165 | // No keys to delete |
| 166 | if len(keysToDelete) == len(baseArgs) { |
| 167 | return nil |
| 168 | } |
| 169 | |
| 170 | flags := dockerComposeFlags(append(baseArgs, keysToDelete...)...) |
| 171 | _, err = sh.Exec(nil, nil, os.Stderr, "docker", flags...) |
| 172 | return err |
| 173 | } |
| 174 | |
| 175 | // DBStart starts the databases of the development environment. |
| 176 | func (Dev) DBStart() error { |
nothing calls this directly
no test coverage detected