本文整理汇总了Golang中github.com/stevejiang/gotable/api/go/table.Context类的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: testDump
func testDump(tc *table.Context) {
//r, err := tc.DumpDB()
r, err := tc.DumpTable(1)
if err != nil {
fmt.Printf("Dump failed: %s\n", err)
return
}
fmt.Println("Dump result:")
var idx = 0
for {
for _, kv := range r.Kvs {
fmt.Printf("%02d) %d\t%q\t%d\t%q\t%d\t%q\n", idx,
kv.TableId, kv.RowKey, kv.ColSpace, kv.ColKey, kv.Score, kv.Value)
idx++
}
if r.End {
break
}
r, err = tc.DumpMore(r)
if err != nil {
fmt.Printf("DumpMore failed: %s\n", err)
return
}
}
}
开发者ID:tradia,项目名称:gotable,代码行数:28,代码来源:example.go
示例2: testPing
func testPing(tc *table.Context) {
start := time.Now()
err := tc.Ping()
if err != nil {
fmt.Printf("Ping failed: %s\n", err)
return
}
elapsed := time.Since(start)
fmt.Printf("Ping succeed: %.2fms\n", float64(elapsed)/1e6)
}
开发者ID:tradia,项目名称:gotable,代码行数:13,代码来源:example.go
示例3: mGet
func mGet(c *table.Context, done chan *table.Call, zop bool, ma table.MGetArgs) {
var err error
var r []table.GetReply
if zop {
if done == nil {
r, err = c.ZmGet(ma)
} else {
_, err = c.GoZmGet(ma, done)
}
} else {
if done == nil {
r, err = c.MGet(ma)
} else {
_, err = c.GoMGet(ma, done)
}
}
if err != nil {
fmt.Printf("MGet failed: %s\n", err)
os.Exit(1)
}
if *verbose != 0 && done == nil {
for i := 0; i < len(r); i++ {
var one = r[i]
fmt.Printf("%02d) [%q\t%q]\t[%d\t%q]\n", i,
one.RowKey, one.ColKey, one.Score, one.Value)
}
}
}
开发者ID:tradia,项目名称:gotable,代码行数:29,代码来源:main.go
示例4: scan
func scan(c *table.Context, done chan *table.Call, zop bool,
rowKey, colKey []byte, score int64, num int) {
var err error
var r table.ScanReply
if zop {
if done == nil {
r, err = c.ZScanPivot(0, rowKey, colKey, score, true, true, num)
} else {
_, err = c.GoZScanPivot(0, rowKey, colKey, score, true, true, num, done)
}
} else {
if done == nil {
r, err = c.ScanPivot(0, rowKey, colKey, true, num)
} else {
_, err = c.GoScanPivot(0, rowKey, colKey, true, num, done)
}
}
if err != nil {
fmt.Printf("Scan failed: %s\n", err)
os.Exit(1)
}
if *verbose != 0 && done == nil {
for i := 0; i < len(r.Kvs); i++ {
var one = r.Kvs[i]
fmt.Printf("%02d) [%q\t%q]\t[%d\t%q]\n", i,
r.RowKey, one.ColKey, one.Score, one.Value)
}
}
}
开发者ID:tradia,项目名称:gotable,代码行数:30,代码来源:main.go
示例5: incr
func incr(c *table.Context, done chan *table.Call, zop bool,
rowKey, colKey []byte, score int64) {
var err error
var value []byte
if zop {
if done == nil {
value, score, err = c.ZIncr(0, rowKey, colKey, score, 0)
} else {
_, err = c.GoZIncr(0, rowKey, colKey, score, 0, done)
}
} else {
if done == nil {
value, score, err = c.Incr(0, rowKey, colKey, score, 0)
} else {
_, err = c.GoIncr(0, rowKey, colKey, score, 0, done)
}
}
if err != nil {
fmt.Printf("Incr failed: %s\n", err)
os.Exit(1)
}
if *verbose != 0 && done == nil {
fmt.Printf("rowKey: %2s, colKey: %s, value: %s, score:%d\n",
string(rowKey), string(colKey), string(value), score)
}
}
开发者ID:tradia,项目名称:gotable,代码行数:27,代码来源:main.go
示例6: set
func set(c *table.Context, done chan *table.Call, zop bool,
rowKey, colKey, value []byte, score int64) {
var err error
if zop {
if done == nil {
err = c.ZSet(0, rowKey, colKey, value, score, 0)
} else {
_, err = c.GoZSet(0, rowKey, colKey, value, score, 0, done)
}
} else {
if done == nil {
err = c.Set(0, rowKey, colKey, value, score, 0)
} else {
_, err = c.GoSet(0, rowKey, colKey, value, score, 0, done)
}
}
if err != nil {
fmt.Printf("Set failed: %s\n", err)
os.Exit(1)
}
if *verbose != 0 && done == nil {
fmt.Printf("rowKey: %2s, colKey: %s\n", string(rowKey), string(colKey))
}
}
开发者ID:tradia,项目名称:gotable,代码行数:25,代码来源:main.go
示例7: testScan
func testScan(tc *table.Context) {
// SCAN
r, err := tc.Scan(1, []byte("row1"), true, 10)
if err != nil {
fmt.Printf("Scan failed: %s\n", err)
return
}
fmt.Println("SCAN result:")
printScanReply(r)
if r.End {
fmt.Println("SCAN finished!")
} else {
fmt.Println("SCAN has more records!")
}
}
开发者ID:tradia,项目名称:gotable,代码行数:16,代码来源:example.go
示例8: testBinary
func testBinary(tc *table.Context) {
var colKey = make([]byte, 4)
var value = make([]byte, 8)
binary.BigEndian.PutUint32(colKey, 998365)
binary.BigEndian.PutUint64(value, 6000000000)
err := tc.Set(1, []byte("row1"), colKey, value, 30, 0)
if err != nil {
fmt.Printf("Set failed: %s\n", err)
}
value, score, _, err := tc.Get(1, []byte("row1"), colKey, 0)
if err != nil {
fmt.Printf("Get failed: %s\n", err)
return
}
fmt.Printf("Binary result: %q\t%d\t%d\n",
value, binary.BigEndian.Uint64(value), score)
}
开发者ID:tradia,项目名称:gotable,代码行数:19,代码来源:example.go
示例9: testMGet
func testMGet(tc *table.Context) {
// MSET
var ma table.MSetArgs
ma.Add(1, []byte("row1"), []byte("col0"), []byte("v00"), 10, 0)
ma.Add(1, []byte("row1"), []byte("col1"), []byte("v01"), 9, 0)
ma.Add(1, []byte("row1"), []byte("col2"), []byte("v02"), 8, 0)
ma.Add(1, []byte("row1"), []byte("col3"), []byte("v03"), 7, 0)
ma.Add(1, []byte("row8"), []byte("col4"), []byte("v04"), 6, 0)
_, err := tc.MSet(ma)
if err != nil {
fmt.Printf("Mset failed: %s\n", err)
return
}
// MGET
var mb table.MGetArgs
mb.Add(1, []byte("row8"), []byte("col4"), 0)
mb.Add(1, []byte("row1"), []byte("col2"), 0)
mb.Add(1, []byte("row1"), []byte("col1"), 0)
mb.Add(1, []byte("row1"), []byte("col3"), 0)
mb.Add(1, []byte("row8"), []byte("not"), 0)
r, err := tc.MGet(mb)
if err != nil {
fmt.Printf("Mget failed: %s\n", err)
return
}
fmt.Println("MGET result:")
for i := 0; i < len(r); i++ {
if r[i].ErrCode < 0 {
fmt.Printf("[%q\t%q]\tget failed with error %d!\n",
r[i].RowKey, r[i].ColKey, r[i].ErrCode)
} else if r[i].ErrCode > 0 {
fmt.Printf("[%q\t%q]\tkey not exist!\n",
r[i].RowKey, r[i].ColKey)
} else {
fmt.Printf("[%q\t%q]\t[%d\t%q]\n",
r[i].RowKey, r[i].ColKey,
r[i].Score, r[i].Value)
}
}
}
开发者ID:tradia,项目名称:gotable,代码行数:42,代码来源:example.go
示例10: testAsync
func testAsync(tc *table.Context) {
//var done = make(chan *table.Call, 2)
c1, err := tc.GoScan(1, []byte("row1"), true, 10, nil)
if err != nil {
fmt.Printf("GoScan failed: %s\n", err)
return
}
c2, err := tc.GoZScan(1, []byte("row2"), true, true, 10, nil)
if err != nil {
fmt.Printf("GoZScan failed: %s\n", err)
return
}
// Wait for reply
<-c1.Done
<-c2.Done
r1, err := c1.Reply()
if err != nil {
fmt.Printf("Reply failed: %s\n", err)
return
} else {
fmt.Println("ASYNC C1 result:")
printScanReply(r1.(table.ScanReply))
}
r2, err := c2.Reply()
if err != nil {
fmt.Printf("Reply failed: %s\n", err)
return
} else {
fmt.Println("ASYNC C2 result:")
printScanReply(r2.(table.ScanReply))
}
}
开发者ID:tradia,项目名称:gotable,代码行数:36,代码来源:example.go
示例11: testZScan
func testZScan(tc *table.Context) {
// ZSET
err := tc.ZSet(1, []byte("row2"), []byte("000"), []byte("v00"), 10, 0)
if err != nil {
fmt.Printf("ZSet failed: %s\n", err)
return
}
// ZMSET
var ma table.MSetArgs
ma.Add(1, []byte("row2"), []byte("001"), []byte("v01"), 9, 0)
ma.Add(1, []byte("row2"), []byte("002"), []byte("v02"), 6, 0)
ma.Add(1, []byte("row2"), []byte("003"), []byte("v03"), 7, 0)
ma.Add(1, []byte("row2"), []byte("004"), []byte("v04"), 8, 0)
ma.Add(1, []byte("row2"), []byte("005"), []byte("v05"), -5, 0)
_, err = tc.ZmSet(ma)
if err != nil {
fmt.Printf("ZmSet failed: %s\n", err)
return
}
// ZSCAN
r, err := tc.ZScan(1, []byte("row2"), true, true, 4)
if err != nil {
fmt.Printf("ZScan failed: %s\n", err)
return
}
fmt.Println("ZSCAN result:")
for {
printScanReply(r)
if r.End {
fmt.Println("ZSCAN finished!")
break
} else {
fmt.Println("ZSCAN has more records:")
}
r, err = tc.ScanMore(r)
if err != nil {
fmt.Printf("ScanMore failed: %s\n", err)
return
}
}
}
开发者ID:tradia,项目名称:gotable,代码行数:46,代码来源:example.go
示例12: testGet
func testGet(tc *table.Context) {
// SET
err := tc.Set(1, []byte("row1"), []byte("col1"), []byte("v01"), 10, 0)
if err != nil {
fmt.Printf("Set failed: %s\n", err)
return
}
// GET
value, score, _, err := tc.Get(1, []byte("row1"), []byte("col1"), 0)
if err != nil {
fmt.Printf("Get failed: %s\n", err)
return
}
if value == nil {
fmt.Printf("GET result1: Key not exist!\n")
} else {
fmt.Printf("GET result1: %q\t%d\n", value, score)
}
// DEL
err = tc.Del(1, []byte("row1"), []byte("col1"), 0)
if err != nil {
fmt.Printf("Del failed: %s\n", err)
return
}
// GET
value, score, _, err = tc.Get(1, []byte("row1"), []byte("col1"), 0)
if err != nil {
fmt.Printf("Get failed: %s\n", err)
return
}
if value == nil {
fmt.Printf("GET result2: Key not exist!\n")
} else {
fmt.Printf("GET result2: %q\t%d\n", value, score)
}
}
开发者ID:tradia,项目名称:gotable,代码行数:41,代码来源:example.go
示例13: testCas
func testCas(tc *table.Context) {
var value []byte
var score int64
var cas, newCas uint32
var err error
// Try i < 11 for cas not match
for i := 0; i < 1; i++ {
// GET with CAS=2
value, score, newCas, err = tc.Get(1, []byte("row1"), []byte("col1"), 2)
if err != nil {
fmt.Printf("Get failed: %s\n", err)
return
}
if i > 0 {
time.Sleep(time.Second)
} else {
cas = newCas
}
fmt.Printf("\tCas %02d: (%d %d)\t(%s, %d)\n", i, newCas, cas, value, score)
}
// SET with CAS
err = tc.Set(1, []byte("row1"), []byte("col1"),
[]byte(string(value)+"-cas"), score+20, cas)
if err != nil {
fmt.Printf("Set failed: %s\n", err)
}
// GET without CAS
value, score, _, err = tc.Get(1, []byte("row1"), []byte("col1"), 0)
if err != nil {
fmt.Printf("Get failed: %s\n", err)
return
}
fmt.Printf("CAS result: %q\t%d\n", value, score)
}
开发者ID:tradia,项目名称:gotable,代码行数:39,代码来源:example.go
注:本文中的github.com/stevejiang/gotable/api/go/table.Context类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论