-
-
Save mgates/b866ab74625f4dd83eb6ebc20d988eff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main │················································································································· | |
│················································································································· | |
import "github.com/coreos/etcd/clientv3" │················································································································· | |
import "github.com/nu7hatch/gouuid" │················································································································· | |
│················································································································· | |
import ( │················································································································· | |
"log" │················································································································· | |
"time" │················································································································· | |
"context" │················································································································· | |
"sync" │················································································································· | |
) │················································································································· | |
func main() { │················································································································· | |
cli, err := clientv3.New(clientv3.Config{ │················································································································· | |
Endpoints: []string{"localhost:2379"}, │················································································································· | |
DialTimeout: 5 * time.Second, │················································································································· | |
}) │················································································································· | |
log.Printf("Start") │················································································································· | |
if err != nil { │················································································································· | |
log.Fatal(err) │················································································································· | |
} │················································································································· | |
var wg sync.WaitGroup │················································································································· | |
for k := 0; k < 200; k++ { │················································································································· | |
wg.Add(1) │················································································································· | |
go func() { │················································································································· | |
for i := 0; i < 3000; i++ { │················································································································· | |
resp, err := cli.Grant(context.TODO(), 5) │················································································································· | |
if err != nil { │················································································································· | |
log.Fatal(err) │················································································································· | |
} │················································································································· | |
u, err := uuid.NewV4() │················································································································· | |
_, err = cli.Put(context.TODO(), u.String(), "bar", clientv3.WithLease(resp.ID)) │················································································································· | |
if err != nil { │················································································································· | |
log.Fatal(err) │················································································································· | |
} else { │················································································································· | |
_, err = cli.Delete(context.TODO(), u.String()) │················································································································· | |
} │················································································································· | |
} │················································································································· | |
defer wg.Done() │················································································································· | |
}() │················································································································· | |
} │················································································································· | |
wg.Wait() │················································································································· | |
defer cli.Close() │················································································································· | |
log.Printf("End") │················································································································· | |
} │················································································································· | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment