Skip to content

Commit

Permalink
add support for multiple redis list types
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyamor committed Aug 19, 2020
1 parent 3fcf463 commit 9ac5d3e
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion pkg/scalers/redis_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,30 @@ func getRedisListLength(ctx context.Context, address string, password string, li
}

client := redis.NewClient(options)
var listType *redis.StatusCmd

cmd := client.LLen(listName)
listType = client.Type(listName)
if listType.Err() != nil {
return -1, listType.Err()
}

var cmd *redis.IntCmd
switch listType.Val() {
case "list":
cmd = client.LLen(listName)
case "set":
cmd = client.SCard(listName)
case "hash":
cmd = client.HLen(listName)
case "zset":
cmd = client.ZCard(listName)
default:
cmd = nil
}

if cmd == nil {
return -1, fmt.Errorf("list must be of type:list,set,hash,zset but was %s", listType.Val())
}
if cmd.Err() != nil {
return -1, cmd.Err()
}
Expand Down

0 comments on commit 9ac5d3e

Please sign in to comment.