0
# Parameters and Configuration
1
2
This document covers type-safe parameter objects and configuration classes used throughout Jedis to provide flexible and maintainable Redis command options.
3
4
## Base Parameter Interface
5
6
### IParams
7
8
Base interface for all parameter classes in Jedis.
9
10
```java { .api }
11
public interface IParams {
12
/**
13
* Convert parameters to Redis protocol arguments
14
* @return Array of byte arrays representing protocol arguments
15
*/
16
byte[][] getByteParams();
17
}
18
```
19
20
## String Command Parameters
21
22
### SetParams
23
24
Parameters for Redis SET command with various options.
25
26
```java { .api }
27
public class SetParams implements IParams {
28
/**
29
* Set expiration in seconds
30
* @param secondsToExpire Seconds until expiration
31
* @return SetParams instance for chaining
32
*/
33
public SetParams ex(long secondsToExpire);
34
35
/**
36
* Set expiration in milliseconds
37
* @param millisecondsToExpire Milliseconds until expiration
38
* @return SetParams instance
39
*/
40
public SetParams px(long millisecondsToExpire);
41
42
/**
43
* Set expiration at specific Unix timestamp (seconds)
44
* @param unixTime Unix timestamp in seconds
45
* @return SetParams instance
46
*/
47
public SetParams exAt(long unixTime);
48
49
/**
50
* Set expiration at specific Unix timestamp (milliseconds)
51
* @param unixTimeInMillis Unix timestamp in milliseconds
52
* @return SetParams instance
53
*/
54
public SetParams pxAt(long unixTimeInMillis);
55
56
/**
57
* Set only if key doesn't exist (SET IF NOT EXISTS)
58
* @return SetParams instance
59
*/
60
public SetParams nx();
61
62
/**
63
* Set only if key exists (SET IF EXISTS)
64
* @return SetParams instance
65
*/
66
public SetParams xx();
67
68
/**
69
* Keep existing TTL (don't change expiration)
70
* @return SetParams instance
71
*/
72
public SetParams keepTtl();
73
74
/**
75
* Get previous value (GET SET behavior)
76
* @return SetParams instance
77
*/
78
public SetParams get();
79
80
/**
81
* Static factory method for convenient creation
82
* @return New SetParams instance
83
*/
84
public static SetParams setParams();
85
}
86
```
87
88
#### Usage Example
89
90
```java
91
Jedis jedis = new Jedis("localhost", 6379);
92
93
// Set with expiration in seconds
94
SetParams expiryParams = SetParams.setParams().ex(3600);
95
jedis.set("session:abc", "user_data", expiryParams);
96
97
// Set only if not exists with millisecond precision
98
SetParams nxParams = SetParams.setParams().px(5000).nx();
99
String result = jedis.set("lock:resource", "locked", nxParams);
100
101
// Set with expiration at specific timestamp
102
long expireAt = System.currentTimeMillis() + 86400000; // 24 hours from now
103
SetParams timestampParams = SetParams.setParams().pxAt(expireAt);
104
jedis.set("daily_cache", "data", timestampParams);
105
106
// Update existing key while keeping TTL
107
SetParams keepTtlParams = SetParams.setParams().xx().keepTtl();
108
jedis.set("existing_key", "new_value", keepTtlParams);
109
110
// Atomic get-and-set operation
111
SetParams getSetParams = SetParams.setParams().get();
112
String previousValue = jedis.set("counter_backup", "new_counter", getSetParams);
113
114
jedis.close();
115
```
116
117
### GetExParams
118
119
Parameters for GETEX command to get value and optionally set expiration.
120
121
```java { .api }
122
public class GetExParams implements IParams {
123
/**
124
* Set expiration in seconds
125
* @param seconds Seconds until expiration
126
* @return GetExParams instance
127
*/
128
public GetExParams ex(long seconds);
129
130
/**
131
* Set expiration in milliseconds
132
* @param milliseconds Milliseconds until expiration
133
* @return GetExParams instance
134
*/
135
public GetExParams px(long milliseconds);
136
137
/**
138
* Set expiration at Unix timestamp (seconds)
139
* @param unixTime Unix timestamp in seconds
140
* @return GetExParams instance
141
*/
142
public GetExParams exAt(long unixTime);
143
144
/**
145
* Set expiration at Unix timestamp (milliseconds)
146
* @param unixTimeInMillis Unix timestamp in milliseconds
147
* @return GetExParams instance
148
*/
149
public GetExParams pxAt(long unixTimeInMillis);
150
151
/**
152
* Remove expiration (make key persistent)
153
* @return GetExParams instance
154
*/
155
public GetExParams persist();
156
}
157
```
158
159
## Scan Parameters
160
161
### ScanParams
162
163
Parameters for SCAN family commands (SCAN, HSCAN, SSCAN, ZSCAN).
164
165
```java { .api }
166
public class ScanParams implements IParams {
167
/**
168
* Set pattern match filter
169
* @param pattern Glob-style pattern (supports *, ?, [abc])
170
* @return ScanParams instance
171
*/
172
public ScanParams match(String pattern);
173
174
/**
175
* Set count hint for number of elements to return per iteration
176
* @param count Number of elements hint
177
* @return ScanParams instance
178
*/
179
public ScanParams count(int count);
180
181
/**
182
* Filter by key type (for SCAN command)
183
* @param type Redis key type (string, list, set, zset, hash, stream)
184
* @return ScanParams instance
185
*/
186
public ScanParams type(String type);
187
188
/**
189
* Static factory method
190
* @return New ScanParams instance
191
*/
192
public static ScanParams scanParams();
193
}
194
```
195
196
#### Usage Example
197
198
```java
199
// Scan keys with pattern matching
200
ScanParams userKeysParams = ScanParams.scanParams()
201
.match("user:*")
202
.count(100);
203
204
String cursor = "0";
205
do {
206
ScanResult<String> scanResult = jedis.scan(cursor, userKeysParams);
207
cursor = scanResult.getCursor();
208
209
for (String key : scanResult.getResult()) {
210
System.out.println("Found user key: " + key);
211
}
212
} while (!cursor.equals("0"));
213
214
// Scan hash fields
215
ScanParams hashParams = ScanParams.scanParams()
216
.match("*_count")
217
.count(50);
218
219
cursor = "0";
220
do {
221
ScanResult<Map.Entry<String, String>> hashScan =
222
jedis.hscan("statistics", cursor, hashParams);
223
cursor = hashScan.getCursor();
224
225
for (Map.Entry<String, String> entry : hashScan.getResult()) {
226
System.out.println(entry.getKey() + " = " + entry.getValue());
227
}
228
} while (!cursor.equals("0"));
229
```
230
231
## Sorted Set Parameters
232
233
### ZAddParams
234
235
Parameters for ZADD command with various options.
236
237
```java { .api }
238
public class ZAddParams implements IParams {
239
/**
240
* Set only if member doesn't exist
241
* @return ZAddParams instance
242
*/
243
public ZAddParams nx();
244
245
/**
246
* Set only if member exists (update existing)
247
* @return ZAddParams instance
248
*/
249
public ZAddParams xx();
250
251
/**
252
* Return changed count instead of added count
253
* @return ZAddParams instance
254
*/
255
public ZAddParams ch();
256
257
/**
258
* Increment score instead of setting it
259
* @return ZAddParams instance
260
*/
261
public ZAddParams incr();
262
263
/**
264
* Greater than - only update if new score is greater
265
* @return ZAddParams instance
266
*/
267
public ZAddParams gt();
268
269
/**
270
* Less than - only update if new score is less
271
* @return ZAddParams instance
272
*/
273
public ZAddParams lt();
274
}
275
```
276
277
### ZRangeParams
278
279
Parameters for ZRANGE command variants.
280
281
```java { .api }
282
public class ZRangeParams implements IParams {
283
/**
284
* Return elements in reverse order
285
* @return ZRangeParams instance
286
*/
287
public ZRangeParams rev();
288
289
/**
290
* Limit results with offset and count
291
* @param offset Result offset
292
* @param count Result count
293
* @return ZRangeParams instance
294
*/
295
public ZRangeParams limit(long offset, long count);
296
297
/**
298
* Range by score instead of rank
299
* @return ZRangeParams instance
300
*/
301
public ZRangeParams byScore();
302
303
/**
304
* Range by lexicographical order
305
* @return ZRangeParams instance
306
*/
307
public ZRangeParams byLex();
308
309
/**
310
* Include scores in results
311
* @return ZRangeParams instance
312
*/
313
public ZRangeParams withScores();
314
}
315
```
316
317
### ZParams
318
319
Parameters for sorted set operations like ZUNIONSTORE and ZINTERSTORE.
320
321
```java { .api }
322
public class ZParams implements IParams {
323
/**
324
* Set weights for input sets
325
* @param weights Array of weight values
326
* @return ZParams instance
327
*/
328
public ZParams weights(double... weights);
329
330
/**
331
* Set aggregation function
332
* @param aggregate Aggregation function (SUM, MIN, MAX)
333
* @return ZParams instance
334
*/
335
public ZParams aggregate(Aggregate aggregate);
336
337
public enum Aggregate {
338
SUM, MIN, MAX
339
}
340
}
341
```
342
343
#### Usage Example
344
345
```java
346
// Add elements with conditional logic
347
ZAddParams conditionalAdd = new ZAddParams().nx().ch();
348
Long changed = jedis.zadd("leaderboard", Map.of("player1", 100.0), conditionalAdd);
349
350
// Update existing members only
351
ZAddParams updateOnly = new ZAddParams().xx().ch();
352
jedis.zadd("leaderboard", Map.of("player1", 150.0), updateOnly);
353
354
// Increment score
355
ZAddParams increment = new ZAddParams().incr();
356
Double newScore = jedis.zadd("leaderboard", Map.of("player1", 10.0), increment);
357
358
// Range with score filtering and limits
359
ZRangeParams rangeParams = new ZRangeParams()
360
.byScore()
361
.withScores()
362
.limit(0, 10);
363
364
List<Tuple> topPlayers = jedis.zrangeWithScores("leaderboard", 90, 200, rangeParams);
365
366
// Union multiple sorted sets with weights
367
ZParams unionParams = new ZParams()
368
.weights(2.0, 1.0) // Weight first set 2x, second 1x
369
.aggregate(ZParams.Aggregate.MAX);
370
371
jedis.zunionstore("combined_scores", unionParams, "leaderboard1", "leaderboard2");
372
```
373
374
## Geospatial Parameters
375
376
### GeoAddParams
377
378
Parameters for GEOADD command.
379
380
```java { .api }
381
public class GeoAddParams implements IParams {
382
/**
383
* Add only if member doesn't exist
384
* @return GeoAddParams instance
385
*/
386
public GeoAddParams nx();
387
388
/**
389
* Update only if member exists
390
* @return GeoAddParams instance
391
*/
392
public GeoAddParams xx();
393
394
/**
395
* Return changed count
396
* @return GeoAddParams instance
397
*/
398
public GeoAddParams ch();
399
}
400
```
401
402
### GeoRadiusParam
403
404
Parameters for GEORADIUS and GEORADIUSBYMEMBER commands.
405
406
```java { .api }
407
public class GeoRadiusParam implements IParams {
408
/**
409
* Include coordinates in results
410
* @return GeoRadiusParam instance
411
*/
412
public GeoRadiusParam withCoord();
413
414
/**
415
* Include distances in results
416
* @return GeoRadiusParam instance
417
*/
418
public GeoRadiusParam withDist();
419
420
/**
421
* Include geohash values in results
422
* @return GeoRadiusParam instance
423
*/
424
public GeoRadiusParam withHash();
425
426
/**
427
* Limit number of results
428
* @param count Maximum results
429
* @return GeoRadiusParam instance
430
*/
431
public GeoRadiusParam count(int count);
432
433
/**
434
* Sort results ascending by distance
435
* @return GeoRadiusParam instance
436
*/
437
public GeoRadiusParam sortAscending();
438
439
/**
440
* Sort results descending by distance
441
* @return GeoRadiusParam instance
442
*/
443
public GeoRadiusParam sortDescending();
444
445
/**
446
* Static factory method
447
* @return New GeoRadiusParam instance
448
*/
449
public static GeoRadiusParam geoRadiusParam();
450
}
451
```
452
453
### GeoSearchParam
454
455
Parameters for GEOSEARCH command (Redis 6.2+).
456
457
```java { .api }
458
public class GeoSearchParam implements IParams {
459
/**
460
* Search from specific coordinates
461
* @param longitude Longitude coordinate
462
* @param latitude Latitude coordinate
463
* @return GeoSearchParam instance
464
*/
465
public GeoSearchParam fromLonLat(double longitude, double latitude);
466
467
/**
468
* Search from existing member location
469
* @param member Member name
470
* @return GeoSearchParam instance
471
*/
472
public GeoSearchParam fromMember(String member);
473
474
/**
475
* Search within radius
476
* @param radius Search radius
477
* @param unit Distance unit
478
* @return GeoSearchParam instance
479
*/
480
public GeoSearchParam byRadius(double radius, GeoUnit unit);
481
482
/**
483
* Search within rectangle box
484
* @param width Box width
485
* @param height Box height
486
* @param unit Distance unit
487
* @return GeoSearchParam instance
488
*/
489
public GeoSearchParam byBox(double width, double height, GeoUnit unit);
490
491
/**
492
* Sort results ascending
493
* @return GeoSearchParam instance
494
*/
495
public GeoSearchParam asc();
496
497
/**
498
* Sort results descending
499
* @return GeoSearchParam instance
500
*/
501
public GeoSearchParam desc();
502
503
/**
504
* Limit result count
505
* @param count Maximum results
506
* @return GeoSearchParam instance
507
*/
508
public GeoSearchParam count(int count);
509
510
/**
511
* Include coordinates in results
512
* @return GeoSearchParam instance
513
*/
514
public GeoSearchParam withCoord();
515
516
/**
517
* Include distances in results
518
* @return GeoSearchParam instance
519
*/
520
public GeoSearchParam withDist();
521
522
/**
523
* Include geohash in results
524
* @return GeoSearchParam instance
525
*/
526
public GeoSearchParam withHash();
527
}
528
```
529
530
#### Usage Example
531
532
```java
533
// Add locations with conditions
534
Map<String, GeoCoordinate> locations = Map.of(
535
"store1", new GeoCoordinate(-122.4194, 37.7749), // San Francisco
536
"store2", new GeoCoordinate(-118.2437, 34.0522) // Los Angeles
537
);
538
539
GeoAddParams addParams = new GeoAddParams().nx().ch();
540
Long added = jedis.geoadd("stores", addParams, locations);
541
542
// Search for stores within radius with full information
543
GeoRadiusParam radiusParam = GeoRadiusParam.geoRadiusParam()
544
.withCoord()
545
.withDist()
546
.withHash()
547
.count(10)
548
.sortAscending();
549
550
List<GeoRadiusResponse> nearbyStores = jedis.georadius("stores",
551
-122.0, 37.5, 100, GeoUnit.MI, radiusParam);
552
553
for (GeoRadiusResponse store : nearbyStores) {
554
System.out.println("Store: " + store.getMemberByString());
555
System.out.println("Distance: " + store.getDistance() + " miles");
556
System.out.println("Coordinates: " + store.getCoordinate());
557
}
558
559
// Modern GEOSEARCH (Redis 6.2+)
560
GeoSearchParam searchParam = new GeoSearchParam()
561
.fromLonLat(-122.4194, 37.7749)
562
.byRadius(50, GeoUnit.MI)
563
.withDist()
564
.withCoord()
565
.asc()
566
.count(5);
567
568
List<GeoRadiusResponse> searchResults = jedis.geosearch("stores", searchParam);
569
```
570
571
## Stream Parameters
572
573
### XAddParams
574
575
Parameters for Redis Streams XADD command.
576
577
```java { .api }
578
public class XAddParams implements IParams {
579
/**
580
* Set maximum stream length
581
* @param maxLen Maximum number of entries
582
* @return XAddParams instance
583
*/
584
public XAddParams maxLen(long maxLen);
585
586
/**
587
* Set approximate maximum length for efficiency
588
* @param maxLen Approximate maximum entries
589
* @return XAddParams instance
590
*/
591
public XAddParams maxLen(long maxLen, boolean approximateLength);
592
593
/**
594
* Minimum ID for trimming
595
* @param minId Minimum entry ID to keep
596
* @return XAddParams instance
597
*/
598
public XAddParams minId(String minId);
599
600
/**
601
* Minimum ID with approximate trimming
602
* @param minId Minimum entry ID
603
* @param approximateLength Use approximate trimming
604
* @return XAddParams instance
605
*/
606
public XAddParams minId(String minId, boolean approximateLength);
607
608
/**
609
* Limit trimming operations for performance
610
* @param limit Maximum trimming operations
611
* @return XAddParams instance
612
*/
613
public XAddParams limit(long limit);
614
615
/**
616
* Add only if ID doesn't exist
617
* @return XAddParams instance
618
*/
619
public XAddParams nomkStream();
620
}
621
```
622
623
### XReadParams
624
625
Parameters for Redis Streams XREAD command.
626
627
```java { .api }
628
public class XReadParams implements IParams {
629
/**
630
* Set read count limit
631
* @param count Maximum entries to read per stream
632
* @return XReadParams instance
633
*/
634
public XReadParams count(int count);
635
636
/**
637
* Set blocking timeout
638
* @param block Timeout in milliseconds (0 for infinite)
639
* @return XReadParams instance
640
*/
641
public XReadParams block(long block);
642
}
643
```
644
645
### XReadGroupParams
646
647
Parameters for Redis Streams XREADGROUP command.
648
649
```java { .api }
650
public class XReadGroupParams implements IParams {
651
/**
652
* Set read count limit
653
* @param count Maximum entries per stream
654
* @return XReadGroupParams instance
655
*/
656
public XReadGroupParams count(int count);
657
658
/**
659
* Set blocking timeout
660
* @param block Timeout in milliseconds
661
* @return XReadGroupParams instance
662
*/
663
public XReadGroupParams block(long block);
664
665
/**
666
* Don't acknowledge messages automatically
667
* @return XReadGroupParams instance
668
*/
669
public XReadGroupParams noAck();
670
}
671
```
672
673
#### Usage Example
674
675
```java
676
// Add to stream with length limit and trimming
677
XAddParams addParams = new XAddParams()
678
.maxLen(10000, true) // Keep ~10K entries (approximate)
679
.limit(100); // Limit trimming operations
680
681
Map<String, String> fields = Map.of(
682
"user_id", "123",
683
"action", "login",
684
"timestamp", String.valueOf(System.currentTimeMillis())
685
);
686
687
StreamEntryID entryId = jedis.xadd("events", addParams, fields);
688
689
// Read from streams with blocking
690
XReadParams readParams = new XReadParams()
691
.count(10)
692
.block(5000); // Block up to 5 seconds
693
694
Map<String, StreamEntryID> streams = Map.of("events", StreamEntryID.LAST_ENTRY);
695
List<Map.Entry<String, List<StreamEntry>>> result = jedis.xread(readParams, streams);
696
697
// Consumer group reading
698
XReadGroupParams groupParams = new XReadGroupParams()
699
.count(5)
700
.block(1000)
701
.noAck();
702
703
List<Map.Entry<String, List<StreamEntry>>> messages =
704
jedis.xreadGroup("processors", "consumer1", groupParams, streams);
705
```
706
707
## List Parameters
708
709
### LPosParams
710
711
Parameters for Redis LPOS command to find element positions in lists.
712
713
```java { .api }
714
public class LPosParams implements IParams {
715
/**
716
* Find nth occurrence
717
* @param rank Occurrence rank (1-based, negative for reverse)
718
* @return LPosParams instance
719
*/
720
public LPosParams rank(int rank);
721
722
/**
723
* Return up to count positions
724
* @param count Maximum positions to return
725
* @return LPosParams instance
726
*/
727
public LPosParams count(int count);
728
729
/**
730
* Limit search to maxlen elements
731
* @param maxlen Maximum elements to examine
732
* @return LPosParams instance
733
*/
734
public LPosParams maxlen(int maxlen);
735
}
736
```
737
738
## Bit Operations Parameters
739
740
### BitPosParams
741
742
Parameters for Redis BITPOS command.
743
744
```java { .api }
745
public class BitPosParams implements IParams {
746
/**
747
* Set start position in bytes
748
* @param start Start byte position
749
* @return BitPosParams instance
750
*/
751
public BitPosParams start(long start);
752
753
/**
754
* Set end position in bytes
755
* @param end End byte position
756
* @return BitPosParams instance
757
*/
758
public BitPosParams end(long end);
759
760
/**
761
* Use bit-level addressing instead of byte-level
762
* @return BitPosParams instance
763
*/
764
public BitPosParams bit();
765
766
/**
767
* Use byte-level addressing (default)
768
* @return BitPosParams instance
769
*/
770
public BitPosParams byteParam();
771
}
772
```
773
774
## Server Management Parameters
775
776
### ClientKillParams
777
778
Parameters for Redis CLIENT KILL command.
779
780
```java { .api }
781
public class ClientKillParams implements IParams {
782
/**
783
* Kill client by address
784
* @param address Client address (host:port)
785
* @return ClientKillParams instance
786
*/
787
public ClientKillParams addr(String address);
788
789
/**
790
* Kill client by ID
791
* @param id Client ID
792
* @return ClientKillParams instance
793
*/
794
public ClientKillParams id(long id);
795
796
/**
797
* Kill clients of specific type
798
* @param type Client type
799
* @return ClientKillParams instance
800
*/
801
public ClientKillParams type(ClientType type);
802
803
/**
804
* Kill clients from specific user
805
* @param user Username
806
* @return ClientKillParams instance
807
*/
808
public ClientKillParams user(String user);
809
810
/**
811
* Skip calling client
812
* @return ClientKillParams instance
813
*/
814
public ClientKillParams skipMe();
815
}
816
```
817
818
### RestoreParams
819
820
Parameters for Redis RESTORE command.
821
822
```java { .api }
823
public class RestoreParams implements IParams {
824
/**
825
* Replace existing key
826
* @return RestoreParams instance
827
*/
828
public RestoreParams replace();
829
830
/**
831
* Don't replace existing key
832
* @return RestoreParams instance
833
*/
834
public RestoreParams absTtl();
835
836
/**
837
* Set idle time
838
* @param idleTime Idle time in seconds
839
* @return RestoreParams instance
840
*/
841
public RestoreParams idleTime(long idleTime);
842
843
/**
844
* Set frequency
845
* @param frequency LFU frequency value
846
* @return RestoreParams instance
847
*/
848
public RestoreParams freq(int frequency);
849
}
850
```
851
852
#### Usage Example
853
854
```java
855
// Find specific occurrences in list
856
LPosParams posParams = new LPosParams()
857
.rank(2) // Find 2nd occurrence
858
.count(3) // Return up to 3 positions
859
.maxlen(1000); // Search only first 1000 elements
860
861
List<Long> positions = jedis.lpos("mylist", "search_value", posParams);
862
863
// Bit operations with precise control
864
BitPosParams bitParams = new BitPosParams()
865
.start(10) // Start from byte 10
866
.end(50) // End at byte 50
867
.bit(); // Use bit-level addressing
868
869
Long bitPosition = jedis.bitpos("bitmap", true, bitParams);
870
871
// Kill specific client connections
872
ClientKillParams killParams = new ClientKillParams()
873
.type(ClientType.NORMAL)
874
.user("guest")
875
.skipMe();
876
877
Long killedClients = jedis.clientKill(killParams);
878
```
879
880
## Base Parameter Classes
881
882
### BaseSetExParams and BaseGetExParams
883
884
Base classes for SET-like and GET-like parameter operations.
885
886
```java { .api }
887
public abstract class BaseSetExParams implements IParams {
888
/**
889
* Set expiration in seconds
890
* @param seconds Expiration time
891
* @return Parameter instance
892
*/
893
protected abstract BaseSetExParams ex(long seconds);
894
895
/**
896
* Set expiration in milliseconds
897
* @param milliseconds Expiration time
898
* @return Parameter instance
899
*/
900
protected abstract BaseSetExParams px(long milliseconds);
901
902
/**
903
* Set expiration at Unix timestamp
904
* @param timestamp Unix timestamp in seconds
905
* @return Parameter instance
906
*/
907
protected abstract BaseSetExParams exAt(long timestamp);
908
909
/**
910
* Set expiration at Unix timestamp in milliseconds
911
* @param timestamp Unix timestamp in milliseconds
912
* @return Parameter instance
913
*/
914
protected abstract BaseSetExParams pxAt(long timestamp);
915
}
916
917
public abstract class BaseGetExParams implements IParams {
918
/**
919
* Get with expiration in seconds
920
* @param seconds Expiration time
921
* @return Parameter instance
922
*/
923
protected abstract BaseGetExParams ex(long seconds);
924
925
/**
926
* Get with expiration in milliseconds
927
* @param milliseconds Expiration time
928
* @return Parameter instance
929
*/
930
protected abstract BaseGetExParams px(long milliseconds);
931
932
/**
933
* Get with expiration at timestamp
934
* @param timestamp Unix timestamp
935
* @return Parameter instance
936
*/
937
protected abstract BaseGetExParams exAt(long timestamp);
938
939
/**
940
* Get with expiration at timestamp in milliseconds
941
* @param timestamp Unix timestamp in milliseconds
942
* @return Parameter instance
943
*/
944
protected abstract BaseGetExParams pxAt(long timestamp);
945
946
/**
947
* Remove expiration (persist)
948
* @return Parameter instance
949
*/
950
protected abstract BaseGetExParams persist();
951
}
952
```
953
954
## Parameter Usage Best Practices
955
956
### Fluent Interface Pattern
957
958
```java
959
// Chain parameters for readable configuration
960
SetParams sessionParams = SetParams.setParams()
961
.ex(1800) // 30 minutes
962
.nx() // Only if not exists
963
.get(); // Return previous value
964
965
String previousSession = jedis.set("session:" + userId, sessionData, sessionParams);
966
967
// Complex scan with multiple filters
968
ScanParams complexScan = ScanParams.scanParams()
969
.match("user:*:profile")
970
.type("hash")
971
.count(500);
972
973
// Geospatial search with all options
974
GeoSearchParam fullGeoSearch = new GeoSearchParam()
975
.fromLonLat(-122.4194, 37.7749)
976
.byRadius(25, GeoUnit.KM)
977
.withCoord()
978
.withDist()
979
.asc()
980
.count(20);
981
982
List<GeoRadiusResponse> locations = jedis.geosearch("locations", fullGeoSearch);
983
```
984
985
### Conditional Parameter Building
986
987
```java
988
public SetParams buildSetParams(boolean useExpiry, boolean onlyIfNotExists,
989
boolean getOldValue) {
990
SetParams params = SetParams.setParams();
991
992
if (useExpiry) {
993
params.ex(3600); // 1 hour
994
}
995
996
if (onlyIfNotExists) {
997
params.nx();
998
}
999
1000
if (getOldValue) {
1001
params.get();
1002
}
1003
1004
return params;
1005
}
1006
1007
// Usage
1008
SetParams dynamicParams = buildSetParams(true, false, true);
1009
String oldValue = jedis.set("dynamic_key", "new_value", dynamicParams);
1010
```
1011
1012
### Parameter Validation
1013
1014
```java
1015
public class ParameterValidator {
1016
public static ZAddParams validateZAddParams(ZAddParams params,
1017
boolean requireConditional) {
1018
if (requireConditional && params == null) {
1019
throw new IllegalArgumentException("ZAddParams required for conditional operations");
1020
}
1021
return params;
1022
}
1023
1024
public static ScanParams validateScanCount(ScanParams params, int maxCount) {
1025
if (params != null) {
1026
// Ensure reasonable count limits
1027
return params.count(Math.min(maxCount, 1000));
1028
}
1029
return ScanParams.scanParams().count(100);
1030
}
1031
}
1032
```
1033
1034
The parameter system in Jedis provides type-safe, fluent configuration for Redis commands while maintaining backward compatibility and performance. These parameter objects enable complex Redis operations to be expressed clearly and maintainably in Java code.