Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v2] add support for multiple redis list types in redis list scaler #1013

Merged
merged 2 commits into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
- Add consumer offset reset policy option to Kafka scaler ([#925](https://github.com/kedacore/keda/pull/925))
- Add option to restore to original replica count after ScaledObject's deletion ([#219](https://github.com/kedacore/keda-docs/pull/219))
- Add Prometheus metrics for KEDA Metrics API Server ([#823](https://github.com/kedacore/keda/issues/823) | [docs](https://keda.sh/docs/2.0/operate/#prometheus-exporter-metrics))

- add support for multiple redis list types in redis list scaler ([#1006](https://github.com/kedacore/keda/pull/1006)) | [docs](https://keda.sh/docs/2.0/scalers/redis-lists/))
### Improvements

- HPA: move from autoscaling v2beta1 to v2beta2 ([#721](https://github.com/kedacore/keda/issues/721))
Expand Down
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