本文整理匯總了Golang中github.com/cockroachdb/cockroach/client.Txn.Put方法的典型用法代碼示例。如果您正苦於以下問題:Golang Txn.Put方法的具體用法?Golang Txn.Put怎麽用?Golang Txn.Put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cockroachdb/cockroach/client.Txn
的用法示例。
在下文中一共展示了Txn.Put方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: incCmd
// incCmd adds one to the value of c.key in the env (as determined by
// a previous read or write, or else assumed to be zero) and writes it
// to the db.
func incCmd(c *cmd, txn *client.Txn, t *testing.T) *roachpb.Error {
r := c.env[c.key] + 1
if pErr := txn.Put(c.getKey(), r); pErr != nil {
return pErr
}
c.env[c.key] = r
c.debug = fmt.Sprintf("[%d]", r)
return nil
}
示例2: writeCmd
// writeCmd sums values from the env (and possibly numeric constants)
// and writes the value to the db. "c.endKey" here needs to be parsed
// in the context of this command, which is a "+"-separated list of
// keys from the env or numeric constants to sum.
func writeCmd(c *cmd, txn *client.Txn, t *testing.T) *roachpb.Error {
sum := int64(0)
for _, sp := range strings.Split(c.endKey, "+") {
if constant, err := strconv.Atoi(sp); err != nil {
sum += c.env[sp]
} else {
sum += int64(constant)
}
}
pErr := txn.Put(c.getKey(), sum)
c.debug = fmt.Sprintf("[%d]", sum)
return pErr
}
示例3: incCmd
// incCmd adds one to the value of c.key in the env (as determined by
// a previous read or write, or else assumed to be zero) and writes it
// to the db.
func incCmd(c *cmd, txn *client.Txn, t *testing.T) error {
val, ok := c.env[c.key]
if !ok {
panic(fmt.Sprintf("can't increment key %q; not yet read", c.key))
}
r := val + 1
if err := txn.Put(c.getKey(), r); err != nil {
return err
}
c.env[c.key] = r
c.debug = fmt.Sprintf("[%d]", r)
return nil
}