本文整理匯總了Golang中github.com/coreos/etcd/etcdserver/etcdserverpb.RangeRequest.Serializable方法的典型用法代碼示例。如果您正苦於以下問題:Golang RangeRequest.Serializable方法的具體用法?Golang RangeRequest.Serializable怎麽用?Golang RangeRequest.Serializable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/coreos/etcd/etcdserver/etcdserverpb.RangeRequest
的用法示例。
在下文中一共展示了RangeRequest.Serializable方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: rangeFunc
func rangeFunc(cmd *cobra.Command, args []string) {
if len(args) == 0 || len(args) > 2 {
fmt.Fprintln(os.Stderr, cmd.Usage())
os.Exit(1)
}
k := []byte(args[0])
var end []byte
if len(args) == 2 {
end = []byte(args[1])
}
if rangeConsistency == "l" {
fmt.Println("bench with linearizable range")
} else if rangeConsistency == "s" {
fmt.Println("bench with serializable range")
} else {
fmt.Fprintln(os.Stderr, cmd.Usage())
os.Exit(1)
}
results = make(chan result)
requests := make(chan etcdserverpb.RangeRequest, totalClients)
bar = pb.New(rangeTotal)
clients := mustCreateClients(totalClients, totalConns)
bar.Format("Bom !")
bar.Start()
for i := range clients {
wg.Add(1)
go doRange(clients[i].KV, requests)
}
pdoneC := printReport(results)
go func() {
for i := 0; i < rangeTotal; i++ {
r := etcdserverpb.RangeRequest{Key: k, RangeEnd: end}
if rangeConsistency == "s" {
r.Serializable = true
}
requests <- r
}
close(requests)
}()
wg.Wait()
bar.Finish()
close(results)
<-pdoneC
}
示例2: Range
func (p *kvProxy) Range(ctx context.Context, r *pb.RangeRequest) (*pb.RangeResponse, error) {
if r.Serializable {
resp, err := p.cache.Get(r)
switch err {
case nil:
return resp, nil
case cache.ErrCompacted:
return nil, err
}
}
resp, err := p.kv.Do(ctx, RangeRequestToOp(r))
if err != nil {
return nil, err
}
// cache linearizable as serializable
r.Serializable = true
gresp := (*pb.RangeResponse)(resp.Get())
p.cache.Add(r, gresp)
return gresp, nil
}