示例#1
0
func bsetbitCommand(req *requestContext) error {
	args := req.args
	if len(args) != 3 {
		return ErrCmdParams
	}

	var err error
	var offset int32
	var val int8

	offset, err = ledis.StrInt32(args[1], nil)

	if err != nil {
		return ErrOffset
	}

	val, err = ledis.StrInt8(args[2], nil)
	if val != 0 && val != 1 {
		return ErrBool
	}

	if err != nil {
		return ErrBool
	}

	if ori, err := req.db.BSetBit(args[0], offset, uint8(val)); err != nil {
		return err
	} else {
		req.resp.writeInteger(int64(ori))
	}
	return nil
}
示例#2
0
func bsetbitCommand(c *client) error {
	args := c.args
	if len(args) != 3 {
		return ErrCmdParams
	}

	var err error
	var offset int32
	var val int8

	offset, err = ledis.StrInt32(args[1], nil)
	if err != nil {
		return err
	}

	val, err = ledis.StrInt8(args[2], nil)
	if err != nil {
		return err
	}

	if ori, err := c.db.BSetBit(args[0], offset, uint8(val)); err != nil {
		return err
	} else {
		c.writeInteger(int64(ori))
	}
	return nil
}
示例#3
0
func bmsetbitCommand(req *requestContext) error {
	args := req.args
	if len(args) < 3 {
		return ErrCmdParams
	}

	key := args[0]
	if len(args[1:])&1 != 0 {
		return ErrCmdParams
	} else {
		args = args[1:]
	}

	var err error
	var offset int32
	var val int8

	pairs := make([]ledis.BitPair, len(args)>>1)
	for i := 0; i < len(pairs); i++ {
		offset, err = ledis.StrInt32(args[i<<1], nil)

		if err != nil {
			return ErrOffset
		}

		val, err = ledis.StrInt8(args[i<<1+1], nil)
		if val != 0 && val != 1 {
			return ErrBool
		}

		if err != nil {
			return ErrBool
		}

		pairs[i].Pos = offset
		pairs[i].Val = uint8(val)
	}

	if place, err := req.db.BMSetBit(key, pairs...); err != nil {
		return err
	} else {
		req.resp.writeInteger(place)
	}
	return nil
}