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


Golang resp.NewBulkBytes函數代碼示例

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


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

示例1: ZScoreCmd

// ZSCORE key member
func ZScoreCmd(s Session, args [][]byte) (redis.Resp, error) {
	if v, ok, err := s.Store().ZScore(s.DB(), args); err != nil {
		return toRespError(err)
	} else if !ok {
		return redis.NewBulkBytes(nil), nil
	} else {
		return redis.NewBulkBytes(store.FormatFloat(v)), nil
	}
}
開發者ID:CowLeo,項目名稱:qdb,代碼行數:10,代碼來源:zset.go

示例2: HGetCmd

// HGET key field
func HGetCmd(s Session, args [][]byte) (redis.Resp, error) {
	if b, err := s.Store().HGet(s.DB(), args); err != nil {
		return toRespError(err)
	} else {
		return redis.NewBulkBytes(b), nil
	}
}
開發者ID:cuiwm,項目名稱:reborn,代碼行數:8,代碼來源:hash.go

示例3: EchoCmd

// ECHO text
func EchoCmd(s Session, args [][]byte) (redis.Resp, error) {
	if len(args) != 1 {
		return toRespErrorf("len(args) = %d, expect = 1", len(args))
	}

	return redis.NewBulkBytes(args[0]), nil
}
開發者ID:vebin,項目名稱:reborn,代碼行數:8,代碼來源:misc.go

示例4: InfoCmd

// INFO [section]
func InfoCmd(s Session, args [][]byte) (redis.Resp, error) {
	if len(args) != 0 && len(args) != 1 {
		return toRespErrorf("len(args) = %d, expect = 0|1", len(args))
	}

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

	section := "all"
	if len(args) == 1 {
		section = strings.ToLower(string(args[0]))
	}

	var b bytes.Buffer

	switch section {
	case "database":
		c.h.infoDataBase(&b)
	case "config":
		c.h.infoConfig(&b)
	case "clients":
		c.h.infoClients(&b)
	case "replication":
		c.h.infoReplication(&b)
	default:
		// all
		c.h.infoAll(&b)
	}

	fmt.Fprintf(&b, "\r\n")

	return redis.NewBulkBytes(b.Bytes()), nil
}
開發者ID:vebin,項目名稱:reborn,代碼行數:36,代碼來源:misc.go

示例5: ZIncrByCmd

// ZINCRBY key delta member
func ZIncrByCmd(s Session, args [][]byte) (redis.Resp, error) {
	if v, err := s.Store().ZIncrBy(s.DB(), args); err != nil {
		return toRespError(err)
	} else {
		return redis.NewBulkBytes(store.FormatFloat(v)), nil
	}
}
開發者ID:CowLeo,項目名稱:qdb,代碼行數:8,代碼來源:zset.go

示例6: LIndexCmd

// LINDEX key index
func LIndexCmd(s Session, args [][]byte) (redis.Resp, error) {
	if v, err := s.Store().LIndex(s.DB(), args); err != nil {
		return toRespError(err)
	} else {
		return redis.NewBulkBytes(v), nil
	}
}
開發者ID:cuiwm,項目名稱:reborn,代碼行數:8,代碼來源:list.go

示例7: SetCmd

// SET key value [EX seconds] [PX milliseconds] [NX|XX]
func SetCmd(s Session, args [][]byte) (redis.Resp, error) {
	if err := s.Store().Set(s.DB(), args); err != nil && errors2.ErrorNotEqual(err, store.ErrSetAborted) {
		return toRespError(err)
	} else if errors2.ErrorEqual(err, store.ErrSetAborted) {
		return redis.NewBulkBytes(nil), nil
	} else {
		return redis.NewString("OK"), nil
	}
}
開發者ID:CowLeo,項目名稱:qdb,代碼行數:10,代碼來源:string.go

示例8: ZRevRankCmd

// ZREVRANK key member
func ZRevRankCmd(s Session, args [][]byte) (redis.Resp, error) {
	if v, err := s.Store().ZRevRank(s.DB(), args); err != nil {
		return toRespError(err)
	} else if v >= 0 {
		return redis.NewInt(v), nil
	} else {
		return redis.NewBulkBytes(nil), nil
	}
}
開發者ID:CowLeo,項目名稱:qdb,代碼行數:10,代碼來源:zset.go

示例9: DumpCmd

// DUMP key
func DumpCmd(s Session, args [][]byte) (redis.Resp, error) {
	if x, err := s.Store().Dump(s.DB(), args); err != nil {
		return toRespError(err)
	} else if dump, err := rdb.EncodeDump(x); err != nil {
		return toRespError(err)
	} else {
		return redis.NewBulkBytes(dump), nil
	}
}
開發者ID:CowLeo,項目名稱:qdb,代碼行數:10,代碼來源:keys.go

示例10: RegisterBulkReply

func RegisterBulkReply(name string, f CommandBulkStringFunc, flag CommandFlag) {
	v := func(s Session, args [][]byte) (redis.Resp, error) {
		r, err := f(s, args)
		if err != nil {
			return toRespError(err)
		}
		return redis.NewBulkBytes(r), nil
	}

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

示例11: testReplication

func (s *testReplSuite) testReplication(c *C, master testReplNode, slave testReplNode) {
	// first let both stop replication
	s.doCmdMustOK(c, master.Port(), "SLAVEOF", "NO", "ONE")
	s.doCmdMustOK(c, slave.Port(), "SLAVEOF", "NO", "ONE")

	s.doCmdMustOK(c, master.Port(), "SET", "a", "100")

	offset := int64(-1)
	// slaveof, will do full sync first, must support psync
	nc := slave.Slaveof(c, master.Port())
	defer nc.Close(c)

	s.waitAndCheckSyncOffset(c, slave, offset)

	resp := s.doCmd(c, slave.Port(), "GET", "a")
	c.Assert(slave.SyncOffset(c), Not(Equals), int64(-1))
	c.Assert(resp, DeepEquals, redis.NewBulkBytesWithString("100"))

	// write to a slave, must error
	resp = s.doCmd(c, slave.Port(), "SET", "e", "1")
	c.Assert(resp, FitsTypeOf, (*redis.Error)(nil))
	c.Assert(resp.(*redis.Error).Value, Matches, "READONLY.*")

	s.doCmdMustOK(c, master.Port(), "SET", "b", "100")

	time.Sleep(500 * time.Millisecond)
	resp = s.doCmd(c, slave.Port(), "GET", "b")
	c.Assert(resp, DeepEquals, redis.NewBulkBytesWithString("100"))

	s.doCmdMustOK(c, master.Port(), "SET", "c", "")

	// set another value with TTL
	s.doCmdMustOK(c, master.Port(), "SET", "ttl_key", "1", "PX", 100)

	time.Sleep(500 * time.Millisecond)
	resp = s.doCmd(c, slave.Port(), "GET", "c")
	c.Assert(resp, DeepEquals, redis.NewBulkBytesWithString(""))

	// get expired key to let master force delete it
	resp = s.doCmd(c, master.Port(), "GET", "ttl_key")
	c.Assert(resp, DeepEquals, redis.NewBulkBytes(nil))

	time.Sleep(500 * time.Millisecond)

	// the key must be deleted from master repliction
	resp = s.doCmd(c, slave.Port(), "GET", "ttl_key")
	c.Assert(resp, DeepEquals, redis.NewBulkBytes(nil))

	offset = slave.SyncOffset(c)
	// now close replication connection
	nc.Close(c)
	s.doCmdMustOK(c, master.Port(), "SET", "b", "1000")

	s.doCmdMustOK(c, master.Port(), "SET", "c", "123")

	s.waitAndCheckSyncOffset(c, slave, offset)

	resp = s.doCmd(c, slave.Port(), "GET", "b")
	c.Assert(resp, DeepEquals, redis.NewBulkBytesWithString("1000"))

	resp = s.doCmd(c, slave.Port(), "GET", "c")
	c.Assert(resp, DeepEquals, redis.NewBulkBytesWithString("123"))

	s.checkRole(c, master.Port(), "master")
	s.checkRole(c, slave.Port(), "slave")

	s.doCmdMustOK(c, slave.Port(), "SLAVEOF", "NO", "ONE")
	s.doCmdMustOK(c, master.Port(), "SLAVEOF", "NO", "ONE")

	s.checkRole(c, master.Port(), "master")
	s.checkRole(c, slave.Port(), "master")
}
開發者ID:CowLeo,項目名稱:qdb,代碼行數:72,代碼來源:repl_test.go


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