func TestRedis(t *testing.T) { s, _ := testutil.PrepareTestRedis() for i := 0; i < 10000; i++ { s.Set("key"+strconv.Itoa(i), "hoge"+strconv.Itoa(i)) } client := redis.NewClient(&redis.Options{Addr: s.Addr()}) // 普通にループ result := map[string]string{} for i := 0; i < 10000; i++ { key := "key" + strconv.Itoa(i) res, _ := client.Get(key).Result() result[key] = res } // Pipelineを使ってループ m := map[string]*redis.StringCmd{} pipe := client.Pipeline() for i := 0; i < 10000; i++ { m["key"+strconv.Itoa(i)] = pipe.Get("key" + strconv.Itoa(i)) } _, err := pipe.Exec() if err != nil { panic(err) } result2 := map[string]string{} for k, v := range m { res, _ := v.Result() result2[k] = res } }