1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-28 06:42:00 +03:00

Pass pointers where it makes sense

This commit is contained in:
Vladimir Mihailenco
2019-05-16 16:27:19 +03:00
parent 458982a440
commit 685d8922de
4 changed files with 217 additions and 223 deletions

View File

@ -1220,7 +1220,7 @@ func xPendingParser(rd *proto.Reader, n int64) (interface{}, error) {
//------------------------------------------------------------------------------
type XPendingExt struct {
Id string
ID string
Consumer string
Idle time.Duration
RetryCount int64
@ -1290,7 +1290,7 @@ func xPendingExtSliceParser(rd *proto.Reader, n int64) (interface{}, error) {
}
ret = append(ret, XPendingExt{
Id: id,
ID: id,
Consumer: consumer,
Idle: time.Duration(idle) * time.Millisecond,
RetryCount: retryCount,
@ -1370,7 +1370,7 @@ func zSliceParser(rd *proto.Reader, n int64) (interface{}, error) {
type ZWithKeyCmd struct {
baseCmd
val ZWithKey
val *ZWithKey
}
var _ Cmder = (*ZWithKeyCmd)(nil)
@ -1381,11 +1381,11 @@ func NewZWithKeyCmd(args ...interface{}) *ZWithKeyCmd {
}
}
func (cmd *ZWithKeyCmd) Val() ZWithKey {
func (cmd *ZWithKeyCmd) Val() *ZWithKey {
return cmd.val
}
func (cmd *ZWithKeyCmd) Result() (ZWithKey, error) {
func (cmd *ZWithKeyCmd) Result() (*ZWithKey, error) {
return cmd.Val(), cmd.Err()
}
@ -1399,7 +1399,7 @@ func (cmd *ZWithKeyCmd) readReply(rd *proto.Reader) error {
if cmd.err != nil {
return cmd.err
}
cmd.val = v.(ZWithKey)
cmd.val = v.(*ZWithKey)
return nil
}
@ -1424,7 +1424,8 @@ func zWithKeyParser(rd *proto.Reader, n int64) (interface{}, error) {
if err != nil {
return nil, err
}
return z, nil
return &z, nil
}
//------------------------------------------------------------------------------
@ -1787,7 +1788,23 @@ func (cmd *GeoPosCmd) readReply(rd *proto.Reader) error {
func geoPosSliceParser(rd *proto.Reader, n int64) (interface{}, error) {
positions := make([]*GeoPos, 0, n)
for i := int64(0); i < n; i++ {
v, err := rd.ReadReply(geoPosParser)
_, err := rd.ReadReply(func(rd *proto.Reader, n int64) (interface{}, error) {
var pos GeoPos
var err error
pos.Longitude, err = rd.ReadFloatReply()
if err != nil {
return nil, err
}
pos.Latitude, err = rd.ReadFloatReply()
if err != nil {
return nil, err
}
positions = append(positions, &pos)
return nil, nil
})
if err != nil {
if err == Nil {
positions = append(positions, nil)
@ -1795,33 +1812,10 @@ func geoPosSliceParser(rd *proto.Reader, n int64) (interface{}, error) {
}
return nil, err
}
switch v := v.(type) {
case *GeoPos:
positions = append(positions, v)
default:
return nil, fmt.Errorf("got %T, expected *GeoPos", v)
}
}
return positions, nil
}
func geoPosParser(rd *proto.Reader, n int64) (interface{}, error) {
var pos GeoPos
var err error
pos.Longitude, err = rd.ReadFloatReply()
if err != nil {
return nil, err
}
pos.Latitude, err = rd.ReadFloatReply()
if err != nil {
return nil, err
}
return &pos, nil
}
//------------------------------------------------------------------------------
type CommandInfo struct {