-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRedis.d
3889 lines (3543 loc) · 145 KB
/
Redis.d
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
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Hunt - A redis client library for D programming language.
*
* Copyright (C) 2018-2019 HuntLabs
*
* Website: https://www.huntlabs.net/
*
* Licensed under the Apache-2.0 License.
*
*/
module hunt.redis.Redis;
import hunt.redis.BinaryRedis;
import hunt.redis.BinaryRedisPubSub;
import hunt.redis.BitOP;
import hunt.redis.BitPosParams;
import hunt.redis.BuilderFactory;
import hunt.redis.Client;
import hunt.redis.ClusterReset;
import hunt.redis.GeoCoordinate;
import hunt.redis.GeoRadiusResponse;
import hunt.redis.GeoUnit;
import hunt.redis.HostAndPort;
import hunt.redis.ListPosition;
import hunt.redis.Module;
import hunt.redis.Pipeline;
import hunt.redis.Protocol;
import hunt.redis.RedisMonitor;
import hunt.redis.RedisPubSub;
import hunt.redis.RedisShardInfo;
import hunt.redis.ScanParams;
import hunt.redis.ScanResult;
import hunt.redis.SortingParams;
import hunt.redis.StreamEntry;
import hunt.redis.StreamEntryID;
import hunt.redis.StreamPendingEntry;
import hunt.redis.Transaction;
import hunt.redis.Tuple;
import hunt.redis.ZParams;
import hunt.redis.commands.AdvancedRedisCommands;
import hunt.redis.commands.BasicCommands;
import hunt.redis.commands.ClusterCommands;
import hunt.redis.commands.RedisCommands;
import hunt.redis.commands.ModuleCommands;
import hunt.redis.commands.MultiKeyCommands;
import hunt.redis.Protocol;
import hunt.redis.commands.ScriptingCommands;
import hunt.redis.commands.SentinelCommands;
import hunt.redis.params.ClientKillParams;
import hunt.redis.params.GeoRadiusParam;
import hunt.redis.params.MigrateParams;
import hunt.redis.params.SetParams;
import hunt.redis.params.ZAddParams;
import hunt.redis.params.ZIncrByParams;
import hunt.redis.util.SafeEncoder;
import hunt.redis.util.Slowlog;
import hunt.Byte;
import hunt.collection;
import hunt.Double;
import hunt.Long;
import hunt.Exceptions;
import hunt.logging.ConsoleLogger;
import hunt.net.util.HttpURI;
import std.conv;
/**
*
*/
class Redis : BinaryRedis, RedisCommands, MultiKeyCommands,
AdvancedRedisCommands, ScriptingCommands, BasicCommands,
ClusterCommands, SentinelCommands, ModuleCommands {
// protected RedisPoolAbstract dataSource = null;
this() {
super();
}
this(string host) {
super(host);
}
this(HostAndPort hp) {
super(hp);
}
this(string host, int port) {
super(host, port);
}
this(string host, int port, bool ssl) {
super(host, port, ssl);
}
// this(string host, int port, bool ssl,
// SSLSocketFactory sslSocketFactory, SSLParameters sslParameters,
// HostnameVerifier hostnameVerifier) {
// super(host, port, ssl, sslSocketFactory, sslParameters, hostnameVerifier);
// }
this(string host, int port, int timeout) {
super(host, port, timeout);
}
this(string host, int port, int timeout, bool ssl) {
super(host, port, timeout, ssl);
}
// this(string host, int port, int timeout, bool ssl,
// SSLSocketFactory sslSocketFactory, SSLParameters sslParameters,
// HostnameVerifier hostnameVerifier) {
// super(host, port, timeout, ssl, sslSocketFactory, sslParameters, hostnameVerifier);
// }
this(string host, int port, int connectionTimeout, int soTimeout) {
super(host, port, connectionTimeout, soTimeout);
}
this(string host, int port, int connectionTimeout, int soTimeout,
bool ssl) {
super(host, port, connectionTimeout, soTimeout, ssl);
}
// this(string host, int port, int connectionTimeout, int soTimeout,
// bool ssl, SSLSocketFactory sslSocketFactory, SSLParameters sslParameters,
// HostnameVerifier hostnameVerifier) {
// super(host, port, connectionTimeout, soTimeout, ssl, sslSocketFactory, sslParameters,
// hostnameVerifier);
// }
this(RedisShardInfo shardInfo) {
super(shardInfo);
}
this(HttpURI uri) {
super(uri);
}
// this(HttpURI uri, SSLSocketFactory sslSocketFactory, SSLParameters sslParameters,
// HostnameVerifier hostnameVerifier) {
// super(uri, sslSocketFactory, sslParameters, hostnameVerifier);
// }
this(HttpURI uri, int timeout) {
super(uri, timeout);
}
// this(HttpURI uri, int timeout, SSLSocketFactory sslSocketFactory,
// SSLParameters sslParameters, HostnameVerifier hostnameVerifier) {
// super(uri, timeout, sslSocketFactory, sslParameters, hostnameVerifier);
// }
this(HttpURI uri, int connectionTimeout, int soTimeout) {
super(uri, connectionTimeout, soTimeout);
}
// this(HttpURI uri, int connectionTimeout, int soTimeout,
// SSLSocketFactory sslSocketFactory, SSLParameters sslParameters,
// HostnameVerifier hostnameVerifier) {
// super(uri, connectionTimeout, soTimeout, sslSocketFactory, sslParameters, hostnameVerifier);
// }
/**
* Works same as <tt>ping()</tt> but returns argument message instead of <tt>PONG</tt>.
* @param message
* @return message
*/
string ping(string message) {
checkIsInMultiOrPipeline();
client.ping(message);
return client.getBulkReply();
}
alias ping = BinaryRedis.ping;
/**
* Set the string value as value of the key. The string can't be longer than 1073741824 bytes (1
* GB).
* <p>
* Time complexity: O(1)
* @param key
* @param value
* @return Status code reply
*/
string set(string key, string value) {
checkIsInMultiOrPipeline();
client.set(key, value);
return client.getStatusCodeReply();
}
alias set = BinaryRedis.set;
/**
* Set the string value as value of the key. The string can't be longer than 1073741824 bytes (1
* GB).
* @param key
* @param value
* @param params NX|XX, NX -- Only set the key if it does not already exist. XX -- Only set the
* key if it already exist. EX|PX, expire time units: EX = seconds; PX = milliseconds
* @return Status code reply
*/
string set(string key, string value, SetParams params) {
checkIsInMultiOrPipeline();
client.set(key, value, params);
return client.getStatusCodeReply();
}
/**
* Get the value of the specified key. If the key does not exist null is returned. If the value
* stored at key is not a string an error is returned because GET can only handle string values.
* <p>
* Time complexity: O(1)
* @param key
* @return Bulk reply
*/
string get(string key) {
checkIsInMultiOrPipeline();
client.get(key);
return client.getBulkReply();
}
alias get = BinaryRedis.get;
/**
* Test if the specified keys exist. The command returns the number of keys exist.
* Time complexity: O(N)
* @param keys
* @return Integer reply, specifically: an integer greater than 0 if one or more keys exist,
* 0 if none of the specified keys exist.
*/
Long exists(string[] keys...) {
checkIsInMultiOrPipeline();
client.exists(keys);
return client.getIntegerReply();
}
alias exists = BinaryRedis.exists;
/**
* Test if the specified key exists. The command returns true if the key exists, otherwise false is
* returned. Note that even keys set with an empty string as value will return true. Time
* complexity: O(1)
* @param key
* @return bool reply, true if the key exists, otherwise false
*/
// override
bool exists(string key) {
checkIsInMultiOrPipeline();
client.exists(key);
return client.getIntegerReply() == 1;
}
/**
* Remove the specified keys. If a given key does not exist no operation is performed for this
* key. The command returns the number of keys removed. Time complexity: O(1)
* @param keys
* @return Integer reply, specifically: an integer greater than 0 if one or more keys were removed
* 0 if none of the specified key existed
*/
Long del(string[] keys...) {
checkIsInMultiOrPipeline();
client.del(keys);
return client.getIntegerReply();
}
alias del = BinaryRedis.del;
Long del(string key) {
checkIsInMultiOrPipeline();
client.del(key);
return client.getIntegerReply();
}
/**
* This command is very similar to DEL: it removes the specified keys. Just like DEL a key is
* ignored if it does not exist. However the command performs the actual memory reclaiming in a
* different thread, so it is not blocking, while DEL is. This is where the command name comes
* from: the command just unlinks the keys from the keyspace. The actual removal will happen later
* asynchronously.
* <p>
* Time complexity: O(1) for each key removed regardless of its size. Then the command does O(N)
* work in a different thread in order to reclaim memory, where N is the number of allocations the
* deleted objects where composed of.
* @param keys
* @return Integer reply: The number of keys that were unlinked
*/
Long unlink(string[] keys...) {
checkIsInMultiOrPipeline();
client.unlink(keys);
return client.getIntegerReply();
}
alias unlink = BinaryRedis.unlink;
Long unlink(string key) {
client.unlink(key);
return client.getIntegerReply();
}
/**
* Return the type of the value stored at key in form of a string. The type can be one of "none",
* "string", "list", "set". "none" is returned if the key does not exist. Time complexity: O(1)
* @param key
* @return Status code reply, specifically: "none" if the key does not exist "string" if the key
* contains a string value "list" if the key contains a List value "set" if the key
* contains a Set value "zset" if the key contains a Sorted Set value "hash" if the key
* contains a Hash value
*/
string type(string key) {
checkIsInMultiOrPipeline();
client.type(key);
return client.getStatusCodeReply();
}
alias type = BinaryRedis.type;
Set!(string) keys(string pattern) {
checkIsInMultiOrPipeline();
client.keys(pattern);
return BuilderFactory.STRING_SET.build(cast(Object)client.getBinaryMultiBulkReply());
}
alias keys = BinaryRedis.keys;
/**
* Return a randomly selected key from the currently selected DB.
* <p>
* Time complexity: O(1)
* @return Singe line reply, specifically the randomly selected key or an empty string is the
* database is empty
*/
string randomKey() {
checkIsInMultiOrPipeline();
client.randomKey();
return client.getBulkReply();
}
/**
* Atomically renames the key oldkey to newkey. If the source and destination name are the same an
* error is returned. If newkey already exists it is overwritten.
* <p>
* Time complexity: O(1)
* @param oldkey
* @param newkey
* @return Status code repy
*/
string rename(string oldkey, string newkey) {
checkIsInMultiOrPipeline();
client.rename(oldkey, newkey);
return client.getStatusCodeReply();
}
alias rename = BinaryRedis.rename;
/**
* Rename oldkey into newkey but fails if the destination key newkey already exists.
* <p>
* Time complexity: O(1)
* @param oldkey
* @param newkey
* @return Integer reply, specifically: 1 if the key was renamed 0 if the target key already exist
*/
// override
Long renamenx(string oldkey, string newkey) {
checkIsInMultiOrPipeline();
client.renamenx(oldkey, newkey);
return client.getIntegerReply();
}
/**
* Set a timeout on the specified key. After the timeout the key will be automatically deleted by
* the server. A key with an associated timeout is said to be volatile in Redis terminology.
* <p>
* Volatile keys are stored on disk like the other keys, the timeout is persistent too like all the
* other aspects of the dataset. Saving a dataset containing expires and stopping the server does
* not stop the flow of time as Redis stores on disk the time when the key will no longer be
* available as Unix time, and not the remaining seconds.
* <p>
* Since Redis 2.1.3 you can update the value of the timeout of a key already having an expire
* set. It is also possible to undo the expire at all turning the key into a normal key using the
* {@link #persist(string) PERSIST} command.
* <p>
* Time complexity: O(1)
* @see <a href="http://redis.io/commands/expire">Expire Command</a>
* @param key
* @param seconds
* @return Integer reply, specifically: 1: the timeout was set. 0: the timeout was not set since
* the key already has an associated timeout (this may happen only in Redis versions <
* 2.1.3, Redis >= 2.1.3 will happily update the timeout), or the key does not exist.
*/
Long expire(string key, int seconds) {
checkIsInMultiOrPipeline();
client.expire(key, seconds);
return client.getIntegerReply();
}
alias expire = BinaryRedis.expire;
/**
* EXPIREAT works exactly like {@link #expire(string, int) EXPIRE} but instead to get the number of
* seconds representing the Time To Live of the key as a second argument (that is a relative way
* of specifying the TTL), it takes an absolute one in the form of a UNIX timestamp (Number of
* seconds elapsed since 1 Gen 1970).
* <p>
* EXPIREAT was introduced in order to implement the Append Only File persistence mode so that
* EXPIRE commands are automatically translated into EXPIREAT commands for the append only file.
* Of course EXPIREAT can also used by programmers that need a way to simply specify that a given
* key should expire at a given time in the future.
* <p>
* Since Redis 2.1.3 you can update the value of the timeout of a key already having an expire
* set. It is also possible to undo the expire at all turning the key into a normal key using the
* {@link #persist(string) PERSIST} command.
* <p>
* Time complexity: O(1)
* @see <a href="http://redis.io/commands/expire">Expire Command</a>
* @param key
* @param unixTime
* @return Integer reply, specifically: 1: the timeout was set. 0: the timeout was not set since
* the key already has an associated timeout (this may happen only in Redis versions <
* 2.1.3, Redis >= 2.1.3 will happily update the timeout), or the key does not exist.
*/
Long expireAt(string key, long unixTime) {
checkIsInMultiOrPipeline();
client.expireAt(key, unixTime);
return client.getIntegerReply();
}
alias expireAt = BinaryRedis.expireAt;
/**
* The TTL command returns the remaining time to live in seconds of a key that has an
* {@link #expire(string, int) EXPIRE} set. This introspection capability allows a Redis client to
* check how many seconds a given key will continue to be part of the dataset.
* @param key
* @return Integer reply, returns the remaining time to live in seconds of a key that has an
* EXPIRE. In Redis 2.6 or older, if the Key does not exists or does not have an
* associated expire, -1 is returned. In Redis 2.8 or newer, if the Key does not have an
* associated expire, -1 is returned or if the Key does not exists, -2 is returned.
*/
Long ttl(string key) {
checkIsInMultiOrPipeline();
client.ttl(key);
return client.getIntegerReply();
}
alias ttl = BinaryRedis.ttl;
/**
* Alters the last access time of a key(s). A key is ignored if it does not exist.
* Time complexity: O(N) where N is the number of keys that will be touched.
* @param keys
* @return Integer reply: The number of keys that were touched.
*/
Long touch(string[] keys...) {
checkIsInMultiOrPipeline();
client.touch(keys);
return client.getIntegerReply();
}
alias touch = BinaryRedis.touch;
Long touch(string key) {
checkIsInMultiOrPipeline();
client.touch(key);
return client.getIntegerReply();
}
alias touch = BinaryRedis.touch;
/**
* Move the specified key from the currently selected DB to the specified destination DB. Note
* that this command returns 1 only if the key was successfully moved, and 0 if the target key was
* already there or if the source key was not found at all, so it is possible to use MOVE as a
* locking primitive.
* @param key
* @param dbIndex
* @return Integer reply, specifically: 1 if the key was moved 0 if the key was not moved because
* already present on the target DB or was not found in the current DB.
*/
Long move(string key, int dbIndex) {
checkIsInMultiOrPipeline();
client.move(key, dbIndex);
return client.getIntegerReply();
}
alias move = BinaryRedis.move;
/**
* GETSET is an atomic set this value and return the old value command. Set key to the string
* value and return the old value stored at key. The string can't be longer than 1073741824 bytes
* (1 GB).
* <p>
* Time complexity: O(1)
* @param key
* @param value
* @return Bulk reply
*/
string getSet(string key, string value) {
checkIsInMultiOrPipeline();
client.getSet(key, value);
return client.getBulkReply();
}
alias getSet = BinaryRedis.getSet;
/**
* Get the values of all the specified keys. If one or more keys don't exist or is not of type
* string, a 'nil' value is returned instead of the value of the specified key, but the operation
* never fails.
* <p>
* Time complexity: O(1) for every key
* @param keys
* @return Multi bulk reply
*/
List!(string) mget(string[] keys...) {
checkIsInMultiOrPipeline();
client.mget(keys);
return client.getMultiBulkReply();
}
alias mget = BinaryRedis.mget;
/**
* SETNX works exactly like {@link #set(string, string) SET} with the only difference that if the
* key already exists no operation is performed. SETNX actually means "SET if Not eXists".
* <p>
* Time complexity: O(1)
* @param key
* @param value
* @return Integer reply, specifically: 1 if the key was set 0 if the key was not set
*/
Long setnx(string key, string value) {
checkIsInMultiOrPipeline();
client.setnx(key, value);
return client.getIntegerReply();
}
alias setnx = BinaryRedis.setnx;
/**
* The command is exactly equivalent to the following group of commands:
* {@link #set(string, string) SET} + {@link #expire(string, int) EXPIRE}. The operation is
* atomic.
* <p>
* Time complexity: O(1)
* @param key
* @param seconds
* @param value
* @return Status code reply
*/
string setex(string key, int seconds, string value) {
checkIsInMultiOrPipeline();
client.setex(key, seconds, value);
return client.getStatusCodeReply();
}
alias setex = BinaryRedis.setex;
/**
* Set the the respective keys to the respective values. MSET will replace old values with new
* values, while {@link #msetnx(string...) MSETNX} will not perform any operation at all even if
* just a single key already exists.
* <p>
* Because of this semantic MSETNX can be used in order to set different keys representing
* different fields of an unique logic object in a way that ensures that either all the fields or
* none at all are set.
* <p>
* Both MSET and MSETNX are atomic operations. This means that for instance if the keys A and B
* are modified, another client talking to Redis can either see the changes to both A and B at
* once, or no modification at all.
* @see #msetnx(string...)
* @param keysvalues
* @return Status code reply Basically +OK as MSET can't fail
*/
string mset(string[] keysvalues...) {
checkIsInMultiOrPipeline();
client.mset(keysvalues);
return client.getStatusCodeReply();
}
alias mset = BinaryRedis.mset;
/**
* Set the the respective keys to the respective values. {@link #mset(string...) MSET} will
* replace old values with new values, while MSETNX will not perform any operation at all even if
* just a single key already exists.
* <p>
* Because of this semantic MSETNX can be used in order to set different keys representing
* different fields of an unique logic object in a way that ensures that either all the fields or
* none at all are set.
* <p>
* Both MSET and MSETNX are atomic operations. This means that for instance if the keys A and B
* are modified, another client talking to Redis can either see the changes to both A and B at
* once, or no modification at all.
* @see #mset(string...)
* @param keysvalues
* @return Integer reply, specifically: 1 if the all the keys were set 0 if no key was set (at
* least one key already existed)
*/
Long msetnx(string[] keysvalues...) {
checkIsInMultiOrPipeline();
client.msetnx(keysvalues);
return client.getIntegerReply();
}
alias msetnx = BinaryRedis.msetnx;
/**
* IDECRBY work just like {@link #decr(string) INCR} but instead to decrement by 1 the decrement
* is integer.
* <p>
* INCR commands are limited to 64 bit signed integers.
* <p>
* Note: this is actually a string operation, that is, in Redis there are not "integer" types.
* Simply the string stored at the key is parsed as a base 10 64 bit signed integer, incremented,
* and then converted back as a string.
* <p>
* Time complexity: O(1)
* @see #incr(string)
* @see #decr(string)
* @see #incrBy(string, long)
* @param key
* @param decrement
* @return Integer reply, this commands will reply with the new value of key after the increment.
*/
Long decrBy(string key, long decrement) {
checkIsInMultiOrPipeline();
client.decrBy(key, decrement);
return client.getIntegerReply();
}
alias decrBy = BinaryRedis.decrBy;
/**
* Decrement the number stored at key by one. If the key does not exist or contains a value of a
* wrong type, set the key to the value of "0" before to perform the decrement operation.
* <p>
* INCR commands are limited to 64 bit signed integers.
* <p>
* Note: this is actually a string operation, that is, in Redis there are not "integer" types.
* Simply the string stored at the key is parsed as a base 10 64 bit signed integer, incremented,
* and then converted back as a string.
* <p>
* Time complexity: O(1)
* @see #incr(string)
* @see #incrBy(string, long)
* @see #decrBy(string, long)
* @param key
* @return Integer reply, this commands will reply with the new value of key after the increment.
*/
Long decr(string key) {
checkIsInMultiOrPipeline();
client.decr(key);
return client.getIntegerReply();
}
alias decr = BinaryRedis.decr;
/**
* INCRBY work just like {@link #incr(string) INCR} but instead to increment by 1 the increment is
* integer.
* <p>
* INCR commands are limited to 64 bit signed integers.
* <p>
* Note: this is actually a string operation, that is, in Redis there are not "integer" types.
* Simply the string stored at the key is parsed as a base 10 64 bit signed integer, incremented,
* and then converted back as a string.
* <p>
* Time complexity: O(1)
* @see #incr(string)
* @see #decr(string)
* @see #decrBy(string, long)
* @param key
* @param increment
* @return Integer reply, this commands will reply with the new value of key after the increment.
*/
Long incrBy(string key, long increment) {
checkIsInMultiOrPipeline();
client.incrBy(key, increment);
return client.getIntegerReply();
}
alias incrBy = BinaryRedis.incrBy;
/**
* INCRBYFLOAT
* <p>
* INCRBYFLOAT commands are limited to double precision floating point values.
* <p>
* Note: this is actually a string operation, that is, in Redis there are not "double" types.
* Simply the string stored at the key is parsed as a base double precision floating point value,
* incremented, and then converted back as a string. There is no DECRYBYFLOAT but providing a
* negative value will work as expected.
* <p>
* Time complexity: O(1)
* @param key
* @param increment
* @return Double reply, this commands will reply with the new value of key after the increment.
*/
Double incrByFloat(string key, double increment) {
checkIsInMultiOrPipeline();
client.incrByFloat(key, increment);
string dval = client.getBulkReply();
return (dval !is null ? new Double(dval) : null);
}
alias incrByFloat = BinaryRedis.incrByFloat;
/**
* Increment the number stored at key by one. If the key does not exist or contains a value of a
* wrong type, set the key to the value of "0" before to perform the increment operation.
* <p>
* INCR commands are limited to 64 bit signed integers.
* <p>
* Note: this is actually a string operation, that is, in Redis there are not "integer" types.
* Simply the string stored at the key is parsed as a base 10 64 bit signed integer, incremented,
* and then converted back as a string.
* <p>
* Time complexity: O(1)
* @see #incrBy(string, long)
* @see #decr(string)
* @see #decrBy(string, long)
* @param key
* @return Integer reply, this commands will reply with the new value of key after the increment.
*/
Long incr(string key) {
checkIsInMultiOrPipeline();
client.incr(key);
return client.getIntegerReply();
}
alias incr = BinaryRedis.incr;
/**
* If the key already exists and is a string, this command appends the provided value at the end
* of the string. If the key does not exist it is created and set as an empty string, so APPEND
* will be very similar to SET in this special case.
* <p>
* Time complexity: O(1). The amortized time complexity is O(1) assuming the appended value is
* small and the already present value is of any size, since the dynamic string library used by
* Redis will double the free space available on every reallocation.
* @param key
* @param value
* @return Integer reply, specifically the total length of the string after the append operation.
*/
Long append(string key, string value) {
checkIsInMultiOrPipeline();
client.append(key, value);
return client.getIntegerReply();
}
alias append = BinaryRedis.append;
/**
* Return a subset of the string from offset start to offset end (both offsets are inclusive).
* Negative offsets can be used in order to provide an offset starting from the end of the string.
* So -1 means the last char, -2 the penultimate and so forth.
* <p>
* The function handles out of range requests without raising an error, but just limiting the
* resulting range to the actual length of the string.
* <p>
* Time complexity: O(start+n) (with start being the start index and n the total length of the
* requested range). Note that the lookup part of this command is O(1) so for small strings this
* is actually an O(1) command.
* @param key
* @param start
* @param end
* @return Bulk reply
*/
string substr(string key, int start, int end) {
checkIsInMultiOrPipeline();
client.substr(key, start, end);
return client.getBulkReply();
}
alias substr = BinaryRedis.substr;
/**
* Set the specified hash field to the specified value.
* <p>
* If key does not exist, a new key holding a hash is created.
* <p>
* <b>Time complexity:</b> O(1)
* @param key
* @param field
* @param value
* @return If the field already exists, and the HSET just produced an update of the value, 0 is
* returned, otherwise if a new field is created 1 is returned.
*/
Long hset(string key, string field, string value) {
checkIsInMultiOrPipeline();
client.hset(key, field, value);
return client.getIntegerReply();
}
alias hset = BinaryRedis.hset;
Long hset(string key, Map!(string, string) hash) {
checkIsInMultiOrPipeline();
client.hset(key, hash);
return client.getIntegerReply();
}
/**
* If key holds a hash, retrieve the value associated to the specified field.
* <p>
* If the field is not found or the key does not exist, a special 'nil' value is returned.
* <p>
* <b>Time complexity:</b> O(1)
* @param key
* @param field
* @return Bulk reply
*/
string hget(string key, string field) {
checkIsInMultiOrPipeline();
client.hget(key, field);
return client.getBulkReply();
}
alias hget = BinaryRedis.hget;
/**
* Set the specified hash field to the specified value if the field not exists. <b>Time
* complexity:</b> O(1)
* @param key
* @param field
* @param value
* @return If the field already exists, 0 is returned, otherwise if a new field is created 1 is
* returned.
*/
Long hsetnx(string key, string field, string value) {
checkIsInMultiOrPipeline();
client.hsetnx(key, field, value);
return client.getIntegerReply();
}
alias hsetnx = BinaryRedis.hsetnx;
/**
* Set the respective fields to the respective values. HMSET replaces old values with new values.
* <p>
* If key does not exist, a new key holding a hash is created.
* <p>
* <b>Time complexity:</b> O(N) (with N being the number of fields)
* @param key
* @param hash
* @return Return OK or Exception if hash is empty
*/
string hmset(string key, Map!(string, string) hash) {
checkIsInMultiOrPipeline();
client.hmset(key, hash);
return client.getStatusCodeReply();
}
alias hmset = BinaryRedis.hmset;
/**
* Retrieve the values associated to the specified fields.
* <p>
* If some of the specified fields do not exist, nil values are returned. Non existing keys are
* considered like empty hashes.
* <p>
* <b>Time complexity:</b> O(N) (with N being the number of fields)
* @param key
* @param fields
* @return Multi Bulk Reply specifically a list of all the values associated with the specified
* fields, in the same order of the request.
*/
List!(string) hmget(string key, string[] fields...) {
checkIsInMultiOrPipeline();
client.hmget(key, fields);
return client.getMultiBulkReply();
}
alias hmget = BinaryRedis.hmget;
/**
* Increment the number stored at field in the hash at key by value. If key does not exist, a new
* key holding a hash is created. If field does not exist or holds a string, the value is set to 0
* before applying the operation. Since the value argument is signed you can use this command to
* perform both increments and decrements.
* <p>
* The range of values supported by HINCRBY is limited to 64 bit signed integers.
* <p>
* <b>Time complexity:</b> O(1)
* @param key
* @param field
* @param value
* @return Integer reply The new value at field after the increment operation.
*/
Long hincrBy(string key, string field, long value) {
checkIsInMultiOrPipeline();
client.hincrBy(key, field, value);
return client.getIntegerReply();
}
alias hincrBy = BinaryRedis.hincrBy;
/**
* Increment the number stored at field in the hash at key by a double precision floating point
* value. If key does not exist, a new key holding a hash is created. If field does not exist or
* holds a string, the value is set to 0 before applying the operation. Since the value argument
* is signed you can use this command to perform both increments and decrements.
* <p>
* The range of values supported by HINCRBYFLOAT is limited to double precision floating point
* values.
* <p>
* <b>Time complexity:</b> O(1)
* @param key
* @param field
* @param value
* @return Double precision floating point reply The new value at field after the increment
* operation.
*/
Double hincrByFloat(string key, string field, double value) {
checkIsInMultiOrPipeline();
client.hincrByFloat(key, field, value);
string dval = client.getBulkReply();
return (dval !is null ? new Double(dval) : null);
}
alias hincrByFloat = BinaryRedis.hincrByFloat;
/**
* Test for existence of a specified field in a hash. <b>Time complexity:</b> O(1)
* @param key
* @param field
* @return Return true if the hash stored at key contains the specified field. Return false if the key is
* not found or the field is not present.
*/
// override
bool hexists(string key, string field) {
checkIsInMultiOrPipeline();
client.hexists(key, field);
return client.getIntegerReply() == 1;
}
alias hexists = BinaryRedis.hexists;
/**
* Remove the specified field from an hash stored at key.
* <p>
* <b>Time complexity:</b> O(1)
* @param key
* @param fields
* @return If the field was present in the hash it is deleted and 1 is returned, otherwise 0 is
* returned and no operation is performed.
*/
Long hdel(string key, string[] fields...) {
checkIsInMultiOrPipeline();
client.hdel(key, fields);
return client.getIntegerReply();
}
alias hdel = BinaryRedis.hdel;
/**
* Return the number of items in a hash.
* <p>
* <b>Time complexity:</b> O(1)
* @param key
* @return The number of entries (fields) contained in the hash stored at key. If the specified
* key does not exist, 0 is returned assuming an empty hash.
*/
Long hlen(string key) {
checkIsInMultiOrPipeline();
client.hlen(key);
return client.getIntegerReply();
}
alias hlen = BinaryRedis.hlen;
/**
* Return all the fields in a hash.
* <p>
* <b>Time complexity:</b> O(N), where N is the total number of entries
* @param key
* @return All the fields names contained into a hash.
*/
Set!(string) hkeys(string key) {
checkIsInMultiOrPipeline();
client.hkeys(key);
return BuilderFactory.STRING_SET.build(cast(Object)client.getBinaryMultiBulkReply());
}
alias hkeys = BinaryRedis.hkeys;
/**
* Return all the values in a hash.
* <p>
* <b>Time complexity:</b> O(N), where N is the total number of entries
* @param key
* @return All the fields values contained into a hash.
*/
List!(string) hvals(string key) {
checkIsInMultiOrPipeline();
client.hvals(key);
List!(string) lresult = client.getMultiBulkReply();
return lresult;
}
alias hvals = BinaryRedis.hvals;
/**
* Return all the fields and associated values in a hash.
* <p>
* <b>Time complexity:</b> O(N), where N is the total number of entries
* @param key
* @return All the fields and values contained into a hash.
*/
Map!(string, string) hgetAll(string key) {
checkIsInMultiOrPipeline();
client.hgetAll(key);
return BuilderFactory.STRING_MAP.build(cast(Object)client.getBinaryMultiBulkReply());
}
alias hgetAll = BinaryRedis.hgetAll;
/**
* Add the string value to the head (LPUSH) or tail (RPUSH) of the list stored at key. If the key
* does not exist an empty list is created just before the append operation. If the key exists but
* is not a List an error is returned.
* <p>
* Time complexity: O(1)
* @param key
* @param strings
* @return Integer reply, specifically, the number of elements inside the list after the push
* operation.
*/
Long rpush(string key, string[] strings...) {
checkIsInMultiOrPipeline();
client.rpush(key, strings);
return client.getIntegerReply();
}
alias rpush = BinaryRedis.rpush;