示例#1
0
文件: main.go 项目: tradia/gotable
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))
	}
}
示例#2
0
文件: example.go 项目: tradia/gotable
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
		}
	}
}