本文整理汇总了Golang中github.com/wandoulabs/redis-port/pkg/libs/errors.Trace函数的典型用法代码示例。如果您正苦于以下问题:Golang Trace函数的具体用法?Golang Trace怎么用?Golang Trace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Trace函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ping
func (c *conn) ping() error {
deadline := time.Now().Add(time.Second * 5)
if err := c.nc.SetDeadline(deadline); err != nil {
return errors.Trace(err)
}
if _, err := c.w.WriteString("*1\r\n$4\r\nping\r\n"); err != nil {
return errors.Trace(err)
}
if err := c.w.Flush(); err != nil {
return errors.Trace(err)
}
var rsp string
for !strings.HasSuffix(rsp, "\r\n") {
b := []byte{0}
if _, err := c.r.Read(b); err != nil {
return errors.Trace(err)
}
if len(rsp) == 0 && b[0] == '\n' {
continue
}
rsp += string(b)
}
rsp = rsp[:len(rsp)-2]
if strings.ToLower(rsp) != "+pong" {
return errors.Errorf("invalid response of command ping: %s", rsp)
} else {
return nil
}
}
开发者ID:fengshao0907,项目名称:rpdb,代码行数:30,代码来源:conn.go
示例2: EncodeObject
func (e *Encoder) EncodeObject(db uint32, key []byte, expireat uint64, obj interface{}) error {
o, ok := obj.(objectEncoder)
if !ok {
return errors.Errorf("unsupported object type")
}
if e.db == -1 || uint32(e.db) != db {
e.db = int64(db)
if err := e.enc.EncodeDatabase(int(db)); err != nil {
return errors.Trace(err)
}
}
if expireat != 0 {
if err := e.enc.EncodeExpiry(expireat); err != nil {
return errors.Trace(err)
}
}
if err := o.encodeType(e.enc); err != nil {
return err
}
if err := e.enc.EncodeString(key); err != nil {
return errors.Trace(err)
}
if err := o.encodeValue(e.enc); err != nil {
return err
}
return nil
}
开发者ID:hushi55,项目名称:Grep,代码行数:27,代码来源:encoder.go
示例3: loadRpdbRow
func loadRpdbRow(r rpdbReader, db uint32, key []byte) (rpdbRow, error) {
metaKey := EncodeMetaKey(db, key)
p, err := r.getRowValue(metaKey)
if err != nil || p == nil {
return nil, err
}
if len(p) == 0 {
return nil, errors.Trace(ErrObjectCode)
}
var o rpdbRow
var code = ObjectCode(p[0])
switch code {
default:
return nil, errors.Trace(ErrObjectCode)
case StringCode:
o = new(stringRow)
case HashCode:
o = new(hashRow)
case ListCode:
o = new(listRow)
case ZSetCode:
o = new(zsetRow)
case SetCode:
o = new(setRow)
}
o.lazyInit(&rpdbRowHelper{
code: code,
metaKey: metaKey,
dataKeyPrefix: EncodeDataKeyPrefix(db, key),
})
return o, o.ParseMetaValue(p)
}
开发者ID:fengshao0907,项目名称:rpdb,代码行数:32,代码来源:row.go
示例4: encodeText
func (e *encoder) encodeText(s string) error {
if _, err := e.w.WriteString(s); err != nil {
return errors.Trace(err)
}
if _, err := e.w.WriteString("\r\n"); err != nil {
return errors.Trace(err)
}
return nil
}
开发者ID:TigerZhang,项目名称:redis-port,代码行数:9,代码来源:encoder.go
示例5: encodeValue
func (o Set) encodeValue(enc *rdb.Encoder) error {
if err := enc.EncodeLength(uint32(len(o))); err != nil {
return errors.Trace(err)
}
for _, e := range o {
if err := enc.EncodeString(e); err != nil {
return errors.Trace(err)
}
}
return nil
}
开发者ID:hushi55,项目名称:Grep,代码行数:11,代码来源:encoder.go
示例6: decodeText
func (d *decoder) decodeText() (string, error) {
b, err := d.r.ReadBytes('\n')
if err != nil {
return "", errors.Trace(err)
}
if n := len(b) - 2; n < 0 || b[n] != '\r' {
return "", errors.Trace(ErrBadRespCRLFEnd)
} else {
return string(b[:n]), nil
}
}
开发者ID:TigerZhang,项目名称:redis-port,代码行数:11,代码来源:decoder.go
示例7: writeSome
func (p *fileBuffer) writeSome(b []byte) (int, error) {
if p.f == nil {
return 0, errors.Trace(ErrClosedBacklog)
}
maxlen, offset := woffset(len(b), p.size, p.wpos)
if maxlen == 0 {
return 0, nil
}
n, err := p.f.WriteAt(b[:maxlen], int64(offset))
p.wpos += uint64(n)
return n, errors.Trace(err)
}
开发者ID:TigerZhang,项目名称:redis-port,代码行数:12,代码来源:file.go
示例8: readSomeAt
func (p *memBuffer) readSomeAt(b []byte, rpos uint64) (int, error) {
if p.b == nil {
return 0, errors.Trace(ErrClosedBacklog)
}
if rpos > p.wpos || rpos+p.size < p.wpos {
return 0, errors.Trace(ErrInvalidOffset)
}
maxlen, offset := roffset(len(b), p.size, rpos, p.wpos)
if maxlen == 0 {
return 0, nil
}
n := copy(b, p.b[offset:offset+maxlen])
return n, nil
}
开发者ID:TigerZhang,项目名称:redis-port,代码行数:14,代码来源:buff.go
示例9: Clear
func (db *RocksDB) Clear() error {
if db.rkdb != nil {
db.rkdb.Close()
db.rkdb = nil
db.opts.SetCreateIfMissing(true)
db.opts.SetErrorIfExists(true)
if err := gorocks.DestroyDatabase(db.path, db.opts); err != nil {
return errors.Trace(err)
} else if db.rkdb, err = gorocks.Open(db.path, db.opts); err != nil {
return errors.Trace(err)
}
}
return nil
}
开发者ID:fengshao0907,项目名称:rpdb,代码行数:14,代码来源:database.go
示例10: readSomeAt
func (p *fileBuffer) readSomeAt(b []byte, rpos uint64) (int, error) {
if p.f == nil {
return 0, errors.Trace(ErrClosedBacklog)
}
if rpos > p.wpos || rpos+p.size < p.wpos {
return 0, errors.Trace(ErrInvalidOffset)
}
maxlen, offset := roffset(len(b), p.size, rpos, p.wpos)
if maxlen == 0 {
return 0, nil
}
n, err := p.f.ReadAt(b[:maxlen], int64(offset))
return n, errors.Trace(err)
}
开发者ID:TigerZhang,项目名称:redis-port,代码行数:14,代码来源:file.go
示例11: Serve
func Serve(config *Config, bl *rpdb.Rpdb) error {
h := &Handler{
config: config,
master: make(chan *conn, 0),
signal: make(chan int, 0),
}
defer func() {
close(h.signal)
}()
l, err := net.Listen("tcp", config.Listen)
if err != nil {
return errors.Trace(err)
}
defer l.Close()
if h.htable, err = redis.NewHandlerTable(h); err != nil {
return err
} else {
go h.daemonSyncMaster()
}
log.Infof("open listen address '%s' and start service", l.Addr())
for {
if nc, err := l.Accept(); err != nil {
return errors.Trace(err)
} else {
h.counters.clientsAccepted.Add(1)
go func() {
h.counters.clients.Add(1)
defer h.counters.clients.Sub(1)
c := newConn(nc, bl, h.config.ConnTimeout)
defer c.Close()
log.Infof("new connection: %s", c.summ)
if err := c.serve(h); err != nil {
if errors.Equal(err, io.EOF) {
log.Infof("connection lost: %s [io.EOF]", c.summ)
} else {
log.InfoErrorf(err, "connection lost: %s", c.summ)
}
} else {
log.Infof("connection exit: %s", c.summ)
}
}()
}
}
}
开发者ID:fengshao0907,项目名称:rpdb,代码行数:48,代码来源:main.go
示例12: decodeRawBytes
func decodeRawBytes(r *BufReader, err error, refs ...interface{}) error {
if err != nil {
return err
}
if len(refs) == 0 {
if r.Len() != 0 {
return errors.Trace(ErrNotMatched)
}
return nil
}
for _, i := range refs {
switch x := i.(type) {
case byte:
if v, err := r.ReadByte(); err != nil {
return err
} else if v != x {
return errors.Errorf("read byte %d, expect %d", v, x)
}
case ObjectCode:
if v, err := r.ReadByte(); err != nil {
return err
} else if v != byte(x) {
return errors.Errorf("read code [%s], expect [%s]", ObjectCode(v), x)
}
case *[]byte:
p, err := r.ReadVarbytes()
if err != nil {
return err
}
*x = p
case *uint32:
v, err := r.ReadUvarint()
if err != nil {
return err
}
*x = uint32(v)
case *uint64:
v, err := r.ReadUvarint()
if err != nil {
return err
}
*x = v
case *int64:
v, err := r.ReadVarint()
if err != nil {
return err
}
*x = v
case *float64:
v, err := r.ReadFloat64()
if err != nil {
return err
}
*x = v
default:
log.Panicf("unsupported type in row value: %+v", x)
}
}
return nil
}
开发者ID:fengshao0907,项目名称:rpdb,代码行数:60,代码来源:row.go
示例13: encodeBulkBytes
func (e *encoder) encodeBulkBytes(b []byte) error {
if b == nil {
return e.encodeInt(-1)
} else {
if err := e.encodeInt(int64(len(b))); err != nil {
return err
}
if _, err := e.w.Write(b); err != nil {
return errors.Trace(err)
}
if _, err := e.w.WriteString("\r\n"); err != nil {
return errors.Trace(err)
}
return nil
}
}
开发者ID:TigerZhang,项目名称:redis-port,代码行数:16,代码来源:encoder.go
示例14: DecodeDump
func DecodeDump(p []byte) (interface{}, error) {
d := &decoder{}
if err := rdb.DecodeDump(p, 0, nil, 0, d); err != nil {
return nil, errors.Trace(err)
}
return d.obj, d.err
}
开发者ID:hushi55,项目名称:Grep,代码行数:7,代码来源:decoder.go
示例15: ParseFloat
func ParseFloat(i interface{}) (float64, error) {
var s string
switch x := Num64(i).(type) {
case int64:
return float64(x), nil
case uint64:
return float64(x), nil
case float64:
switch {
case math.IsNaN(x):
return 0, errors.New("float is NaN")
case math.IsInf(x, 0):
return 0, errors.New("float is Inf")
}
return float64(x), nil
case string:
s = x
case []byte:
s = string(x)
default:
s = fmt.Sprint(x)
}
f, err := strconv.ParseFloat(s, 64)
return f, errors.Trace(err)
}
开发者ID:fengshao0907,项目名称:rpdb,代码行数:25,代码来源:format.go
示例16: ParseUint
func ParseUint(i interface{}) (uint64, error) {
var s string
switch x := Num64(i).(type) {
case int64:
if x < 0 {
return 0, errors.New("integer overflow")
}
return uint64(x), nil
case uint64:
return uint64(x), nil
case float64:
switch {
case math.IsNaN(x):
return 0, errors.New("float is NaN")
case math.IsInf(x, 0):
return 0, errors.New("float is Inf")
case math.Abs(x-float64(uint64(x))) > 1e-9:
return 0, errors.New("float to uint64")
}
return uint64(x), nil
case string:
s = x
case []byte:
s = string(x)
default:
s = fmt.Sprint(x)
}
u, err := strconv.ParseUint(s, 10, 64)
return u, errors.Trace(err)
}
开发者ID:fengshao0907,项目名称:rpdb,代码行数:30,代码来源:format.go
示例17: SlaveOf
// SLAVEOF host port
func (h *Handler) SlaveOf(arg0 interface{}, args [][]byte) (redis.Resp, error) {
if len(args) != 2 {
return toRespErrorf("len(args) = %d, expect = 2", len(args))
}
s, err := session(arg0, args)
if err != nil {
return toRespError(err)
}
addr := fmt.Sprintf("%s:%s", string(args[0]), string(args[1]))
log.Infof("set slave of %s", addr)
var c *conn
if strings.ToLower(addr) != "no:one" {
if nc, err := net.DialTimeout("tcp", addr, time.Second); err != nil {
return toRespError(errors.Trace(err))
} else {
c = newConn(nc, s.Rpdb(), 0)
if err := c.ping(); err != nil {
c.Close()
return toRespError(err)
}
}
}
select {
case <-h.signal:
if c != nil {
c.Close()
}
return toRespErrorf("sync master has been closed")
case h.master <- c:
return redis.NewString("OK"), nil
}
}
开发者ID:fengshao0907,项目名称:rpdb,代码行数:36,代码来源:sync.go
示例18: ParseFloat64
func ParseFloat64(i interface{}) (float64, error) {
if v, ok := Num64(i); ok {
switch x := v.(type) {
case int64:
return float64(x), nil
case uint64:
return float64(x), nil
case float64:
switch {
case math.IsNaN(x):
return 0, errors.Errorf("parse nan float64")
case math.IsInf(x, 0):
return 0, errors.Errorf("parse inf float64")
}
return float64(x), nil
default:
return 0, errors.Errorf("parse float64 from unknown num64")
}
} else {
var s string
switch x := i.(type) {
case nil:
return 0, errors.Errorf("parse float64 from nil")
case string:
s = x
case []byte:
s = string(x)
default:
return 0, errors.Errorf("parse float64 from <%s>", reflect.TypeOf(i))
}
f, err := strconv.ParseFloat(s, 64)
return f, errors.Trace(err)
}
}
开发者ID:TigerZhang,项目名称:redis-port,代码行数:34,代码来源:strconv.go
示例19: restore
func (b *Rpdb) restore(bt *store.Batch, db uint32, key []byte, expireat uint64, obj interface{}) error {
_, err := b.deleteIfExists(bt, db, key)
if err != nil {
return err
}
if !IsExpired(expireat) {
var o rpdbRow
switch obj.(type) {
default:
return errors.Trace(ErrObjectValue)
case rdb.String:
o = newStringRow(db, key)
case rdb.Hash:
o = newHashRow(db, key)
case rdb.List:
o = newListRow(db, key)
case rdb.ZSet:
o = newZSetRow(db, key)
case rdb.Set:
o = newSetRow(db, key)
}
return o.storeObject(b, bt, expireat, obj)
}
log.Debugf("restore an expired object, db = %d, key = %v, expireat = %d", db, key, expireat)
return nil
}
开发者ID:fengshao0907,项目名称:rpdb,代码行数:28,代码来源:keys.go
示例20: openSyncConn
func openSyncConn(target string, passwd string) (net.Conn, <-chan int64) {
c := openNetConn(target, passwd)
if _, err := c.Write(redis.MustEncodeToBytes(redis.NewCommand("sync"))); err != nil {
log.PanicError(errors.Trace(err), "write sync command failed")
}
return c, waitRdbDump(c)
}
开发者ID:TigerZhang,项目名称:redis-port,代码行数:7,代码来源:utils.go
注:本文中的github.com/wandoulabs/redis-port/pkg/libs/errors.Trace函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论