当前位置: 首页>>代码示例>>Golang>>正文


Golang ledis.String函数代码示例

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


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

示例1: slaveofCommand

func slaveofCommand(req *requestContext) error {
	args := req.args

	if len(args) != 2 {
		return ErrCmdParams
	}

	masterAddr := ""

	if strings.ToLower(ledis.String(args[0])) == "no" &&
		strings.ToLower(ledis.String(args[1])) == "one" {
		//stop replication, use master = ""
	} else {
		if _, err := strconv.ParseInt(ledis.String(args[1]), 10, 16); err != nil {
			return err
		}

		masterAddr = fmt.Sprintf("%s:%s", args[0], args[1])
	}

	if err := req.app.slaveof(masterAddr); err != nil {
		return err
	}

	req.resp.writeStatus(OK)

	return nil
}
开发者ID:JREAMLU,项目名称:ledisdb,代码行数:28,代码来源:cmd_replication.go

示例2: writeFVPairArray

func (w *httpWriter) writeFVPairArray(lst []ledis.FVPair) {
	m := make(map[string]string)
	for _, elem := range lst {
		m[ledis.String(elem.Field)] = ledis.String(elem.Value)
	}
	w.genericWrite(m)
}
开发者ID:huanshi,项目名称:ledisdb,代码行数:7,代码来源:client_http.go

示例3: zrangebyscoreGeneric

func zrangebyscoreGeneric(c *client, reverse bool) error {
	args := c.args
	if len(args) < 3 {
		return ErrCmdParams
	}

	key := args[0]
	min, max, err := zparseScoreRange(args[1], args[2])
	if err != nil {
		return err
	}

	args = args[3:]

	var withScores bool = false

	if len(args) > 0 && strings.ToLower(ledis.String(args[0])) == "withscores" {
		withScores = true
		args = args[1:]
	}

	var offset int = 0
	var count int = -1

	if len(args) > 0 {
		if len(args) != 3 {
			return ErrCmdParams
		}

		if strings.ToLower(ledis.String(args[0])) != "limit" {
			return ErrCmdParams
		}

		if offset, err = strconv.Atoi(ledis.String(args[1])); err != nil {
			return ErrCmdParams
		}

		if count, err = strconv.Atoi(ledis.String(args[2])); err != nil {
			return ErrCmdParams
		}
	}

	if offset < 0 {
		//for redis, if offset < 0, a empty will return
		//so here we directly return a empty array
		c.writeArray([]interface{}{})
		return nil
	}

	if v, err := c.db.ZRangeByScoreGeneric(key, min, max, withScores, offset, count, reverse); err != nil {
		return err
	} else {
		c.writeArray(v)
	}

	return nil
}
开发者ID:rchunping,项目名称:ledisdb,代码行数:57,代码来源:cmd_zset.go

示例4: zparseRange

func zparseRange(c *client, a1 []byte, a2 []byte) (start int, stop int, err error) {
	if start, err = strconv.Atoi(ledis.String(a1)); err != nil {
		return
	}

	if stop, err = strconv.Atoi(ledis.String(a2)); err != nil {
		return
	}

	return
}
开发者ID:Gohan,项目名称:ledisdb,代码行数:11,代码来源:cmd_zset.go

示例5: readRequest

//A client sends to the Redis server a RESP Array consisting of just Bulk Strings.
func (c *respClient) readRequest() ([][]byte, error) {
	l, err := c.readLine()
	if err != nil {
		return nil, err
	} else if len(l) == 0 || l[0] != '*' {
		return nil, errReadRequest
	}

	var nparams int
	if nparams, err = strconv.Atoi(ledis.String(l[1:])); err != nil {
		return nil, err
	} else if nparams <= 0 {
		return nil, errReadRequest
	}

	req := make([][]byte, 0, nparams)
	var n int
	for i := 0; i < nparams; i++ {
		if l, err = c.readLine(); err != nil {
			return nil, err
		}

		if len(l) == 0 {
			return nil, errReadRequest
		} else if l[0] == '$' {
			//handle resp string
			if n, err = strconv.Atoi(ledis.String(l[1:])); err != nil {
				return nil, err
			} else if n == -1 {
				req = append(req, nil)
			} else {
				buf := make([]byte, n)
				if _, err = io.ReadFull(c.rb, buf); err != nil {
					return nil, err
				}

				if l, err = c.readLine(); err != nil {
					return nil, err
				} else if len(l) != 0 {
					return nil, errors.New("bad bulk string format")
				}

				req = append(req, buf)

			}

		} else {
			return nil, errReadRequest
		}
	}

	return req, nil
}
开发者ID:Abioy,项目名称:ledisdb,代码行数:54,代码来源:client_resp.go

示例6: writeFVPairArray

func (w *luaWriter) writeFVPairArray(lst []ledis.FVPair) {
	if lst == nil {
		w.l.PushBoolean(false)
		return
	}

	w.l.CreateTable(len(lst)*2, 0)
	for i, v := range lst {
		w.l.PushString(ledis.String(v.Field))
		w.l.RawSeti(-2, 2*i+1)

		w.l.PushString(ledis.String(v.Value))
		w.l.RawSeti(-2, 2*i+2)
	}
}
开发者ID:Abioy,项目名称:ledisdb,代码行数:15,代码来源:script.go

示例7: zrangeGeneric

func zrangeGeneric(req *requestContext, reverse bool) error {
	args := req.args
	if len(args) < 3 {
		return ErrCmdParams
	}

	key := args[0]

	start, stop, err := zparseRange(req, args[1], args[2])
	if err != nil {
		return ErrValue
	}

	args = args[3:]
	var withScores bool = false

	if len(args) > 0 {
		if len(args) != 1 {
			return ErrCmdParams
		}
		if strings.ToLower(ledis.String(args[0])) == "withscores" {
			withScores = true
		} else {
			return ErrSyntax
		}
	}

	if datas, err := req.db.ZRangeGeneric(key, start, stop, reverse); err != nil {
		return err
	} else {
		req.resp.writeScorePairArray(datas, withScores)
	}
	return nil
}
开发者ID:JREAMLU,项目名称:ledisdb,代码行数:34,代码来源:cmd_zset.go

示例8: handleRequest

func (c *respClient) handleRequest(reqData [][]byte) {
	req := c.req

	if len(reqData) == 0 {
		c.req.cmd = ""
		c.req.args = reqData[0:0]
	} else {
		c.req.cmd = strings.ToLower(ledis.String(reqData[0]))
		c.req.args = reqData[1:]
	}
	if c.req.cmd == "quit" {
		c.req.resp.writeStatus(OK)
		c.req.resp.flush()
		c.conn.Close()
		return
	}

	req.db = c.db

	c.req.perform()

	c.db = req.db // "SELECT"

	return
}
开发者ID:JREAMLU,项目名称:ledisdb,代码行数:25,代码来源:client_resp.go

示例9: scriptCommand

func scriptCommand(c *client) error {
	s := c.app.s
	l := s.l

	s.Lock()

	base := l.GetTop()

	defer func() {
		l.SetTop(base)
		s.Unlock()
	}()

	args := c.args

	if len(args) < 1 {
		return ErrCmdParams
	}

	switch strings.ToLower(ledis.String(args[0])) {
	case "load":
		return scriptLoadCommand(c)
	case "exists":
		return scriptExistsCommand(c)
	case "flush":
		return scriptFlushCommand(c)
	default:
		return fmt.Errorf("invalid script %s", args[0])
	}

	return nil
}
开发者ID:Abioy,项目名称:ledisdb,代码行数:32,代码来源:cmd_script.go

示例10: ReadBulkTo

func ReadBulkTo(rb *bufio.Reader, w io.Writer) error {
	l, err := ReadLine(rb)
	if len(l) == 0 {
		return errBulkFormat
	} else if l[0] == '$' {
		var n int
		//handle resp string
		if n, err = strconv.Atoi(ledis.String(l[1:])); err != nil {
			return err
		} else if n == -1 {
			return nil
		} else {
			if _, err = io.CopyN(w, rb, int64(n)); err != nil {
				return err
			}

			if l, err = ReadLine(rb); err != nil {
				return err
			} else if len(l) != 0 {
				return errBulkFormat
			}
		}
	} else {
		return errBulkFormat
	}

	return nil
}
开发者ID:Eddie0330,项目名称:ledisdb,代码行数:28,代码来源:util.go

示例11: boptCommand

func boptCommand(req *requestContext) error {
	args := req.args
	if len(args) < 2 {
		return ErrCmdParams
	}

	opDesc := strings.ToLower(ledis.String(args[0]))
	dstKey := args[1]
	srcKeys := args[2:]

	var op uint8
	switch opDesc {
	case "and":
		op = ledis.OPand
	case "or":
		op = ledis.OPor
	case "xor":
		op = ledis.OPxor
	case "not":
		op = ledis.OPnot
	default:
		return ErrCmdParams
	}

	if len(srcKeys) == 0 {
		return ErrCmdParams
	}
	if blen, err := req.db.BOperation(op, dstKey, srcKeys...); err != nil {
		return err
	} else {
		req.resp.writeInteger(int64(blen))
	}
	return nil
}
开发者ID:JREAMLU,项目名称:ledisdb,代码行数:34,代码来源:cmd_bit.go

示例12: selectCommand

func selectCommand(c *client) error {
	if len(c.args) != 1 {
		return ErrCmdParams
	}

	if index, err := strconv.Atoi(ledis.String(c.args[0])); err != nil {
		return err
	} else {
		if c.db.IsTransaction() {
			if err := c.tx.Select(index); err != nil {
				return err
			} else {
				c.db = c.tx.DB
			}
		} else if c.db.IsInMulti() {
			if err := c.script.Select(index); err != nil {
				return err
			} else {
				c.db = c.script.DB
			}
		} else {
			if db, err := c.ldb.Select(index); err != nil {
				return err
			} else {
				c.db = db
			}
		}
		c.resp.writeStatus(OK)
	}

	return nil
}
开发者ID:Abioy,项目名称:ledisdb,代码行数:32,代码来源:command.go

示例13: writeBulk

func (w *luaWriter) writeBulk(b []byte) {
	if b == nil {
		w.l.PushBoolean(false)
	} else {
		w.l.PushString(ledis.String(b))
	}
}
开发者ID:Abioy,项目名称:ledisdb,代码行数:7,代码来源:script.go

示例14: scriptLoadCommand

func scriptLoadCommand(c *client) error {
	s := c.app.s
	l := s.l

	if len(c.args) != 2 {
		return ErrCmdParams
	}

	h := sha1.Sum(c.args[1])
	key := hex.EncodeToString(h[0:20])

	if r := l.LoadString(ledis.String(c.args[1])); r != 0 {
		err := fmt.Errorf("%s", l.ToString(-1))
		l.Pop(1)
		return err
	} else {
		l.PushValue(-1)
		l.SetGlobal(key)

		s.chunks[key] = struct{}{}
	}

	c.resp.writeBulk(ledis.Slice(key))
	return nil
}
开发者ID:Abioy,项目名称:ledisdb,代码行数:25,代码来源:cmd_script.go

示例15: writeScorePairArray

func (w *httpWriter) writeScorePairArray(lst []ledis.ScorePair, withScores bool) {
	var arr []string
	if withScores {
		arr = make([]string, 2*len(lst))
		for i, data := range lst {
			arr[2*i] = ledis.String(data.Member)
			arr[2*i+1] = strconv.FormatInt(data.Score, 10)
		}
	} else {
		arr = make([]string, len(lst))
		for i, data := range lst {
			arr[i] = ledis.String(data.Member)
		}
	}
	w.genericWrite(arr)
}
开发者ID:huanshi,项目名称:ledisdb,代码行数:16,代码来源:client_http.go


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