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)) } }
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) }
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) } }
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) }