Skip to content

Commit 54bd7bc

Browse files
committed
Merge branch 'master' of https://github.com/redis/go-redis into os-migrate-golang-ci-to-new-version-format
2 parents d3073d9 + 182a04f commit 54bd7bc

File tree

7 files changed

+191
-12
lines changed

7 files changed

+191
-12
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,7 @@ The core team regularly looks at pull requests. We will provide
112112
feedback as soon as possible. After receiving our feedback, please respond
113113
within two weeks. After that time, we may close your PR if it isn't
114114
showing any activity.
115+
116+
## Support
117+
118+
Maintainers can provide limited support to contributors on discord: https://discord.gg/W4txy5AeKM

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
[![build workflow](https://github.com/redis/go-redis/actions/workflows/build.yml/badge.svg)](https://github.com/redis/go-redis/actions)
44
[![PkgGoDev](https://pkg.go.dev/badge/github.com/redis/go-redis/v9)](https://pkg.go.dev/github.com/redis/go-redis/v9?tab=doc)
55
[![Documentation](https://img.shields.io/badge/redis-documentation-informational)](https://redis.uptrace.dev/)
6+
[![Go Report Card](https://goreportcard.com/badge/github.com/redis/go-redis/v9)](https://goreportcard.com/report/github.com/redis/go-redis/v9)
67
[![codecov](https://codecov.io/github/redis/go-redis/graph/badge.svg?token=tsrCZKuSSw)](https://codecov.io/github/redis/go-redis)
7-
[![Chat](https://discordapp.com/api/guilds/752070105847955518/widget.png)](https://discord.gg/rWtp5Aj)
8+
9+
[![Discord](https://img.shields.io/discord/697882427875393627.svg?style=social&logo=discord)](https://discord.gg/W4txy5AeKM)
10+
[![Twitch](https://img.shields.io/twitch/status/redisinc?style=social)](https://www.twitch.tv/redisinc)
11+
[![YouTube](https://img.shields.io/youtube/channel/views/UCD78lHSwYqMlyetR0_P4Vig?style=social)](https://www.youtube.com/redisinc)
12+
[![Twitter](https://img.shields.io/twitter/follow/redisinc?style=social)](https://twitter.com/redisinc)
13+
[![Stack Exchange questions](https://img.shields.io/stackexchange/stackoverflow/t/go-redis?style=social&logo=stackoverflow&label=Stackoverflow)](https://stackoverflow.com/questions/tagged/go-redis)
814

915
> go-redis is the official Redis client library for the Go programming language. It offers a straightforward interface for interacting with Redis servers.
1016
@@ -44,7 +50,7 @@ in the `go.mod` to `go 1.24` in one of the next releases.
4450
## Resources
4551

4652
- [Discussions](https://github.com/redis/go-redis/discussions)
47-
- [Chat](https://discord.gg/rWtp5Aj)
53+
- [Chat](https://discord.gg/W4txy5AeKM)
4854
- [Reference](https://pkg.go.dev/github.com/redis/go-redis/v9)
4955
- [Examples](https://pkg.go.dev/github.com/redis/go-redis/v9#pkg-examples)
5056

command.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3831,7 +3831,8 @@ func (cmd *MapStringStringSliceCmd) readReply(rd *proto.Reader) error {
38313831
}
38323832

38333833
// -----------------------------------------------------------------------
3834-
// MapStringInterfaceCmd represents a command that returns a map of strings to interface{}.
3834+
3835+
// MapMapStringInterfaceCmd represents a command that returns a map of strings to interface{}.
38353836
type MapMapStringInterfaceCmd struct {
38363837
baseCmd
38373838
val map[string]interface{}

commands.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ func appendArg(dst []interface{}, arg interface{}) []interface{} {
8181
return dst
8282
case time.Time, time.Duration, encoding.BinaryMarshaler, net.IP:
8383
return append(dst, arg)
84+
case nil:
85+
return dst
8486
default:
8587
// scan struct field
8688
v := reflect.ValueOf(arg)
@@ -330,7 +332,7 @@ func (info LibraryInfo) Validate() error {
330332
return nil
331333
}
332334

333-
// Hello Set the resp protocol used.
335+
// Hello sets the resp protocol used.
334336
func (c statefulCmdable) Hello(ctx context.Context,
335337
ver int, username, password, clientName string,
336338
) *MapStringInterfaceCmd {

commands_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7209,6 +7209,17 @@ var _ = Describe("Commands", func() {
72097209
Expect(err).NotTo(HaveOccurred())
72107210
Expect(vals).To(Equal([]interface{}{int64(12), proto.RedisError("error"), "abc"}))
72117211
})
7212+
7213+
It("returns empty values when args are nil", func() {
7214+
vals, err := client.Eval(
7215+
ctx,
7216+
"return {ARGV[1]}",
7217+
[]string{},
7218+
nil,
7219+
).Result()
7220+
Expect(err).NotTo(HaveOccurred())
7221+
Expect(vals).To(BeEmpty())
7222+
})
72127223
})
72137224

72147225
Describe("EvalRO", func() {
@@ -7232,6 +7243,17 @@ var _ = Describe("Commands", func() {
72327243
Expect(err).NotTo(HaveOccurred())
72337244
Expect(vals).To(Equal([]interface{}{int64(12), proto.RedisError("error"), "abc"}))
72347245
})
7246+
7247+
It("returns empty values when args are nil", func() {
7248+
vals, err := client.EvalRO(
7249+
ctx,
7250+
"return {ARGV[1]}",
7251+
[]string{},
7252+
nil,
7253+
).Result()
7254+
Expect(err).NotTo(HaveOccurred())
7255+
Expect(vals).To(BeEmpty())
7256+
})
72357257
})
72367258

72377259
Describe("Functions", func() {

doctests/home_json_example_test.go

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,107 @@ func ExampleClient_search_json() {
227227
// London - 1
228228
// Tel Aviv - 2
229229
}
230+
231+
func ExampleClient_search_hash() {
232+
ctx := context.Background()
233+
234+
rdb := redis.NewClient(&redis.Options{
235+
Addr: "localhost:6379",
236+
Password: "", // no password docs
237+
DB: 0, // use default DB
238+
Protocol: 2,
239+
})
240+
241+
// REMOVE_START
242+
rdb.Del(ctx, "huser:1", "huser:2", "huser:3")
243+
rdb.FTDropIndex(ctx, "hash-idx:users")
244+
// REMOVE_END
245+
246+
// STEP_START make_hash_index
247+
_, err := rdb.FTCreate(
248+
ctx,
249+
"hash-idx:users",
250+
// Options:
251+
&redis.FTCreateOptions{
252+
OnHash: true,
253+
Prefix: []interface{}{"huser:"},
254+
},
255+
// Index schema fields:
256+
&redis.FieldSchema{
257+
FieldName: "name",
258+
FieldType: redis.SearchFieldTypeText,
259+
},
260+
&redis.FieldSchema{
261+
FieldName: "city",
262+
FieldType: redis.SearchFieldTypeTag,
263+
},
264+
&redis.FieldSchema{
265+
FieldName: "age",
266+
FieldType: redis.SearchFieldTypeNumeric,
267+
},
268+
).Result()
269+
270+
if err != nil {
271+
panic(err)
272+
}
273+
// STEP_END
274+
275+
user1 := map[string]interface{}{
276+
"name": "Paul John",
277+
"email": "[email protected]",
278+
"age": 42,
279+
"city": "London",
280+
}
281+
282+
user2 := map[string]interface{}{
283+
"name": "Eden Zamir",
284+
"email": "[email protected]",
285+
"age": 29,
286+
"city": "Tel Aviv",
287+
}
288+
289+
user3 := map[string]interface{}{
290+
"name": "Paul Zamir",
291+
"email": "[email protected]",
292+
"age": 35,
293+
"city": "Tel Aviv",
294+
}
295+
296+
// STEP_START add_hash_data
297+
_, err = rdb.HSet(ctx, "huser:1", user1).Result()
298+
299+
if err != nil {
300+
panic(err)
301+
}
302+
303+
_, err = rdb.HSet(ctx, "huser:2", user2).Result()
304+
305+
if err != nil {
306+
panic(err)
307+
}
308+
309+
_, err = rdb.HSet(ctx, "huser:3", user3).Result()
310+
311+
if err != nil {
312+
panic(err)
313+
}
314+
// STEP_END
315+
316+
// STEP_START query1_hash
317+
findPaulHashResult, err := rdb.FTSearch(
318+
ctx,
319+
"hash-idx:users",
320+
"Paul @age:[30 40]",
321+
).Result()
322+
323+
if err != nil {
324+
panic(err)
325+
}
326+
327+
fmt.Println(findPaulHashResult)
328+
// >>> {1 [{huser:3 <nil> <nil> <nil> map[age:35 city:Tel Aviv...
329+
// STEP_END
330+
331+
// Output:
332+
// {1 [{huser:3 <nil> <nil> <nil> map[age:35 city:Tel Aviv email:[email protected] name:Paul Zamir]}]}
333+
}

hash_commands.go

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,10 @@ type HExpireArgs struct {
224224

225225
// HExpire - Sets the expiration time for specified fields in a hash in seconds.
226226
// The command constructs an argument list starting with "HEXPIRE", followed by the key, duration, any conditional flags, and the specified fields.
227-
// For more information - https://redis.io/commands/hexpire/
227+
// Available since Redis 7.4 CE.
228+
// For more information refer to [HEXPIRE Documentation].
229+
//
230+
// [HEXPIRE Documentation]: https://redis.io/commands/hexpire/
228231
func (c cmdable) HExpire(ctx context.Context, key string, expiration time.Duration, fields ...string) *IntSliceCmd {
229232
args := []interface{}{"HEXPIRE", key, formatSec(ctx, expiration), "FIELDS", len(fields)}
230233

@@ -239,7 +242,10 @@ func (c cmdable) HExpire(ctx context.Context, key string, expiration time.Durati
239242
// HExpireWithArgs - Sets the expiration time for specified fields in a hash in seconds.
240243
// It requires a key, an expiration duration, a struct with boolean flags for conditional expiration settings (NX, XX, GT, LT), and a list of fields.
241244
// The command constructs an argument list starting with "HEXPIRE", followed by the key, duration, any conditional flags, and the specified fields.
242-
// For more information - https://redis.io/commands/hexpire/
245+
// Available since Redis 7.4 CE.
246+
// For more information refer to [HEXPIRE Documentation].
247+
//
248+
// [HEXPIRE Documentation]: https://redis.io/commands/hexpire/
243249
func (c cmdable) HExpireWithArgs(ctx context.Context, key string, expiration time.Duration, expirationArgs HExpireArgs, fields ...string) *IntSliceCmd {
244250
args := []interface{}{"HEXPIRE", key, formatSec(ctx, expiration)}
245251

@@ -268,7 +274,10 @@ func (c cmdable) HExpireWithArgs(ctx context.Context, key string, expiration tim
268274
// HPExpire - Sets the expiration time for specified fields in a hash in milliseconds.
269275
// Similar to HExpire, it accepts a key, an expiration duration in milliseconds, a struct with expiration condition flags, and a list of fields.
270276
// The command modifies the standard time.Duration to milliseconds for the Redis command.
271-
// For more information - https://redis.io/commands/hpexpire/
277+
// Available since Redis 7.4 CE.
278+
// For more information refer to [HPEXPIRE Documentation].
279+
//
280+
// [HPEXPIRE Documentation]: https://redis.io/commands/hpexpire/
272281
func (c cmdable) HPExpire(ctx context.Context, key string, expiration time.Duration, fields ...string) *IntSliceCmd {
273282
args := []interface{}{"HPEXPIRE", key, formatMs(ctx, expiration), "FIELDS", len(fields)}
274283

@@ -280,6 +289,13 @@ func (c cmdable) HPExpire(ctx context.Context, key string, expiration time.Durat
280289
return cmd
281290
}
282291

292+
// HPExpireWithArgs - Sets the expiration time for specified fields in a hash in milliseconds.
293+
// It requires a key, an expiration duration, a struct with boolean flags for conditional expiration settings (NX, XX, GT, LT), and a list of fields.
294+
// The command constructs an argument list starting with "HPEXPIRE", followed by the key, duration, any conditional flags, and the specified fields.
295+
// Available since Redis 7.4 CE.
296+
// For more information refer to [HPEXPIRE Documentation].
297+
//
298+
// [HPEXPIRE Documentation]: https://redis.io/commands/hpexpire/
283299
func (c cmdable) HPExpireWithArgs(ctx context.Context, key string, expiration time.Duration, expirationArgs HExpireArgs, fields ...string) *IntSliceCmd {
284300
args := []interface{}{"HPEXPIRE", key, formatMs(ctx, expiration)}
285301

@@ -308,7 +324,10 @@ func (c cmdable) HPExpireWithArgs(ctx context.Context, key string, expiration ti
308324
// HExpireAt - Sets the expiration time for specified fields in a hash to a UNIX timestamp in seconds.
309325
// Takes a key, a UNIX timestamp, a struct of conditional flags, and a list of fields.
310326
// The command sets absolute expiration times based on the UNIX timestamp provided.
311-
// For more information - https://redis.io/commands/hexpireat/
327+
// Available since Redis 7.4 CE.
328+
// For more information refer to [HExpireAt Documentation].
329+
//
330+
// [HExpireAt Documentation]: https://redis.io/commands/hexpireat/
312331
func (c cmdable) HExpireAt(ctx context.Context, key string, tm time.Time, fields ...string) *IntSliceCmd {
313332

314333
args := []interface{}{"HEXPIREAT", key, tm.Unix(), "FIELDS", len(fields)}
@@ -348,7 +367,10 @@ func (c cmdable) HExpireAtWithArgs(ctx context.Context, key string, tm time.Time
348367

349368
// HPExpireAt - Sets the expiration time for specified fields in a hash to a UNIX timestamp in milliseconds.
350369
// Similar to HExpireAt but for timestamps in milliseconds. It accepts the same parameters and adjusts the UNIX time to milliseconds.
351-
// For more information - https://redis.io/commands/hpexpireat/
370+
// Available since Redis 7.4 CE.
371+
// For more information refer to [HExpireAt Documentation].
372+
//
373+
// [HExpireAt Documentation]: https://redis.io/commands/hexpireat/
352374
func (c cmdable) HPExpireAt(ctx context.Context, key string, tm time.Time, fields ...string) *IntSliceCmd {
353375
args := []interface{}{"HPEXPIREAT", key, tm.UnixNano() / int64(time.Millisecond), "FIELDS", len(fields)}
354376

@@ -388,7 +410,10 @@ func (c cmdable) HPExpireAtWithArgs(ctx context.Context, key string, tm time.Tim
388410
// HPersist - Removes the expiration time from specified fields in a hash.
389411
// Accepts a key and the fields themselves.
390412
// This command ensures that each field specified will have its expiration removed if present.
391-
// For more information - https://redis.io/commands/hpersist/
413+
// Available since Redis 7.4 CE.
414+
// For more information refer to [HPersist Documentation].
415+
//
416+
// [HPersist Documentation]: https://redis.io/commands/hpersist/
392417
func (c cmdable) HPersist(ctx context.Context, key string, fields ...string) *IntSliceCmd {
393418
args := []interface{}{"HPERSIST", key, "FIELDS", len(fields)}
394419

@@ -403,6 +428,10 @@ func (c cmdable) HPersist(ctx context.Context, key string, fields ...string) *In
403428
// HExpireTime - Retrieves the expiration time for specified fields in a hash as a UNIX timestamp in seconds.
404429
// Requires a key and the fields themselves to fetch their expiration timestamps.
405430
// This command returns the expiration times for each field or error/status codes for each field as specified.
431+
// Available since Redis 7.4 CE.
432+
// For more information refer to [HExpireTime Documentation].
433+
//
434+
// [HExpireTime Documentation]: https://redis.io/commands/hexpiretime/
406435
// For more information - https://redis.io/commands/hexpiretime/
407436
func (c cmdable) HExpireTime(ctx context.Context, key string, fields ...string) *IntSliceCmd {
408437
args := []interface{}{"HEXPIRETIME", key, "FIELDS", len(fields)}
@@ -418,6 +447,10 @@ func (c cmdable) HExpireTime(ctx context.Context, key string, fields ...string)
418447
// HPExpireTime - Retrieves the expiration time for specified fields in a hash as a UNIX timestamp in milliseconds.
419448
// Similar to HExpireTime, adjusted for timestamps in milliseconds. It requires the same parameters.
420449
// Provides the expiration timestamp for each field in milliseconds.
450+
// Available since Redis 7.4 CE.
451+
// For more information refer to [HExpireTime Documentation].
452+
//
453+
// [HExpireTime Documentation]: https://redis.io/commands/hexpiretime/
421454
// For more information - https://redis.io/commands/hexpiretime/
422455
func (c cmdable) HPExpireTime(ctx context.Context, key string, fields ...string) *IntSliceCmd {
423456
args := []interface{}{"HPEXPIRETIME", key, "FIELDS", len(fields)}
@@ -433,7 +466,10 @@ func (c cmdable) HPExpireTime(ctx context.Context, key string, fields ...string)
433466
// HTTL - Retrieves the remaining time to live for specified fields in a hash in seconds.
434467
// Requires a key and the fields themselves. It returns the TTL for each specified field.
435468
// This command fetches the TTL in seconds for each field or returns error/status codes as appropriate.
436-
// For more information - https://redis.io/commands/httl/
469+
// Available since Redis 7.4 CE.
470+
// For more information refer to [HTTL Documentation].
471+
//
472+
// [HTTL Documentation]: https://redis.io/commands/httl/
437473
func (c cmdable) HTTL(ctx context.Context, key string, fields ...string) *IntSliceCmd {
438474
args := []interface{}{"HTTL", key, "FIELDS", len(fields)}
439475

@@ -448,6 +484,10 @@ func (c cmdable) HTTL(ctx context.Context, key string, fields ...string) *IntSli
448484
// HPTTL - Retrieves the remaining time to live for specified fields in a hash in milliseconds.
449485
// Similar to HTTL, but returns the TTL in milliseconds. It requires a key and the specified fields.
450486
// This command provides the TTL in milliseconds for each field or returns error/status codes as needed.
487+
// Available since Redis 7.4 CE.
488+
// For more information refer to [HPTTL Documentation].
489+
//
490+
// [HPTTL Documentation]: https://redis.io/commands/hpttl/
451491
// For more information - https://redis.io/commands/hpttl/
452492
func (c cmdable) HPTTL(ctx context.Context, key string, fields ...string) *IntSliceCmd {
453493
args := []interface{}{"HPTTL", key, "FIELDS", len(fields)}
@@ -480,7 +520,7 @@ func (c cmdable) HGetEX(ctx context.Context, key string, fields ...string) *Stri
480520
return cmd
481521
}
482522

483-
// ExpirationType represents an expiration option for the HGETEX command.
523+
// HGetEXExpirationType represents an expiration option for the HGETEX command.
484524
type HGetEXExpirationType string
485525

486526
const (

0 commit comments

Comments
 (0)