本文整理汇总了Golang中github.com/pingcap/tidb/kv.RetrieverMutator.Get方法的典型用法代码示例。如果您正苦于以下问题:Golang RetrieverMutator.Get方法的具体用法?Golang RetrieverMutator.Get怎么用?Golang RetrieverMutator.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pingcap/tidb/kv.RetrieverMutator
的用法示例。
在下文中一共展示了RetrieverMutator.Get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Exist
func (c *index) Exist(rm kv.RetrieverMutator, indexedValues []types.Datum, h int64) (bool, int64, error) {
key, distinct, err := c.GenIndexKey(indexedValues, h)
if err != nil {
return false, 0, errors.Trace(err)
}
value, err := rm.Get(key)
if kv.IsErrNotFound(err) {
return false, 0, nil
}
if err != nil {
return false, 0, errors.Trace(err)
}
// For distinct index, the value of key is handle.
if distinct {
handle, err := decodeHandle(value)
if err != nil {
return false, 0, errors.Trace(err)
}
if handle != h {
return true, handle, errors.Trace(kv.ErrKeyExists)
}
return true, handle, nil
}
return true, h, nil
}
示例2: Create
// Create creates a new entry in the kvIndex data.
// If the index is unique and there is an existing entry with the same key, Create will return ErrKeyExists.
func (c *index) Create(rm kv.RetrieverMutator, indexedValues []types.Datum, h int64) error {
key, distinct, err := c.GenIndexKey(indexedValues, h)
if err != nil {
return errors.Trace(err)
}
if !distinct {
// TODO: reconsider value
err = rm.Set(key, []byte("timestamp?"))
return errors.Trace(err)
}
_, err = rm.Get(key)
if kv.IsErrNotFound(err) {
err = rm.Set(key, encodeHandle(h))
return errors.Trace(err)
}
return errors.Trace(kv.ErrKeyExists)
}
示例3: Create
// Create creates a new entry in the kvIndex data.
// If the index is unique and there is an existing entry with the same key,
// Create will return the existing entry's handle as the first return value, ErrKeyExists as the second return value.
func (c *index) Create(rm kv.RetrieverMutator, indexedValues []types.Datum, h int64) (int64, error) {
key, distinct, err := c.GenIndexKey(indexedValues, h)
if err != nil {
return 0, errors.Trace(err)
}
if !distinct {
// non-unique index doesn't need store value, write a '0' to reduce space
err = rm.Set(key, []byte{'0'})
return 0, errors.Trace(err)
}
value, err := rm.Get(key)
if kv.IsErrNotFound(err) {
err = rm.Set(key, encodeHandle(h))
return 0, errors.Trace(err)
}
handle, err := decodeHandle(value)
if err != nil {
return 0, errors.Trace(err)
}
return handle, errors.Trace(kv.ErrKeyExists)
}