Skip to content

Commit 9eb0410

Browse files
authored
Merge branch 'master' into apply-make-fmt
2 parents 5dc79ef + 182a04f commit 9eb0410

File tree

6 files changed

+187
-9
lines changed

6 files changed

+187
-9
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

commands.go

Lines changed: 2 additions & 0 deletions
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)

commands_test.go

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

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

72367258
Describe("Functions", func() {

doctests/home_json_example_test.go

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

hash_commands.go

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,10 @@ type HExpireArgs struct {
225225

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

@@ -240,7 +243,10 @@ func (c cmdable) HExpire(ctx context.Context, key string, expiration time.Durati
240243
// HExpireWithArgs - Sets the expiration time for specified fields in a hash in seconds.
241244
// 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.
242245
// The command constructs an argument list starting with "HEXPIRE", followed by the key, duration, any conditional flags, and the specified fields.
243-
// For more information - https://redis.io/commands/hexpire/
246+
// Available since Redis 7.4 CE.
247+
// For more information refer to [HEXPIRE Documentation].
248+
//
249+
// [HEXPIRE Documentation]: https://redis.io/commands/hexpire/
244250
func (c cmdable) HExpireWithArgs(ctx context.Context, key string, expiration time.Duration, expirationArgs HExpireArgs, fields ...string) *IntSliceCmd {
245251
args := []interface{}{"HEXPIRE", key, formatSec(ctx, expiration)}
246252

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

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

293+
// HPExpireWithArgs - Sets the expiration time for specified fields in a hash in milliseconds.
294+
// 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.
295+
// The command constructs an argument list starting with "HPEXPIRE", followed by the key, duration, any conditional flags, and the specified fields.
296+
// Available since Redis 7.4 CE.
297+
// For more information refer to [HPEXPIRE Documentation].
298+
//
299+
// [HPEXPIRE Documentation]: https://redis.io/commands/hpexpire/
284300
func (c cmdable) HPExpireWithArgs(ctx context.Context, key string, expiration time.Duration, expirationArgs HExpireArgs, fields ...string) *IntSliceCmd {
285301
args := []interface{}{"HPEXPIRE", key, formatMs(ctx, expiration)}
286302

@@ -309,7 +325,10 @@ func (c cmdable) HPExpireWithArgs(ctx context.Context, key string, expiration ti
309325
// HExpireAt - Sets the expiration time for specified fields in a hash to a UNIX timestamp in seconds.
310326
// Takes a key, a UNIX timestamp, a struct of conditional flags, and a list of fields.
311327
// The command sets absolute expiration times based on the UNIX timestamp provided.
312-
// For more information - https://redis.io/commands/hexpireat/
328+
// Available since Redis 7.4 CE.
329+
// For more information refer to [HExpireAt Documentation].
330+
//
331+
// [HExpireAt Documentation]: https://redis.io/commands/hexpireat/
313332
func (c cmdable) HExpireAt(ctx context.Context, key string, tm time.Time, fields ...string) *IntSliceCmd {
314333
args := []interface{}{"HEXPIREAT", key, tm.Unix(), "FIELDS", len(fields)}
315334

@@ -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)}

0 commit comments

Comments
 (0)