rustis 0.19.3

Redis async driver for Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
use crate::{
    client::{PreparedCommand, prepare_command},
    commands::{ExpireOption, GetExOptions, SetExpiration},
    resp::{
        ArgCounter, FastPathCommandBuilder, Response, cmd, deserialize_vec_of_pairs, serialize_flag,
    },
};
use serde::{Deserialize, Serialize, de::DeserializeOwned};

/// A group of Redis commands related to [`Hashes`](https://redis.io/docs/data-types/hashes/)
///
/// # See Also
/// [Redis Hash Commands](https://redis.io/commands/?group=hash)
pub trait HashCommands<'a>: Sized {
    /// Removes the specified fields from the hash stored at key.
    ///
    /// # Return
    /// the number of fields that were removed from the hash, not including specified but non existing fields.
    ///
    /// # See Also
    /// [<https://redis.io/commands/hdel/>](https://redis.io/commands/hdel/)
    #[must_use]
    fn hdel(self, key: impl Serialize, fields: impl Serialize) -> PreparedCommand<'a, Self, usize> {
        prepare_command(self, cmd("HDEL").key(key).arg(fields))
    }

    /// Returns if field is an existing field in the hash stored at key.
    ///
    /// # Return
    /// * `true` - if the hash contains field.
    /// * `false` - if the hash does not contain field, or key does not exist.
    ///
    /// # See Also
    /// [<https://redis.io/commands/hexists/>](https://redis.io/commands/hexists/)
    #[must_use]
    fn hexists(
        self,
        key: impl Serialize,
        field: impl Serialize,
    ) -> PreparedCommand<'a, Self, bool> {
        prepare_command(self, cmd("HEXISTS").key(key).arg(field))
    }

    /// Set an expiration (TTL or time to live) on one or more fields of a given hash key.
    ///
    /// Field(s) will automatically be deleted from the hash key when their TTLs expire.
    ///
    /// # Arguments
    /// * `key` - The hash key
    /// * `seconds ` - The expiration time in seconds
    /// * `option` - The [`ExpireOption`](crate::commands::ExpireOption) option.
    /// * `fields` - The fields to expire.
    ///
    /// # Return
    /// For each field:
    /// * `-2` - if no such field exists in the provided hash key, or the provided key does not exist.
    /// * `0` - if the specified NX | XX | GT | LT condition has not been met.
    /// * `1` - if the expiration time was set/updated.
    /// * `2` - when the command is called with 0 seconds.
    ///
    /// # See Also
    /// [<https://redis.io/commands/hexpire/>](https://redis.io/commands/hexpire/)
    #[must_use]
    fn hexpire<R: Response>(
        self,
        key: impl Serialize,
        seconds: u64,
        option: impl Into<Option<ExpireOption>>,
        fields: impl Serialize,
    ) -> PreparedCommand<'a, Self, R> {
        prepare_command(
            self,
            cmd("HEXPIRE")
                .key(key)
                .arg(seconds)
                .arg(option.into())
                .arg("FIELDS")
                .arg_with_count(fields),
        )
    }

    /// HEXPIREAT has the same effect and semantics as HEXPIRE,
    /// but instead of specifying the number of seconds for the TTL (time to live),
    /// it takes an absolute Unix timestamp in seconds since Unix epoch.
    ///
    /// A timestamp in the past will delete the field immediately.
    ///
    /// # Arguments
    /// * `key` - The hash key
    /// * `unix_time_seconds ` - The aboslute unix timestamp the fields will expire at.
    /// * `option` - The [`ExpireOption`](crate::commands::ExpireOption) option.
    /// * `fields` - The fields to expire.
    ///
    /// # Return
    /// For each field:
    /// * `-2` - if no such field exists in the provided hash key, or the provided key does not exist.
    /// * `0` - if the specified NX | XX | GT | LT condition has not been met.
    /// * `1` - if the expiration time was set/updated.
    /// * `2` - when the command is called with a past Unix time in seconds.
    ///
    /// # See Also
    /// [<https://redis.io/commands/hexpireat/>](https://redis.io/commands/hexpireat/)
    #[must_use]
    fn hexpireat<R: Response>(
        self,
        key: impl Serialize,
        unix_time_seconds: u64,
        option: impl Into<Option<ExpireOption>>,
        fields: impl Serialize,
    ) -> PreparedCommand<'a, Self, R> {
        prepare_command(
            self,
            cmd("HEXPIREAT")
                .key(key)
                .arg(unix_time_seconds)
                .arg(option.into())
                .arg("FIELDS")
                .arg_with_count(fields),
        )
    }

    /// Returns the absolute Unix timestamp in seconds since Unix epoch
    /// at which the given key's field(s) will expire.
    ///
    /// # Arguments
    /// * `key` - The hash key
    /// * `fields` - The fields to get the expiration time from.
    ///
    /// # Return
    /// For each field, the expiration (Unix timestamp) in seconds.
    /// - The command returns -2 if no such field exists in the provided hash key, or the provided key does not exist.
    /// - The command returns -1 if the field exists but has no associated expiration set.
    ///
    /// # See Also
    /// [<https://redis.io/commands/hexpiretime/>](https://redis.io/commands/hexpiretime/)
    #[must_use]
    fn hexpiretime<R: Response>(
        self,
        key: impl Serialize,
        fields: impl Serialize,
    ) -> PreparedCommand<'a, Self, R> {
        prepare_command(
            self,
            cmd("HEXPIRETIME")
                .key(key)
                .arg("FIELDS")
                .arg_with_count(fields),
        )
    }

    /// Returns the value associated with field in the hash stored at key.
    ///
    /// # Return
    /// The value associated with field, or nil when field is not present in the hash or key does not exist.
    ///
    /// # See Also
    /// [<https://redis.io/commands/hget/>](https://redis.io/commands/hget/)
    #[must_use]
    fn hget<R: Response>(
        self,
        key: impl Serialize,
        field: impl Serialize,
    ) -> PreparedCommand<'a, Self, R> {
        prepare_command(self, FastPathCommandBuilder::hget(key, field))
    }

    /// Returns all fields and values of the hash stored at key.
    ///
    /// # Return
    /// The list of fields and their values stored in the hash, or an empty list when key does not exist.
    ///
    /// # See Also
    /// [<https://redis.io/commands/hgetall/>](https://redis.io/commands/hgetall/)
    #[must_use]
    fn hgetall<R: Response>(self, key: impl Serialize) -> PreparedCommand<'a, Self, R> {
        prepare_command(self, cmd("HGETALL").key(key))
    }

    /// Get and delete the value of one or more fields of a given hash key.
    ///
    /// When the last field is deleted, the key will also be deleted.
    ///
    /// # Arguments
    /// * `key` - The hash key
    /// * `fields` - The fields to get and delete.
    ///
    /// # Return
    /// A list of deleted fields and their values or nil for fields that do not exist.
    ///
    /// # See Also
    /// [<https://redis.io/commands/hgetdel/>](https://redis.io/commands/hgetdel/)
    #[must_use]
    fn hgetdel<R: Response>(
        self,
        key: impl Serialize,
        fields: impl Serialize,
    ) -> PreparedCommand<'a, Self, R> {
        prepare_command(
            self,
            cmd("HGETDEL").key(key).arg("FIELDS").arg_with_count(fields),
        )
    }

    /// Get the value of one or more fields of a given hash key
    /// and optionally set their expiration time or time-to-live (TTL).
    ///
    /// # Arguments
    /// * `key` - The hash key
    /// * `options` - The [`GetExOptions`](crate::commands::GetExOptions) options.
    /// * `fields` - The fields to get.
    ///
    /// # Return
    /// a list of values associated with the given fields, in the same order as they are requested.
    ///
    /// # See Also
    /// [<https://redis.io/commands/hgetex/>](https://redis.io/commands/hgetex/)
    #[must_use]
    fn hgetex<R: Response>(
        self,
        key: impl Serialize,
        options: GetExOptions,
        fields: impl Serialize,
    ) -> PreparedCommand<'a, Self, R> {
        prepare_command(
            self,
            cmd("HGETEX")
                .key(key)
                .arg(options)
                .arg("FIELDS")
                .arg_with_count(fields),
        )
    }

    /// Increments the number stored at field in the hash stored at key by increment.
    ///
    /// # Return
    /// The value at field after the increment operation.
    ///
    /// # See Also
    /// [<https://redis.io/commands/hincrby/>](https://redis.io/commands/hincrby/)
    #[must_use]
    fn hincrby(
        self,
        key: impl Serialize,
        field: impl Serialize,
        increment: i64,
    ) -> PreparedCommand<'a, Self, i64> {
        prepare_command(self, FastPathCommandBuilder::hincrby(key, field, increment))
    }

    /// Increment the specified field of a hash stored at key,
    /// and representing a floating point number, by the specified increment.
    ///
    /// # Return
    /// The value at field after the increment operation.
    ///
    /// # See Also
    /// [<https://redis.io/commands/hincrbyfloat/>](https://redis.io/commands/hincrbyfloat/)
    #[must_use]
    fn hincrbyfloat(
        self,
        key: impl Serialize,
        field: impl Serialize,
        increment: f64,
    ) -> PreparedCommand<'a, Self, f64> {
        prepare_command(self, cmd("HINCRBYFLOAT").key(key).arg(field).arg(increment))
    }

    /// Returns all field names in the hash stored at key.
    ///
    /// # Return
    /// The list of fields in the hash, or an empty list when key does not exist.
    ///
    /// # See Also
    /// [<https://redis.io/commands/hkeys/>](https://redis.io/commands/hkeys/)
    #[must_use]
    fn hkeys<R: Response>(self, key: impl Serialize) -> PreparedCommand<'a, Self, R> {
        prepare_command(self, cmd("HKEYS").key(key))
    }

    /// Returns the number of fields contained in the hash stored at key.
    ///
    /// # Return
    /// The number of fields in the hash, or 0 when key does not exist.
    ///
    /// # See Also
    /// [<https://redis.io/commands/hlen/>](https://redis.io/commands/hlen/)
    #[must_use]
    fn hlen(self, key: impl Serialize) -> PreparedCommand<'a, Self, usize> {
        prepare_command(self, cmd("HLEN").key(key))
    }

    /// Returns the values associated with the specified fields in the hash stored at key.
    ///
    /// # Return
    /// The list of values associated with the given fields, in the same order as they are requested.
    ///
    /// # See Also
    /// [<https://redis.io/commands/hmget/>](https://redis.io/commands/hmget/)
    #[must_use]
    fn hmget<R: Response>(
        self,
        key: impl Serialize,
        fields: impl Serialize,
    ) -> PreparedCommand<'a, Self, R> {
        prepare_command(self, cmd("HMGET").key(key).arg(fields))
    }

    /// Remove the existing expiration on a hash key's field(s),
    /// turning the field(s) from volatile (a field with expiration set)
    /// to persistent (a field that will never expire as no TTL (time to live) is associated).
    ///
    /// # Return
    /// For each field:
    /// * `-2` - if no such field exists in the provided hash key, or the provided key does not exist.
    /// * `-1` - if the field exists but has no associated expiration set.
    /// * `1` - the expiration was removed.
    ///
    /// # See Also
    /// [<https://redis.io/commands/hpersist/>](https://redis.io/commands/hpersist/)
    #[must_use]
    fn hpersist<R: Response>(
        self,
        key: impl Serialize,
        fields: impl Serialize,
    ) -> PreparedCommand<'a, Self, R> {
        prepare_command(self, cmd("HPERSIST").key(key).arg(fields))
    }

    /// This command works like [`hexpire`](HashCommands::hexpire), but the expiration of a field is specified in milliseconds instead of seconds.
    ///
    /// # Arguments
    /// * `key` - The hash key
    /// * `milliseconds ` - The expiration time in milliseconds
    /// * `option` - The [`ExpireOption`](crate::commands::ExpireOption) option.
    /// * `fields` - The fields to expire.
    ///
    /// # Return
    /// For each field:
    /// * `-2` - if no such field exists in the provided hash key, or the provided key does not exist.
    /// * `0` - if the specified NX | XX | GT | LT condition has not been met.
    /// * `1` - if the expiration time was set/updated.
    /// * `2` - when the command is called with 0 milliseconds.
    ///
    /// # See Also
    /// [<https://redis.io/commands/hpexpire/>](https://redis.io/commands/hpexpire/)
    #[must_use]
    fn hpexpire<R: Response>(
        self,
        key: impl Serialize,
        milliseconds: u64,
        option: impl Into<Option<ExpireOption>>,
        fields: impl Serialize,
    ) -> PreparedCommand<'a, Self, R> {
        prepare_command(
            self,
            cmd("HPEXPIRE")
                .key(key)
                .arg(milliseconds)
                .arg(option.into())
                .arg("FIELDS")
                .arg_with_count(fields),
        )
    }

    /// This command has the same effect and semantics as [`hexpireat`](HashCommands::hexpireat),
    /// but the Unix time at which the field will expire
    /// is specified in milliseconds since Unix epoch instead of seconds.
    ///
    /// # Arguments
    /// * `key` - The hash key
    /// * `unix_time_milliseconds` - The aboslute unix timestamp in milliseconds, the fields will expire at.
    /// * `option` - The [`ExpireOption`](crate::commands::ExpireOption) option.
    /// * `fields` - The fields to expire.
    ///
    /// # Return
    /// For each field:
    /// * `-2` - if no such field exists in the provided hash key, or the provided key does not exist.
    /// * `0` - if the specified NX | XX | GT | LT condition has not been met.
    /// * `1` - if the expiration time was set/updated.
    /// * `2` - when the command is called with a past Unix time in milliseconds.
    ///
    /// # See Also
    /// [<https://redis.io/commands/hpexpireat/>](https://redis.io/commands/hpexpireat/)
    #[must_use]
    fn hpexpireat<R: Response>(
        self,
        key: impl Serialize,
        unix_time_milliseconds: u64,
        option: impl Into<Option<ExpireOption>>,
        fields: impl Serialize,
    ) -> PreparedCommand<'a, Self, R> {
        prepare_command(
            self,
            cmd("HPEXPIREAT")
                .key(key)
                .arg(unix_time_milliseconds)
                .arg(option.into())
                .arg("FIELDS")
                .arg_with_count(fields),
        )
    }

    /// This command has the same semantics as [`hexpiretime`](HashCommands::hexpiretime),
    /// but returns the absolute Unix expiration timestamp
    /// in milliseconds since Unix epoch instead of seconds.
    ///
    /// # Arguments
    /// * `key` - The hash key
    /// * `fields` - The fields to get the expiration time from.
    ///
    /// # Return
    /// For each field, the expiration (Unix timestamp) in milliseconds.
    /// - The command returns -2 if no such field exists in the provided hash key, or the provided key does not exist.
    /// - The command returns -1 if the field exists but has no associated expiration set.
    ///
    /// # See Also
    /// [<https://redis.io/commands/hpexpiretime/>](https://redis.io/commands/hpexpiretime/)
    #[must_use]
    fn hpexpiretime<R: Response>(
        self,
        key: impl Serialize,
        fields: impl Serialize,
    ) -> PreparedCommand<'a, Self, R> {
        prepare_command(
            self,
            cmd("HPEXPIRETIME")
                .key(key)
                .arg("FIELDS")
                .arg_with_count(fields),
        )
    }

    /// Like [`httl`](HashCommands::httl), this command returns the remaining TTL (time to live)
    /// of a field that has an expiration set, but in milliseconds instead of seconds.
    ///
    /// # Arguments
    /// * `key` - The hash key
    /// * `fields` - The fields to get the TTL from.
    ///
    /// # Return
    /// the TTL in milliseconds.
    /// - The command returns -2 if no such field exists in the provided hash key, or the provided key does not exist.
    /// - The command returns -1 if the field exists but has no associated expiration set.
    ///
    /// # See Also
    /// [<https://redis.io/commands/hpttl/>](https://redis.io/commands/hpttl/)
    #[must_use]
    fn hpttl<R: Response>(
        self,
        key: impl Serialize,
        fields: impl Serialize,
    ) -> PreparedCommand<'a, Self, R> {
        prepare_command(
            self,
            cmd("HPTTL").key(key).arg("FIELDS").arg_with_count(fields),
        )
    }

    /// return random fields from the hash value stored at key.
    ///
    /// # Return
    /// * When called with just the key argument, return a random field from the hash value stored at key.
    ///
    /// # See Also
    /// [<https://redis.io/commands/hrandfield/>](https://redis.io/commands/hrandfield/)
    #[must_use]
    fn hrandfield<R: Response>(self, key: impl Serialize) -> PreparedCommand<'a, Self, R> {
        prepare_command(self, cmd("HRANDFIELD").key(key))
    }

    /// return random fields from the hash value stored at key.
    ///
    /// # Return
    /// * If the provided count argument is positive, return an array of distinct fields.
    ///   The array's length is either count or the hash's number of fields (HLEN), whichever is lower.
    /// * If called with a negative count, the behavior changes and the command is allowed to return the same field multiple times.
    ///   In this case, the number of returned fields is the absolute value of the specified count.
    ///
    /// # See Also
    /// [<https://redis.io/commands/hrandfield/>](https://redis.io/commands/hrandfield/)
    #[must_use]
    fn hrandfields<R: Response>(
        self,
        key: impl Serialize,
        count: isize,
    ) -> PreparedCommand<'a, Self, R> {
        prepare_command(self, cmd("HRANDFIELD").key(key).arg(count))
    }

    /// return random fields from the hash value stored at key.
    ///
    /// # Return
    /// * If the provided count argument is positive, return an array of distinct fields.
    ///   The array's length is either count or the hash's number of fields (HLEN), whichever is lower.
    /// * If called with a negative count, the behavior changes and the command is allowed to return the same field multiple times.
    ///   In this case, the number of returned fields is the absolute value of the specified count.
    ///   The optional WITHVALUES modifier changes the reply so it includes the respective values of the randomly selected hash fields.
    ///
    /// # See Also
    /// [<https://redis.io/commands/hrandfield/>](https://redis.io/commands/hrandfield/)
    #[must_use]
    fn hrandfields_with_values<R: Response>(
        self,
        key: impl Serialize,
        count: isize,
    ) -> PreparedCommand<'a, Self, R> {
        prepare_command(
            self,
            cmd("HRANDFIELD").key(key).arg(count).arg("WITHVALUES"),
        )
    }

    /// Iterates fields of Hash types and their associated values.
    ///
    /// # Return
    /// array of elements contain two elements, a field and a value,
    /// for every returned element of the Hash.
    ///
    /// # See Also
    /// [<https://redis.io/commands/hlen/>](https://redis.io/commands/hscan/)
    #[must_use]
    fn hscan<F: Response + DeserializeOwned, V: Response + DeserializeOwned>(
        self,
        key: impl Serialize,
        cursor: u64,
        options: HScanOptions,
    ) -> PreparedCommand<'a, Self, HScanResult<F, V>> {
        prepare_command(self, cmd("HSCAN").key(key).arg(cursor).arg(options))
    }

    /// Sets field in the hash stored at key to value.
    ///
    /// # Return
    /// The number of fields that were added.
    ///
    /// # See Also
    /// [<https://redis.io/commands/hset/>](https://redis.io/commands/hset/)
    #[must_use]
    fn hset(self, key: impl Serialize, items: impl Serialize) -> PreparedCommand<'a, Self, usize> {
        prepare_command(self, cmd("HSET").key(key).arg(items))
    }

    /// Set the value of one or more fields of a given hash key,
    /// and optionally set their expiration time or time-to-live (TTL).
    ///
    /// # Return
    /// * `true` if all the fields wereset.
    /// * `false` if no fields were set.
    ///
    /// # See Also
    /// [<https://redis.io/commands/hsetex/>](https://redis.io/commands/hsetex/)
    #[must_use]
    fn hsetex(
        self,
        key: impl Serialize,
        condition: impl Into<Option<HSetExCondition>>,
        expiration: impl Into<Option<SetExpiration>>,
        items: impl Serialize,
    ) -> PreparedCommand<'a, Self, bool> {
        let mut counter = ArgCounter::default();
        items.serialize(&mut counter).expect("Arg counting failed");

        prepare_command(
            self,
            cmd("HSETEX")
                .key(key)
                .arg(condition.into())
                .arg(expiration.into())
                .arg("FIELDS")
                .arg(counter.count / 2)
                .arg(items),
        )
    }

    /// Sets field in the hash stored at key to value, only if field does not yet exist.
    ///
    /// # Return
    /// * `true` - if field is a new field in the hash and value was set.
    /// * `false` - if field already exists in the hash and no operation was performed.
    ///
    /// # See Also
    /// [<https://redis.io/commands/hsetnx/>](https://redis.io/commands/hsetnx/)
    #[must_use]
    fn hsetnx(
        self,
        key: impl Serialize,
        field: impl Serialize,
        value: impl Serialize,
    ) -> PreparedCommand<'a, Self, bool> {
        prepare_command(self, cmd("HSETNX").key(key).arg(field).arg(value))
    }

    /// Returns the string length of the value associated with field in the hash stored at key.
    ///
    /// # Return
    /// the string length of the value associated with field,
    /// or zero when field is not present in the hash or key does not exist at all.
    ///
    /// # See Also
    /// [<https://redis.io/commands/hstrlen/>](https://redis.io/commands/hstrlen/)
    #[must_use]
    fn hstrlen(
        self,
        key: impl Serialize,
        field: impl Serialize,
    ) -> PreparedCommand<'a, Self, usize> {
        prepare_command(self, cmd("HSTRLEN").key(key).arg(field))
    }

    /// Returns the remaining TTL (time to live) of a hash key's field(s) that have a set expiration.
    /// This introspection capability allows you to check how many seconds
    /// a given hash field will continue to be part of the hash key.
    ///
    /// # Arguments
    /// * `key` - The hash key
    /// * `fields` - The fields to get the TTL from.
    ///
    /// # Return
    /// The TTL in seconds.
    /// - The command returns -2 if no such field exists in the provided hash key, or the provided key does not exist.
    /// - The command returns -1 if the field exists but has no associated expiration set.
    ///
    /// # See Also
    /// [<https://redis.io/commands/httl/>](https://redis.io/commands/httl/)
    #[must_use]
    fn httl<R: Response>(
        self,
        key: impl Serialize,
        fields: impl Serialize,
    ) -> PreparedCommand<'a, Self, R> {
        prepare_command(
            self,
            cmd("HTTL").key(key).arg("FIELDS").arg_with_count(fields),
        )
    }

    /// list of values in the hash, or an empty list when key does not exist.
    ///
    /// # Return
    /// The list of values in the hash, or an empty list when key does not exist.
    ///
    /// # See Also
    /// [<https://redis.io/commands/hvals/>](https://redis.io/commands/hvals/)
    #[must_use]
    fn hvals<R: Response>(self, key: impl Serialize) -> PreparedCommand<'a, Self, R> {
        prepare_command(self, cmd("HVALS").key(key))
    }
}

/// Options for the [`hscan`](HashCommands::hscan) command
#[derive(Default, Serialize)]
#[serde(rename_all = "UPPERCASE")]
pub struct HScanOptions<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    r#match: Option<&'a str>,
    #[serde(skip_serializing_if = "Option::is_none")]
    count: Option<u32>,
    #[serde(
        skip_serializing_if = "std::ops::Not::not",
        serialize_with = "serialize_flag"
    )]
    novalues: bool,
}

impl<'a> HScanOptions<'a> {
    #[must_use]
    pub fn match_pattern(mut self, match_pattern: &'a str) -> Self {
        self.r#match = Some(match_pattern);
        self
    }

    #[must_use]
    pub fn count(mut self, count: u32) -> Self {
        self.count = Some(count);
        self
    }

    #[must_use]
    pub fn no_values(mut self) -> Self {
        self.novalues = true;
        self
    }
}

/// Result for the [`hscan`](HashCommands::hscan) command.
#[derive(Debug, Deserialize)]
pub struct HScanResult<F: Response + DeserializeOwned, V: Response + DeserializeOwned> {
    pub cursor: u64,
    #[serde(deserialize_with = "deserialize_vec_of_pairs")]
    pub elements: Vec<(F, V)>,
}

/// Condition option for the [`hsetex`](HashCommands::hsetex) command
#[derive(Serialize)]
#[serde(rename_all = "UPPERCASE")]
pub enum HSetExCondition {
    /// Only set the fields if none of them already exist.
    FNX,
    /// Only set the fields if all of them already exist.
    FXX,
}