當前位置: 首頁>>代碼示例>>Golang>>正文


Golang resp.NewArray函數代碼示例

本文整理匯總了Golang中github.com/reborndb/go/redis/resp.NewArray函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewArray函數的具體用法?Golang NewArray怎麽用?Golang NewArray使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewArray函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: RoleCmd

// ROLE
func RoleCmd(s Session, args [][]byte) (redis.Resp, error) {
	if len(args) != 0 {
		return toRespErrorf("len(args) = %d, expect = 0", len(args))
	}

	c, _ := s.(*conn)
	if c == nil {
		return nil, errors.New("invalid connection")
	}

	ay := redis.NewArray()
	if masterAddr := c.h.masterAddr.Get(); masterAddr == "" {
		// master
		ay.Append(redis.NewBulkBytesWithString("master"))
		c.h.repl.RLock()
		defer c.h.repl.RUnlock()

		ay.Append(redis.NewInt(c.h.repl.masterOffset))
		slaves := redis.NewArray()
		for slave, _ := range c.h.repl.slaves {
			a := redis.NewArray()
			if addr := slave.nc.RemoteAddr(); addr == nil {
				continue
			} else {
				a.Append(redis.NewBulkBytesWithString(strings.Split(addr.String(), ":")[0]))
			}
			a.Append(redis.NewBulkBytesWithString(fmt.Sprintf("%d", slave.listeningPort.Get())))
			a.Append(redis.NewBulkBytesWithString(fmt.Sprintf("%d", slave.syncOffset.Get())))
			slaves.Append(a)
		}

		ay.Append(slaves)
	} else {
		// slave
		ay.Append(redis.NewBulkBytesWithString("slave"))
		seps := strings.Split(masterAddr, ":")
		if len(seps) == 2 {
			port, err := strconv.ParseInt(seps[1], 10, 16)
			if err != nil {
				return toRespError(err)
			}
			ay.Append(redis.NewBulkBytesWithString(seps[0]))
			ay.Append(redis.NewInt(int64(port)))
		} else {
			return toRespErrorf("invalid master addr, must ip:port, but %s", masterAddr)
		}
		ay.Append(redis.NewBulkBytesWithString(c.h.masterConnState.Get()))
		ay.Append(redis.NewInt(c.h.syncOffset.Get()))
	}
	return ay, nil
}
開發者ID:CowLeo,項目名稱:qdb,代碼行數:52,代碼來源:repl.go

示例2: SlotsHashKeyCmd

// SLOTSHASHKEY key [key...]
func SlotsHashKeyCmd(s Session, args [][]byte) (redis.Resp, error) {
	resp := redis.NewArray()
	for _, key := range args {
		_, slot := store.HashKeyToSlot(key)
		resp.AppendInt(int64(slot))
	}
	return resp, nil
}
開發者ID:cuiwm,項目名稱:reborn,代碼行數:9,代碼來源:slots.go

示例3: SlotsInfoCmd

// SLOTSINFO [start [count]]
func SlotsInfoCmd(s Session, args [][]byte) (redis.Resp, error) {
	if m, err := s.Store().SlotsInfo(s.DB(), args); err != nil {
		return toRespError(err)
	} else {
		resp := redis.NewArray()
		for i := uint32(0); i < store.MaxSlotNum; i++ {
			v, ok := m[i]
			if ok {
				s := redis.NewArray()
				s.AppendInt(int64(i))
				s.AppendInt(v)
				resp.Append(s)
			}
		}
		return resp, nil
	}
}
開發者ID:cuiwm,項目名稱:reborn,代碼行數:18,代碼來源:slots.go

示例4: doMigrate

func doMigrate(addr string, timeout time.Duration, db uint32, bins []*rdb.BinEntry) error {
	c, err := getSockConn(addr, timeout)
	if err != nil {
		log.Warningf("connect to %s failed, timeout = %d, err = %s", addr, timeout, err)
		return errors.Trace(err)
	}
	defer putSockConn(addr, c)

	cmd1 := redis.NewArray()
	cmd1.AppendBulkBytes([]byte("select"))
	cmd1.AppendBulkBytes([]byte(FormatUint(uint64(db))))

	if err := c.DoMustOK(cmd1, timeout); err != nil {
		log.Warningf("command select failed, addr = %s, db = %d, err = %s", addr, db, err)
		return errors.Trace(err)
	}
	log.Debugf("command select ok, addr = %s, db = %d, err = %s", addr, db, err)

	cmd2 := redis.NewArray()
	cmd2.AppendBulkBytes([]byte("slotsrestore"))
	for _, bin := range bins {
		cmd2.AppendBulkBytes(bin.Key)
		ttlms := int64(0)
		if bin.ExpireAt != 0 {
			if v, ok := ExpireAtToTTLms(int64(bin.ExpireAt)); ok && v > 0 {
				ttlms = v
			} else {
				ttlms = 1
			}
		}
		cmd2.AppendBulkBytes([]byte(FormatInt(ttlms)))
		cmd2.AppendBulkBytes(bin.Value)
	}

	if err := c.DoMustOK(cmd2, timeout); err != nil {
		log.Warningf("command restore failed, addr = %s, db = %d, len(bins) = %d, err = %s", addr, db, len(bins), err)
		return errors.Trace(err)
	} else {
		log.Debugf("command restore ok, addr = %s, db = %d, len(bins) = %d", addr, db, len(bins))
		return nil
	}
}
開發者ID:CowLeo,項目名稱:qdb,代碼行數:42,代碼來源:migrate.go

示例5: HValsCmd

// HVALS key
func HValsCmd(s Session, args [][]byte) (redis.Resp, error) {
	if a, err := s.Store().HVals(s.DB(), args); err != nil {
		return toRespError(err)
	} else {
		resp := redis.NewArray()
		for _, v := range a {
			resp.AppendBulkBytes(v)
		}
		return resp, nil
	}
}
開發者ID:cuiwm,項目名稱:reborn,代碼行數:12,代碼來源:hash.go

示例6: SlotsMgrtTagSlotCmd

// SLOTSMGRTTAGSLOT host port timeout slot
func SlotsMgrtTagSlotCmd(s Session, args [][]byte) (redis.Resp, error) {
	if n, err := s.Store().SlotsMgrtTagSlot(s.DB(), args); err != nil {
		return toRespError(err)
	} else {
		resp := redis.NewArray()
		resp.AppendInt(n)
		if n != 0 {
			resp.AppendInt(1)
		} else {
			resp.AppendInt(0)
		}
		return resp, nil
	}
}
開發者ID:cuiwm,項目名稱:reborn,代碼行數:15,代碼來源:slots.go

示例7: RegisterArrayReply

func RegisterArrayReply(name string, f CommandArrayFunc, flag CommandFlag) {
	v := func(s Session, args [][]byte) (redis.Resp, error) {
		r, err := f(s, args)
		if err != nil {
			return toRespError(err)
		}
		ay := redis.NewArray()
		for _, b := range r {
			ay.AppendBulkBytes(b)
		}
		return ay, nil
	}

	register(name, v, flag)
}
開發者ID:CowLeo,項目名稱:qdb,代碼行數:15,代碼來源:command.go


注:本文中的github.com/reborndb/go/redis/resp.NewArray函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。