mirror of
https://github.com/redis/go-redis.git
synced 2025-07-28 06:42:00 +03:00
Adding support for ZMPOP command (#2408)
* feat: add ZMPOP command * fix: reply reading string * fix: evaluating a test tweak * fix: test fix * fix: reverting to debug * fix: test fix * fix: remove old implementation * feat: adding ZMPOP and tests * feat: modifying ZMpopCmd * fix: fix test * fix: test removal check * fix: fix testS * Adding more tests * fix: using redis.Nil instead of string * fix: renaming command to ZArrayWithKeyCmd to match the standard * feat: updated ZArrayWithKeyCmd to ZSliceWithKeyCmd * feat: adding help strings --------- Co-authored-by: Anuragkillswitch <70265851+Anuragkillswitch@users.noreply.github.com> Co-authored-by: Chayim <chayim@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
f95bdb8a8b
commit
621c02c583
83
command.go
83
command.go
@ -3752,3 +3752,86 @@ func (cmd *KeyValuesCmd) readReply(rd *proto.Reader) (err error) {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
type ZSliceWithKeyCmd struct {
|
||||
baseCmd
|
||||
|
||||
key string
|
||||
val []Z
|
||||
}
|
||||
|
||||
var _ Cmder = (*ZSliceWithKeyCmd)(nil)
|
||||
|
||||
func NewZSliceWithKeyCmd(ctx context.Context, args ...interface{}) *ZSliceWithKeyCmd {
|
||||
return &ZSliceWithKeyCmd{
|
||||
baseCmd: baseCmd{
|
||||
ctx: ctx,
|
||||
args: args,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (cmd *ZSliceWithKeyCmd) SetVal(key string, val []Z) {
|
||||
cmd.key = key
|
||||
cmd.val = val
|
||||
}
|
||||
|
||||
func (cmd *ZSliceWithKeyCmd) Val() (string, []Z) {
|
||||
return cmd.key, cmd.val
|
||||
}
|
||||
|
||||
func (cmd *ZSliceWithKeyCmd) Result() (string, []Z, error) {
|
||||
return cmd.key, cmd.val, cmd.err
|
||||
}
|
||||
|
||||
func (cmd *ZSliceWithKeyCmd) String() string {
|
||||
return cmdString(cmd, cmd.val)
|
||||
}
|
||||
|
||||
func (cmd *ZSliceWithKeyCmd) readReply(rd *proto.Reader) (err error) {
|
||||
if err = rd.ReadFixedArrayLen(2); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cmd.key, err = rd.ReadString()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
n, err := rd.ReadArrayLen()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
typ, err := rd.PeekReplyType()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
array := typ == proto.RespArray
|
||||
|
||||
if array {
|
||||
cmd.val = make([]Z, n)
|
||||
} else {
|
||||
cmd.val = make([]Z, n/2)
|
||||
}
|
||||
|
||||
for i := 0; i < len(cmd.val); i++ {
|
||||
if array {
|
||||
if err = rd.ReadFixedArrayLen(2); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if cmd.val[i].Member, err = rd.ReadString(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if cmd.val[i].Score, err = rd.ReadFloat(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user