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


Golang redis.NewString函數代碼示例

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


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

示例1: handlePing

func (s *Session) handlePing(r *Request) (*Request, error) {
	if len(r.Resp.Array) != 1 {
		r.Response.Resp = redis.NewError([]byte("ERR wrong number of arguments for 'PING' command"))
		return r, nil
	}
	r.Response.Resp = redis.NewString([]byte("PONG"))
	return r, nil
}
開發者ID:njucslqq,項目名稱:codis,代碼行數:8,代碼來源:session.go

示例2: handleSelect

func (s *Session) handleSelect(r *Request) (*Request, error) {
	if len(r.Resp.Array) != 2 {
		r.Response.Resp = redis.NewError([]byte("ERR wrong number of arguments for 'SELECT' command"))
		return r, nil
	}
	if db, err := strconv.Atoi(string(r.Resp.Array[1].Value)); err != nil {
		r.Response.Resp = redis.NewError([]byte("ERR invalid DB index"))
		return r, nil
	} else if db != 0 {
		r.Response.Resp = redis.NewError([]byte("ERR invalid DB index, only accept DB 0"))
		return r, nil
	} else {
		r.Response.Resp = redis.NewString([]byte("OK"))
		return r, nil
	}
}
開發者ID:njucslqq,項目名稱:codis,代碼行數:16,代碼來源:session.go

示例3: TestBackend

func TestBackend(t *testing.T) {
	l, err := net.Listen("tcp", "127.0.0.1:0")
	assert.MustNoError(err)
	defer l.Close()

	addr := l.Addr().String()
	reqc := make(chan *Request, 16384)
	go func() {
		bc := NewBackendConn(addr)
		defer bc.Close()
		defer close(reqc)
		var resp = redis.NewBulkBytes(make([]byte, 4096))
		for i := 0; i < cap(reqc); i++ {
			r := &Request{
				Resp: resp,
				Wait: &sync.WaitGroup{},
			}
			r.Wait.Add(1)
			bc.PushBack(r)
			reqc <- r
		}
	}()

	go func() {
		c, err := l.Accept()
		assert.MustNoError(err)
		defer c.Close()
		conn := redis.NewConn(c)
		time.Sleep(time.Millisecond * 300)
		for i := 0; i < cap(reqc); i++ {
			_, err := conn.Reader.Decode()
			assert.MustNoError(err)
			resp := redis.NewString([]byte(strconv.Itoa(i)))
			assert.MustNoError(conn.Writer.Encode(resp, true))
		}
	}()

	var n int
	for r := range reqc {
		r.Wait.Wait()
		assert.Must(string(r.Response.Resp.Value) == strconv.Itoa(n))
		n++
	}
	assert.Must(n == cap(reqc))
}
開發者ID:cookiebus,項目名稱:codis,代碼行數:45,代碼來源:backend_test.go

示例4: handleAuth

func (s *Session) handleAuth(r *Request) (*Request, error) {
	if len(r.Resp.Array) != 2 {
		r.Response.Resp = redis.NewError([]byte("ERR wrong number of arguments for 'AUTH' command"))
		return r, nil
	}
	if s.auth == "" {
		r.Response.Resp = redis.NewError([]byte("ERR Client sent AUTH, but no password is set"))
		return r, nil
	}
	if s.auth != string(r.Resp.Array[1].Value) {
		s.authorized = false
		r.Response.Resp = redis.NewError([]byte("ERR invalid password"))
		return r, nil
	} else {
		s.authorized = true
		r.Response.Resp = redis.NewString([]byte("OK"))
		return r, nil
	}
}
開發者ID:njucslqq,項目名稱:codis,代碼行數:19,代碼來源:session.go

示例5: handleRequest

func (s *Session) handleRequest(resp *redis.Resp, d Dispatcher) (*Request, error) {
	opstr, err := getOpStr(resp)
	if err != nil {
		return nil, err
	}
	if isNotAllowed(opstr) {
		return nil, errors.New(fmt.Sprintf("command <%s> is not allowed", opstr))
	}

	usnow := microseconds()
	s.LastOpUnix.Set(usnow / 1e6)

	r := &Request{
		Owner: s,
		OpSeq: s.Ops.Incr(),
		OpStr: opstr,
		Start: usnow,
		Wait:  &sync.WaitGroup{},
		Resp:  resp,
	}

	switch opstr {
	case "QUIT":
		s.quit = true
		fallthrough
	case "AUTH", "SELECT":
		r.Response.Resp = redis.NewString([]byte("OK"))
		return r, nil
	case "MGET":
		return s.handleRequestMGet(r, d)
	case "MSET":
		return s.handleRequestMSet(r, d)
	case "DEL":
		return s.handleRequestMDel(r, d)
	}
	return r, d.Dispatch(r)
}
開發者ID:cbruce,項目名稱:codis,代碼行數:37,代碼來源:session.go

示例6: handleQuit

func (s *Session) handleQuit(r *Request) (*Request, error) {
	s.quit = true
	r.Response.Resp = redis.NewString([]byte("OK"))
	return r, nil
}
開發者ID:njucslqq,項目名稱:codis,代碼行數:5,代碼來源:session.go

示例7: handlePing

func (s *Session) handlePing(r *Request) (*Request, error) {
	r.Response.Resp = redis.NewString([]byte("PONG"))
	return r, nil
}
開發者ID:hongzhang2046,項目名稱:codis,代碼行數:4,代碼來源:session.go


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