• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang redis.NewArray函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/wandoulabs/codis/pkg/proxy/redis.NewArray函数的典型用法代码示例。如果您正苦于以下问题:Golang NewArray函数的具体用法?Golang NewArray怎么用?Golang NewArray使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewArray函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: verifyAuth

func (bc *BackendConn) verifyAuth(c *redis.Conn) error {
	if bc.passwd == "" {
		return nil
	}
	resp := redis.NewArray([]*redis.Resp{
		redis.NewBulkBytes([]byte("AUTH")),
		redis.NewBulkBytes([]byte(bc.passwd)),
	})

	if err := c.Writer.Encode(resp, true); err != nil {
		return err
	}

	resp, err := c.Reader.Decode()
	if err != nil {
		return err
	}
	if resp == nil {
		return errors.New(fmt.Sprintf("error resp: nil response"))
	}
	if resp.IsError() {
		return errors.New(fmt.Sprintf("error resp: %s", resp.Value))
	}
	if resp.IsString() {
		return nil
	} else {
		return errors.New(fmt.Sprintf("error resp: should be string, but got %s", resp.Type))
	}
}
开发者ID:hongzhang2046,项目名称:codis,代码行数:29,代码来源:backend.go


示例2: handleRequestMGet

func (s *Session) handleRequestMGet(r *Request, d Dispatcher) (*Request, error) {
	nkeys := len(r.Resp.Array) - 1
	if nkeys <= 1 {
		return r, d.Dispatch(r)
	}
	var sub = make([]*Request, nkeys)
	for i := 0; i < len(sub); i++ {
		sub[i] = &Request{
			Owner: r.Owner,
			OpSeq: -r.OpSeq,
			OpStr: r.OpStr,
			Start: r.Start,
			Wait:  r.Wait,
			Resp: redis.NewArray([]*redis.Resp{
				r.Resp.Array[0],
				r.Resp.Array[i+1],
			}),
		}
		if err := d.Dispatch(sub[i]); err != nil {
			return nil, err
		}
	}
	r.Coalesce = func() error {
		var array = make([]*redis.Resp, len(sub))
		for i, x := range sub {
			if err := x.Response.Err; err != nil {
				return err
			}
			resp := x.Response.Resp
			if resp == nil {
				return ErrRespIsRequired
			}
			if !resp.IsArray() || len(resp.Array) != 1 {
				return errors.New(fmt.Sprintf("bad mget resp: %s array.len = %d", resp.Type, len(resp.Array)))
			}
			array[i] = resp.Array[0]
		}
		r.Response.Resp = redis.NewArray(array)
		return nil
	}
	return r, nil
}
开发者ID:cbruce,项目名称:codis,代码行数:42,代码来源:session.go


示例3: KeepAlive

func (bc *BackendConn) KeepAlive() bool {
	if len(bc.input) != 0 {
		return false
	}
	r := &Request{
		Resp: redis.NewArray([]*redis.Resp{
			redis.NewBulkBytes([]byte("PING")),
		}),
	}

	select {
	case bc.input <- r:
		return true
	default:
		return false
	}
}
开发者ID:hongzhang2046,项目名称:codis,代码行数:17,代码来源:backend.go


示例4: handleRequestMSet

func (s *Session) handleRequestMSet(r *Request, d Dispatcher) (*Request, error) {
	nblks := len(r.Resp.Array) - 1
	if nblks <= 2 {
		return r, d.Dispatch(r)
	}
	if nblks%2 != 0 {
		r.Response.Resp = redis.NewError([]byte("ERR wrong number of arguments for MSET"))
		return r, nil
	}
	var sub = make([]*Request, nblks/2)
	for i := 0; i < len(sub); i++ {
		sub[i] = &Request{
			Owner: r.Owner,
			OpSeq: -r.OpSeq,
			OpStr: r.OpStr,
			Start: r.Start,
			Wait:  r.Wait,
			Resp: redis.NewArray([]*redis.Resp{
				r.Resp.Array[0],
				r.Resp.Array[i*2+1],
				r.Resp.Array[i*2+2],
			}),
		}
		if err := d.Dispatch(sub[i]); err != nil {
			return nil, err
		}
	}
	r.Coalesce = func() error {
		for _, x := range sub {
			if err := x.Response.Err; err != nil {
				return err
			}
			resp := x.Response.Resp
			if resp == nil {
				return ErrRespIsRequired
			}
			if !resp.IsString() {
				return errors.New(fmt.Sprintf("bad mset resp: %s value.len = %d", resp.Type, len(resp.Value)))
			}
			r.Response.Resp = resp
		}
		return nil
	}
	return r, nil
}
开发者ID:cbruce,项目名称:codis,代码行数:45,代码来源:session.go


示例5: handleRequestMDel

func (s *Session) handleRequestMDel(r *Request, d Dispatcher) (*Request, error) {
	nkeys := len(r.Resp.Array) - 1
	if nkeys <= 1 {
		return r, d.Dispatch(r)
	}
	var sub = make([]*Request, nkeys)
	for i := 0; i < len(sub); i++ {
		sub[i] = &Request{
			Owner: r.Owner,
			OpSeq: -r.OpSeq,
			OpStr: r.OpStr,
			Start: r.Start,
			Wait:  r.Wait,
			Resp: redis.NewArray([]*redis.Resp{
				r.Resp.Array[0],
				r.Resp.Array[i+1],
			}),
		}
		if err := d.Dispatch(sub[i]); err != nil {
			return nil, err
		}
	}
	r.Coalesce = func() error {
		var n int
		for _, x := range sub {
			if err := x.Response.Err; err != nil {
				return err
			}
			resp := x.Response.Resp
			if resp == nil {
				return ErrRespIsRequired
			}
			if !resp.IsInt() || len(resp.Value) != 1 {
				return errors.New(fmt.Sprintf("bad mdel resp: %s value.len = %d", resp.Type, len(resp.Value)))
			}
			if resp.Value[0] != '0' {
				n++
			}
		}
		r.Response.Resp = redis.NewInt([]byte(strconv.Itoa(n)))
		return nil
	}
	return r, nil
}
开发者ID:cbruce,项目名称:codis,代码行数:44,代码来源:session.go


示例6: TestGetOpStr

func TestGetOpStr(t *testing.T) {
	var m = map[string]string{
		"get":     "GET",
		"aBc":     "ABC",
		"おはよ":     "おはよ",
		"ni hao!": "NI HAO!",
		"":        "",
	}
	for k, v := range m {
		resp := redis.NewArray([]*redis.Resp{redis.NewBulkBytes([]byte(k))})
		s, err := getOpStr(resp)
		if v != "" {
			assert.MustNoError(err)
			assert.Must(s == v)
		} else {
			assert.Must(err != nil)
		}
	}
}
开发者ID:cougar731,项目名称:codis,代码行数:19,代码来源:mapper_test.go


示例7: slotsmgrt

func (s *Slot) slotsmgrt(r *Request, key []byte) error {
	if len(key) == 0 || s.migrate.bc == nil {
		return nil
	}
	m := &Request{
		Owner: r.Owner,
		Wait:  &sync.WaitGroup{},
		Resp: redis.NewArray([]*redis.Resp{
			redis.NewBulkBytes([]byte("SLOTSMGRTTAGONE")),
			redis.NewBulkBytes(s.backend.host),
			redis.NewBulkBytes(s.backend.port),
			redis.NewBulkBytes([]byte("3000")),
			redis.NewBulkBytes(key),
		}),
	}
	m.Wait.Add(1)

	s.migrate.bc.PushBack(m)

	m.Wait.Wait()

	resp, err := m.Response.Resp, m.Response.Err
	if err != nil {
		return err
	}
	if resp == nil {
		return ErrRespIsRequired
	}
	if resp.IsError() {
		return errors.New(fmt.Sprintf("error resp: %s", resp.Value))
	}
	if resp.IsInt() {
		log.Debugf("slot-%04d migrate from %s to %s: key = %s, resp = %s",
			s.Id, s.migrate.from, s.backend.addr, key, resp.Value)
		return nil
	} else {
		return errors.New(fmt.Sprintf("error resp: should be integer, but got %s", resp.Type))
	}
}
开发者ID:cookiebus,项目名称:codis,代码行数:39,代码来源:slots.go


示例8: TestGetOpStrCmd


//.........这里部分代码省略.........
		"restore":          "RESTORE",
		"sort":             "SORT",
		"ttl":              "TTL",
		"type":             "TYPE",
		"append":           "APPEND",
		"bitcount":         "BITCOUNT",
		"decr":             "DECR",
		"decrby":           "DECRBY",
		"get":              "GET",
		"getbit":           "GETBIT",
		"getrange":         "GETRANGE",
		"getset":           "GETSET",
		"incr":             "INCR",
		"incrby":           "INCRBY",
		"incrbyfloat":      "INCRBYFLOAT",
		"mget":             "MGET",
		"mset":             "MSET",
		"psetex":           "PSETEX",
		"set":              "SET",
		"setbit":           "SETBIT",
		"setex":            "SETEX",
		"setnx":            "SETNX",
		"setrange":         "SETRANGE",
		"strlen":           "STRLEN",
		"hdel":             "HDEL",
		"hexists":          "HEXISTS",
		"hget":             "HGET",
		"hgetall":          "HGETALL",
		"hincrby":          "HINCRBY",
		"hincrbyfloat":     "HINCRBYFLOAT",
		"hkeys":            "HKEYS",
		"hlen":             "HLEN",
		"hmget":            "HMGET",
		"hmset":            "HMSET",
		"hset":             "HSET",
		"hsetnx":           "HSETNX",
		"hvals":            "HVALS",
		"hscan":            "HSCAN",
		"lindex":           "LINDEX",
		"linsert":          "LINSERT",
		"llen":             "LLEN",
		"lpop":             "LPOP",
		"lpush":            "LPUSH",
		"lpushx":           "LPUSHX",
		"lrange":           "LRANGE",
		"lrem":             "LREM",
		"lset":             "LSET",
		"ltrim":            "LTRIM",
		"rpop":             "RPOP",
		"rpoplpush":        "RPOPLPUSH",
		"rpush":            "RPUSH",
		"rpushx":           "RPUSHX",
		"sadd":             "SADD",
		"scard":            "SCARD",
		"sdiff":            "SDIFF",
		"sdiffstore":       "SDIFFSTORE",
		"sinter":           "SINTER",
		"sinterstore":      "SINTERSTORE",
		"sismember":        "SISMEMBER",
		"smembers":         "SMEMBERS",
		"smove":            "SMOVE",
		"spop":             "SPOP",
		"srandmember":      "SRANDMEMBER",
		"srem":             "SREM",
		"sunion":           "SUNION",
		"sunionstore":      "SUNIONSTORE",
		"sscan":            "SSCAN",
		"zadd":             "ZADD",
		"zcard":            "ZCARD",
		"zcount":           "ZCOUNT",
		"zincrby":          "ZINCRBY",
		"zinterstore":      "ZINTERSTORE",
		"zlexcount":        "ZLEXCOUNT",
		"zrange":           "ZRANGE",
		"zrangebylex":      "ZRANGEBYLEX",
		"zrangebyscore":    "ZRANGEBYSCORE",
		"zrank":            "ZRANK",
		"zrem":             "ZREM",
		"zremrangebylex":   "ZREMRANGEBYLEX",
		"zremrangebyrank":  "ZREMRANGEBYRANK",
		"zremrangebyscore": "ZREMRANGEBYSCORE",
		"zrevrange":        "ZREVRANGE",
		"zrevrangebyscore": "ZREVRANGEBYSCORE",
		"zrevrank":         "ZREVRANK",
		"zscore":           "ZSCORE",
		"zunionstore":      "ZUNIONSTORE",
		"zscan":            "ZSCAN",
		"pfadd":            "PFADD",
		"pfcount":          "PFCOUNT",
		"pfmerge":          "PFMERGE",
		"eval":             "EVAL",
		"evalsha":          "EVALSHA",
	}
	for k, v := range m {
		resp := redis.NewArray([]*redis.Resp{redis.NewBulkBytes([]byte(k))})
		s, err := getOpStr(resp)
		assert.MustNoError(err)
		assert.Must(s == v)
	}
}
开发者ID:cougar731,项目名称:codis,代码行数:101,代码来源:mapper_test.go



注:本文中的github.com/wandoulabs/codis/pkg/proxy/redis.NewArray函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang redis.NewError函数代码示例发布时间:2022-05-28
下一篇:
Golang models.SetProxyStatus函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap