Skip to content

Commit 8091aba

Browse files
committed
replace redundant slice initialization with shorthand declaration
1 parent 847e60b commit 8091aba

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

core/src/plugins/redis/redis.go

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
// Copyright 2025 Clidey, Inc.
2-
//
3-
// Licensed under the Apache License, Version 2.0 (the "License");
4-
// you may not use this file except in compliance with the License.
5-
// You may obtain a copy of the License at
6-
//
7-
// http://www.apache.org/licenses/LICENSE-2.0
8-
//
9-
// Unless required by applicable law or agreed to in writing, software
10-
// distributed under the License is distributed on an "AS IS" BASIS,
11-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
// See the License for the specific language governing permissions and
13-
// limitations under the License.
1+
/*
2+
* Copyright 2025 Clidey, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
1416

1517
package redis
1618

@@ -43,7 +45,7 @@ func (p *RedisPlugin) IsAvailable(config *engine.PluginConfig) bool {
4345

4446
func (p *RedisPlugin) GetDatabases(config *engine.PluginConfig) ([]string, error) {
4547
maxDatabases := 16
46-
availableDatabases := []string{}
48+
var availableDatabases []string
4749

4850
for i := 0; i < maxDatabases; i++ {
4951
dbConfig := *config
@@ -77,20 +79,19 @@ func (p *RedisPlugin) GetStorageUnits(config *engine.PluginConfig, schema string
7779
}
7880
defer client.Close()
7981

80-
// Use SCAN instead of KEYS for better performance
8182
var keys []string
8283
var cursor uint64
83-
84+
8485
for {
8586
var scanKeys []string
86-
scanKeys, cursor, err = client.Scan(ctx, cursor, "*", 0).Result()
87+
scanKeys, cursor, err = client.Scan(ctx, cursor, "*", 0).Result() // count = 0 will use the redis default of 10
8788
if err != nil {
8889
log.Logger.WithError(err).Error("Failed to scan Redis keys")
8990
return nil, err
9091
}
91-
92+
9293
keys = append(keys, scanKeys...)
93-
94+
9495
// When cursor is 0, we've completed the full scan
9596
if cursor == 0 {
9697
break
@@ -251,7 +252,7 @@ func (p *RedisPlugin) GetRows(
251252
log.Logger.WithError(err).WithField("storageUnit", storageUnit).Error("Failed to get Redis hash values")
252253
return nil, err
253254
}
254-
rows := [][]string{}
255+
var rows [][]string
255256
for field, value := range hashValues {
256257
if where == nil || filterRedisHash(field, value, where) {
257258
rows = append(rows, []string{field, value})
@@ -271,7 +272,7 @@ func (p *RedisPlugin) GetRows(
271272
log.Logger.WithError(err).WithField("storageUnit", storageUnit).Error("Failed to get Redis list values")
272273
return nil, err
273274
}
274-
rows := [][]string{}
275+
var rows [][]string
275276
for i, value := range listValues {
276277
if where == nil || filterRedisList(value, where) {
277278
rows = append(rows, []string{strconv.Itoa(i), value})
@@ -287,7 +288,7 @@ func (p *RedisPlugin) GetRows(
287288
log.Logger.WithError(err).WithField("storageUnit", storageUnit).Error("Failed to get Redis set values")
288289
return nil, err
289290
}
290-
rows := [][]string{}
291+
var rows [][]string
291292
for i, value := range setValues {
292293
rows = append(rows, []string{strconv.Itoa(i), value})
293294
}
@@ -302,7 +303,7 @@ func (p *RedisPlugin) GetRows(
302303
log.Logger.WithError(err).WithField("storageUnit", storageUnit).Error("Failed to get Redis zset values")
303304
return nil, err
304305
}
305-
rows := [][]string{}
306+
var rows [][]string
306307
for i, member := range zsetValues {
307308
rows = append(rows, []string{strconv.Itoa(i), member.Member.(string), fmt.Sprintf("%.2f", member.Score)})
308309
}

0 commit comments

Comments
 (0)