Beispiel #1
0
func zscoreCommand(req *requestContext) error {
	args := req.args
	if len(args) != 2 {
		return ErrCmdParams
	}

	if s, err := req.db.ZScore(args[0], args[1]); err != nil {
		if err == ledis.ErrScoreMiss {
			req.resp.writeBulk(nil)
		} else {
			return err
		}
	} else {
		req.resp.writeBulk(ledis.StrPutInt64(s))
	}

	return nil
}
Beispiel #2
0
func zscoreCommand(c *client) error {
	args := c.args
	if len(args) != 2 {
		return ErrCmdParams
	}

	if s, err := c.db.ZScore(args[0], args[1]); err != nil {
		if err == ledis.ErrScoreMiss {
			c.writeBulk(nil)
		} else {
			return err
		}
	} else {
		c.writeBulk(ledis.StrPutInt64(s))
	}

	return nil
}
Beispiel #3
0
func zincrbyCommand(c *client) error {
	args := c.args
	if len(args) != 3 {
		return ErrCmdParams
	}

	key := args[0]

	delta, err := ledis.StrInt64(args[1], nil)
	if err != nil {
		return err
	}

	if v, err := c.db.ZIncrBy(key, delta, args[2]); err != nil {
		return err
	} else {
		c.writeBulk(ledis.StrPutInt64(v))
	}

	return nil
}
Beispiel #4
0
func zincrbyCommand(req *requestContext) error {
	args := req.args
	if len(args) != 3 {
		return ErrCmdParams
	}

	key := args[0]

	delta, err := ledis.StrInt64(args[1], nil)
	if err != nil {
		return ErrValue
	}

	if v, err := req.db.ZIncrBy(key, delta, args[2]); err != nil {
		return err
	} else {
		req.resp.writeBulk(ledis.StrPutInt64(v))
	}

	return nil
}
Beispiel #5
0
func (w *luaWriter) writeScorePairArray(lst []ledis.ScorePair, withScores bool) {
	if lst == nil {
		w.l.PushBoolean(false)
		return
	}

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

			w.l.PushString(ledis.String(ledis.StrPutInt64(v.Score)))
			w.l.RawSeti(-2, 2*i+2)
		}
	} else {
		w.l.CreateTable(len(lst), 0)
		for i, v := range lst {
			w.l.PushString(ledis.String(v.Member))
			w.l.RawSeti(-2, i+1)
		}
	}
}
Beispiel #6
0
func (w *respWriter) writeScorePairArray(lst []ledis.ScorePair, withScores bool) {
	w.buff.WriteByte('*')
	if lst == nil {
		w.buff.Write(NullArray)
		w.buff.Write(Delims)
	} else {
		if withScores {
			w.buff.Write(ledis.Slice(strconv.Itoa(len(lst) * 2)))
			w.buff.Write(Delims)
		} else {
			w.buff.Write(ledis.Slice(strconv.Itoa(len(lst))))
			w.buff.Write(Delims)

		}

		for i := 0; i < len(lst); i++ {
			w.writeBulk(lst[i].Member)

			if withScores {
				w.writeBulk(ledis.StrPutInt64(lst[i].Score))
			}
		}
	}
}
Beispiel #7
0
func (c *client) writeScorePairArray(ay []ledis.ScorePair, withScores bool) {
	c.wb.WriteByte('*')
	if ay == nil {
		c.wb.Write(NullArray)
		c.wb.Write(Delims)
	} else {
		if withScores {
			c.wb.Write(ledis.Slice(strconv.Itoa(len(ay) * 2)))
			c.wb.Write(Delims)
		} else {
			c.wb.Write(ledis.Slice(strconv.Itoa(len(ay))))
			c.wb.Write(Delims)

		}

		for i := 0; i < len(ay); i++ {
			c.writeBulk(ay[i].Member)

			if withScores {
				c.writeBulk(ledis.StrPutInt64(ay[i].Score))
			}
		}
	}
}
Beispiel #8
0
func (w *respWriter) writeInteger(n int64) {
	w.buff.WriteByte(':')
	w.buff.Write(ledis.StrPutInt64(n))
	w.buff.Write(Delims)
}
Beispiel #9
0
func (c *client) writeInteger(n int64) {
	c.wb.WriteByte(':')
	c.wb.Write(ledis.StrPutInt64(n))
	c.wb.Write(Delims)
}