-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.go
3507 lines (2440 loc) · 121 KB
/
commands.go
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
package main
// This file is auto-generated by ./update
var Commands = map[string]Command{
"hdel": {"hdel", "Delete one or more hash fields", "key field [field ...]", "hash", "1.3.10", `@complexity
O(N) where N is the number of fields to be removed.
Removes the specified fields from the hash stored at 'key'. Specified fields
that do not exist within this hash are ignored.
If 'key' does not exist, it is treated as an empty hash and this command returns
'0'.
@return
@integer-reply: the number of fields that were removed from the hash, not including specified but non existing fields.
@history
* '>= 2.4': Accepts multiple 'field' arguments. Redis versions older than 2.4 can only remove a field per call.
To remove multiple fields from a hash in an atomic fashion in earlier
versions, use a 'MULTI'/'EXEC' block.
@examples
@cli
HSET myhash field1 "foo"
HDEL myhash field1
HDEL myhash field2`},
"srandmember": {"srandmember", "Get a random member from a set", "key", "set", "1.001", `@complexity
O(1)
Return a random element from the set value stored at 'key'.
This operation is similar to 'SPOP', however while 'SPOP' also removes the
randomly selected element from the set, 'SRANDMEMBER' will just return a random
element without altering the original set in any way.
@return
@bulk-reply: the randomly selected element, or 'nil' when 'key' does not exist.
@examples
@cli
SADD myset "one"
SADD myset "two"
SADD myset "three"
SRANDMEMBER myset`},
"smove": {"smove", "Move a member from one set to another", "source destination member", "set", "0.091", `@complexity
O(1)
Move 'member' from the set at 'source' to the set at 'destination'. This
operation is atomic. In every given moment the element will appear to be a
member of 'source' **or** 'destination' for other clients.
If the source set does not exist or does not contain the specified element, no
operation is performed and '0' is returned. Otherwise, the element is removed
from the source set and added to the destination set. When the specified
element already exists in the destination set, it is only removed from the
source set.
An error is returned if 'source' or 'destination' does not hold a set value.
@return
@integer-reply, specifically:
* '1' if the element is moved.
* '0' if the element is not a member of 'source' and no operation was performed.
@examples
@cli
SADD myset "one"
SADD myset "two"
SADD myotherset "three"
SMOVE myset myotherset "two"
SMEMBERS myset
SMEMBERS myotherset`},
"flushdb": {"flushdb", "Remove all keys from the current database", "-", "server", "0.07", `Delete all the keys of the currently selected DB. This command never fails.
@return
@status-reply`},
"srem": {"srem", "Remove one or more members from a set", "key member [member ...]", "set", "0.07", `@complexity
O(N) where N is the number of members to be removed.
Remove the specified members from the set stored at 'key'. Specified members
that are not a member of this set are ignored. If 'key' does not exist, it is
treated as an empty set and this command returns '0'.
An error is returned when the value stored at 'key' is not a set.
@return
@integer-reply: the number of members that were removed from the set, not including non existing members.
@history
* '>= 2.4': Accepts multiple 'member' arguments. Redis versions older than 2.4 can only remove a set member per call.
@examples
@cli
SADD myset "one"
SADD myset "two"
SADD myset "three"
SREM myset "one"
SREM myset "four"
SMEMBERS myset`},
"bgsave": {"bgsave", "Asynchronously save the dataset to disk", "-", "server", "0.07", `Save the DB in background. The OK code is immediately returned.
Redis forks, the parent continues to server the clients, the child
saves the DB on disk then exit. A client my be able to check if the
operation succeeded using the 'LASTSAVE' command.
@return
@status-reply`},
"brpoplpush": {"brpoplpush", "Pop a value from a list, push it to another list and return it; or block until one is available", "source destination timeout", "list", "2.1.7", `@complexity
O(1).
'BRPOPLPUSH' is the blocking variant of 'RPOPLPUSH'. When 'source'
contains elements, this command behaves exactly like 'RPOPLPUSH'. When
'source' is empty, Redis will block the connection until another client
pushes to it or until 'timeout' is reached. A 'timeout' of zero can be
used to block indefinitely.
See 'RPOPLPUSH' for more information.
@return
@bulk-reply: the element being popped from 'source' and pushed to
'destination'. If 'timeout' is reached, a @nil-reply is returned.`},
"lindex": {"lindex", "Get an element from a list by its index", "key index", "list", "0.07", `@complexity
O(N) where N is the number of elements to traverse to get to the element
at 'index'. This makes asking for the first or the last
element of the list O(1).
Returns the element at index 'index' in the list stored at 'key'.
The index is zero-based, so '0' means the first element, '1' the second
element and so on. Negative indices can be used to designate elements
starting at the tail of the list. Here, '-1' means the last element, '-2' means
the penultimate and so forth.
When the value at 'key' is not a list, an error is returned.
@return
@bulk-reply: the requested element, or 'nil' when 'index' is out of range.
@examples
@cli
LPUSH mylist "World"
LPUSH mylist "Hello"
LINDEX mylist 0
LINDEX mylist -1
LINDEX mylist 3`},
"hexists": {"hexists", "Determine if a hash field exists", "key field", "hash", "1.3.10", `@complexity
O(1)
Returns if 'field' is an existing field in the hash stored at 'key'.
@return
@integer-reply, specifically:
* '1' if the hash contains 'field'.
* '0' if the hash does not contain 'field', or 'key' does not exist.
@examples
@cli
HSET myhash field1 "foo"
HEXISTS myhash field1
HEXISTS myhash field2`},
"zrange": {"zrange", "Return a range of members in a sorted set, by index", "key start stop [WITHSCORES]", "sorted_set", "1.1", `@complexity
O(log(N)+M) with N being the number of elements in the sorted set and M the
number of elements returned.
Returns the specified range of elements in the sorted set stored at 'key'. The
elements are considered to be ordered from the lowest to the highest score.
Lexicographical order is used for elements with equal score.
See 'ZREVRANGE' when you need the elements ordered from highest to lowest
score (and descending lexicographical order for elements with equal score).
Both 'start' and 'stop' are zero-based indexes, where '0' is the first element,
'1' is the next element and so on. They can also be negative numbers indicating
offsets from the end of the sorted set, with '-1' being the last element of the
sorted set, '-2' the penultimate element and so on.
Out of range indexes will not produce an error. If 'start' is larger than the
largest index in the sorted set, or 'start > stop', an empty list is returned.
If 'stop' is larger than the end of the sorted set Redis will treat it like it
is the last element of the sorted set.
It is possible to pass the 'WITHSCORES' option in order to return the scores of
the elements together with the elements. The returned list will contain
'value1,score1,...,valueN,scoreN' instead of 'value1,...,valueN'. Client
libraries are free to return a more appropriate data type (suggestion: an array
with (value, score) arrays/tuples).
@return
@multi-bulk-reply: list of elements in the specified range (optionally with
their scores).
@examples
@cli
ZADD myzset 1 "one"
ZADD myzset 2 "two"
ZADD myzset 3 "three"
ZRANGE myzset 0 -1
ZRANGE myzset 2 3
ZRANGE myzset -2 -1`},
"setbit": {"setbit", "Sets or clears the bit at offset in the string value stored at key", "key offset value", "string", "2.1.8", `@complexity
O(1)
Sets or clears the bit at _offset_ in the string value stored at _key_.
The bit is either set or cleared depending on _value_, which can be either 0 or
1. When _key_ does not exist, a new string value is created. The string is
grown to make sure it can hold a bit at _offset_. The _offset_ argument is
required to be greater than or equal to 0, and smaller than 2^32 (this
limits bitmaps to 512MB). When the string at _key_ is grown, added
bits are set to 0.
**Warning**: When setting the last possible bit (_offset_ equal to 2^32 -1) and
the string value stored at _key_ does not yet hold a string value, or holds a
small string value, Redis needs to allocate all intermediate memory which can
block the server for some time. On a 2010 MacBook Pro, setting bit number
2^32 -1 (512MB allocation) takes ~300ms, setting bit number 2^30 -1 (128MB
allocation) takes ~80ms, setting bit number 2^28 -1 (32MB allocation) takes
~30ms and setting bit number 2^26 -1 (8MB allocation) takes ~8ms. Note that
once this first allocation is done, subsequent calls to 'SETBIT' for the same
_key_ will not have the allocation overhead.
@return
@integer-reply: the original bit value stored at _offset_.
@examples
@cli
SETBIT mykey 7 1
SETBIT mykey 7 0
GET mykey`},
"getbit": {"getbit", "Returns the bit value at offset in the string value stored at key", "key offset", "string", "2.1.8", `@complexity
O(1)
Returns the bit value at _offset_ in the string value stored at _key_.
When _offset_ is beyond the string length, the string is assumed to be a
contiguous space with 0 bits. When _key_ does not exist it is assumed to be an
empty string, so _offset_ is always out of range and the value is also assumed
to be a contiguous space with 0 bits.
@return
@integer-reply: the bit value stored at _offset_.
@examples
@cli
SETBIT mykey 7 1
GETBIT mykey 0
GETBIT mykey 7
GETBIT mykey 100`},
"watch": {"watch", "Watch the given keys to determine execution of the MULTI/EXEC block", "key [key ...]", "transactions", "2.1.0", `@complexity
O(1) for every key.
Marks the given keys to be watched for conditional execution of a [transaction](/topics/transactions).
@return
@status-reply: always 'OK'.`},
"keys": {"keys", "Find all keys matching the given pattern", "pattern", "generic", "0.07", `@complexity
O(N) with N being the number of keys in the database, under the assumption that
the key names in the database and the given pattern have limited length.
Returns all keys matching 'pattern'.
While the time complexity for this operation is O(N), the constant
times are fairly low. For example, Redis running on an entry level laptop can
scan a 1 million key database in 40 milliseconds.
**Warning**: consider 'KEYS' as a command that should only be used in
production environments with extreme care. It may ruin performance when it is
executed against large databases. This command is intended for debugging and
special operations, such as changing your keyspace layout. Don't use 'KEYS'
in your regular application code. If you're looking for a way to find keys in
a subset of your keyspace, consider using [sets](/topics/data-types#sets).
Supported glob-style patterns:
* 'h?llo' matches 'hello', 'hallo' and 'hxllo'
* 'h*llo' matches 'hllo' and 'heeeello'
* 'h[ae]llo' matches 'hello' and 'hallo,' but not 'hillo'
Use '\' to escape special characters if you want to match them verbatim.
@return
@multi-bulk-reply: list of keys matching 'pattern'.
@examples
@cli
MSET one 1 two 2 three 3 four 4
KEYS *o*
KEYS t??
KEYS *`},
"randomkey": {"randomkey", "Return a random key from the keyspace", "-", "generic", "0.07", `@complexity
O(1)
Return a random key from the currently selected database.
@return
@bulk-reply: the random key, or 'nil' when the database is empty.`},
"lpop": {"lpop", "Remove and get the first element in a list", "key", "list", "0.07", `@complexity
O(1)
Removes and returns the first element of the list stored at 'key'.
@return
@bulk-reply: the value of the first element, or 'nil' when 'key' does not exist.
@examples
@cli
RPUSH mylist "one"
RPUSH mylist "two"
RPUSH mylist "three"
LPOP mylist
LRANGE mylist 0 -1`},
"sadd": {"sadd", "Add one or more members to a set", "key member [member ...]", "set", "0.07", `@complexity
O(N) where N is the number of members to be added.
Add the specified members to the set stored at 'key'. Specified members that
are already a member of this set are ignored. If 'key' does not exist, a new
set is created before adding the specified members.
An error is returned when the value stored at 'key' is not a set.
@return
@integer-reply: the number of elements that were added to the set, not including all the elements already present into the set.
@history
* '>= 2.4': Accepts multiple 'member' arguments. Redis versions before 2.4 are only able to add a single member per call.
@examples
@cli
SADD myset "Hello"
SADD myset "World"
SADD myset "World"
SMEMBERS myset`},
"dbsize": {"dbsize", "Return the number of keys in the selected database", "-", "server", "0.07", `Return the number of keys in the currently selected database.
@return
@integer-reply`},
"rpushx": {"rpushx", "Append a value to a list, only if the list exists", "key value", "list", "2.1.1", `@complexity
O(1)
Inserts 'value' at the tail of the list stored at 'key', only if 'key'
already exists and holds a list. In contrary to 'RPUSH', no operation will
be performed when 'key' does not yet exist.
@return
@integer-reply: the length of the list after the push operation.
@examples
@cli
RPUSH mylist "Hello"
RPUSHX mylist "World"
RPUSHX myotherlist "World"
LRANGE mylist 0 -1
LRANGE myotherlist 0 -1`},
"zremrangebyscore": {"zremrangebyscore", "Remove all members in a sorted set within the given scores", "key min max", "sorted_set", "1.1", `@complexity
O(log(N)+M) with N being the number of elements in the sorted set and M the
number of elements removed by the operation.
Removes all elements in the sorted set stored at 'key' with a score between
'min' and 'max' (inclusive).
Since version 2.1.6, 'min' and 'max' can be exclusive, following the syntax of
'ZRANGEBYSCORE'.
@return
@integer-reply: the number of elements removed.
@examples
@cli
ZADD myzset 1 "one"
ZADD myzset 2 "two"
ZADD myzset 3 "three"
ZREMRANGEBYSCORE myzset -inf (2
ZRANGE myzset 0 -1 WITHSCORES`},
"bgrewriteaof": {"bgrewriteaof", "Asynchronously rewrite the append-only file", "-", "server", "1.07", `Rewrites the [append-only file](/topics/persistence#append-only-file) to reflect the current dataset in memory.
If 'BGREWRITEAOF' fails, no data gets lost as the old AOF will be untouched.
@return
@status-reply: always 'OK'.`},
"unwatch": {"unwatch", "Forget about all watched keys", "-", "transactions", "2.1.0", `@complexity
O(1).
Flushes all the previously watched keys for a [transaction](/topics/transactions).
If you call 'EXEC' or 'DISCARD', there's no need to manually call 'UNWATCH'.
@return
@status-reply: always 'OK'.`},
"lpush": {"lpush", "Prepend one or multiple values to a list", "key value [value ...]", "list", "0.07", `@complexity
O(1)
Insert all the specified values at the head of the list stored at 'key'.
If 'key' does not exist, it is created as empty list before performing
the push operations.
When 'key' holds a value that is not a list, an error is returned.
It is possible to push multiple elements using a single command call just specifying multiple arguments at the end of the command. Elements are inserted one after the other to the head of the list, from the leftmost element to the rightmost element. So for instance the command 'LPUSH mylist a b c' will result into a list containing 'c' as first element, 'b' as second element and 'a' as third element.
@return
@integer-reply: the length of the list after the push operations.
@history
* '>= 2.4': Accepts multiple 'value' arguments. In Redis versions older than 2.4 it was possible to push a single value per command.
@examples
@cli
LPUSH mylist "world"
LPUSH mylist "hello"
LRANGE mylist 0 -1`},
"append": {"append", "Append a value to a key", "key value", "string", "1.3.3", `@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.
If 'key' already exists and is a string, this command appends the 'value' at
the end of the string. If 'key' does not exist it is created and set as an
empty string, so 'APPEND' will be similar to 'SET' in this special case.
@return
@integer-reply: the length of the string after the append operation.
@examples
@cli
EXISTS mykey
APPEND mykey "Hello"
APPEND mykey " World"
GET mykey`},
"zincrby": {"zincrby", "Increment the score of a member in a sorted set", "key increment member", "sorted_set", "1.1", `@complexity
O(log(N)) where N is the number of elements in the sorted set.
Increments the score of 'member' in the sorted set stored at 'key' by
'increment'. If 'member' does not exist in the sorted set, it is added with
'increment' as its score (as if its previous score was '0.0'). If 'key' does
not exist, a new sorted set with the specified 'member' as its sole member is
created.
An error is returned when 'key' exists but does not hold a sorted set.
The 'score' value should be the string representation of a numeric value, and
accepts double precision floating point numbers. It is possible to provide a
negative value to decrement the score.
@return
@bulk-reply: the new score of 'member' (a double precision floating point
number), represented as string.
@examples
@cli
ZADD myzset 1 "one"
ZADD myzset 2 "two"
ZINCRBY myzset 2 "one"
ZRANGE myzset 0 -1 WITHSCORES`},
"zrevrank": {"zrevrank", "Determine the index of a member in a sorted set, with scores ordered from high to low", "key member", "sorted_set", "1.3.4", `@complexity
O(log(N))
Returns the rank of 'member' in the sorted set stored at 'key', with the scores
ordered from high to low. The rank (or index) is 0-based, which means that the
member with the highest score has rank '0'.
Use 'ZRANK' to get the rank of an element with the scores ordered from low to
high.
@return
* If 'member' exists in the sorted set, @integer-reply: the rank of 'member'.
* If 'member' does not exist in the sorted set or 'key' does not exist,
@bulk-reply: 'nil'.
@examples
@cli
ZADD myzset 1 "one"
ZADD myzset 2 "two"
ZADD myzset 3 "three"
ZREVRANK myzset "one"
ZREVRANK myzset "four"`},
"scard": {"scard", "Get the number of members in a set", "key", "set", "0.07", `@complexity
O(1)
Returns the set cardinality (number of elements) of the set stored at 'key'.
@return
@integer-reply: the cardinality (number of elements) of the set, or '0' if
'key' does not exist.
@examples
@cli
SADD myset "Hello"
SADD myset "World"
SCARD myset`},
"zrevrangebyscore": {"zrevrangebyscore", "Return a range of members in a sorted set, by score, with scores ordered from high to low", "key max min [WITHSCORES] [LIMIT offset count]", "sorted_set", "2.1.6", `@complexity
O(log(N)+M) with N being the number of elements in the sorted set and M the
number of elements being returned. If M is constant (e.g. always asking for the
first 10 elements with 'LIMIT'), you can consider it O(log(N)).
Returns all the elements in the sorted set at 'key' with a score between 'max'
and 'min' (including elements with score equal to 'max' or 'min'). In contrary
to the default ordering of sorted sets, for this command the elements are
considered to be ordered from high to low scores.
The elements having the same score are returned in reverse lexicographical order.
Apart from the reversed ordering, 'ZREVRANGEBYSCORE' is similar to
'ZRANGEBYSCORE'.
@return
@multi-bulk-reply: list of elements in the specified score range (optionally with
their scores).
@examples
@cli
ZADD myzset 1 "one"
ZADD myzset 2 "two"
ZADD myzset 3 "three"
ZREVRANGEBYSCORE myzset +inf -inf
ZREVRANGEBYSCORE myzset 2 1
ZREVRANGEBYSCORE myzset 2 (1
ZREVRANGEBYSCORE myzset (2 (1`},
"ltrim": {"ltrim", "Trim a list to the specified range", "key start stop", "list", "0.07", `@complexity
O(N) where N is the number of elements to be removed by the operation.
Trim an existing list so that it will contain only the specified range of
elements specified. Both 'start' and 'stop' are zero-based indexes, where '0'
is the first element of the list (the head), '1' the next element and so on.
For example: 'LTRIM foobar 0 2' will modify the list stored at 'foobar' so that
only the first three elements of the list will remain.
'start' and 'end' can also be negative numbers indicating offsets from the end
of the list, where '-1' is the last element of the list, '-2' the penultimate
element and so on.
Out of range indexes will not produce an error: if 'start' is larger than the
end of the list, or 'start > end', the result will be an empty list (which
causes 'key' to be removed). If 'end' is larger than the end of the list,
Redis will treat it like the last element of the list.
A common use of 'LTRIM' is together with 'LPUSH'/'RPUSH'. For example:
LPUSH mylist someelement
LTRIM mylist 0 99
This pair of commands will push a new element on the list, while making sure
that the list will not grow larger than 100 elements. This is very useful when
using Redis to store logs for example. It is important to note that when used
in this way 'LTRIM' is an O(1) operation because in the average case just one
element is removed from the tail of the list.
@return
@status-reply
@examples
@cli
RPUSH mylist "one"
RPUSH mylist "two"
RPUSH mylist "three"
LTRIM mylist 1 -1
LRANGE mylist 0 -1`},
"hkeys": {"hkeys", "Get all the fields in a hash", "key", "hash", "1.3.10", `@complexity
O(N) where N is the size of the hash.
Returns all field names in the hash stored at 'key'.
@return
@multi-bulk-reply: list of fields in the hash, or an empty list when 'key' does
not exist.
@examples
@cli
HSET myhash field1 "Hello"
HSET myhash field2 "World"
HKEYS myhash`},
"zremrangebyrank": {"zremrangebyrank", "Remove all members in a sorted set within the given indexes", "key start stop", "sorted_set", "1.3.4", `@complexity
O(log(N)+M) with N being the number of elements in the sorted set and M the
number of elements removed by the operation.
Removes all elements in the sorted set stored at 'key' with rank between
'start' and 'stop'. Both 'start' and 'stop' are '0'-based indexes with '0'
being the element with the lowest score. These indexes can be negative numbers,
where they indicate offsets starting at the element with the highest score. For
example: '-1' is the element with the highest score, '-2' the element with the
second highest score and so forth.
@return
@integer-reply: the number of elements removed.
@examples
@cli
ZADD myzset 1 "one"
ZADD myzset 2 "two"
ZADD myzset 3 "three"
ZREMRANGEBYRANK myzset 0 1
ZRANGE myzset 0 -1 WITHSCORES`},
"config resetstat": {"config resetstat", "Reset the stats returned by INFO", "-", "server", "2.0", `@complexity
O(1).
Resets the statistics reported by Redis using the 'INFO' command.
These are the counters that are reset:
* Keyspace hits
* Keyspace misses
* Number of commands processed
* Number of connections received
* Number of expired keys
@return
@status-reply: always 'OK'.`},
"lset": {"lset", "Set the value of an element in a list by its index", "key index value", "list", "0.07", `@complexity
O(N) where N is the length of the list. Setting either the first or the last
element of the list is O(1).
Sets the list element at 'index' to 'value'. For more information on the
'index' argument, see 'LINDEX'.
An error is returned for out of range indexes.
@return
@status-reply
@examples
@cli
RPUSH mylist "one"
RPUSH mylist "two"
RPUSH mylist "three"
LSET mylist 0 "four"
LSET mylist -2 "five"
LRANGE mylist 0 -1`},
"move": {"move", "Move a key to another database", "key db", "generic", "0.07", `@complexity
O(1)
Move 'key' from the currently selected database (see 'SELECT') to the specified
destination database. When 'key' already exists in the destination database, or
it does not exist in the source database, it does nothing. It is possible to
use 'MOVE' as a locking primitive because of this.
@return
@integer-reply, specifically:
* '1' if 'key' was moved.
* '0' if 'key' was not moved.`},
"getset": {"getset", "Set the string value of a key and return its old value", "key value", "string", "0.091", `@complexity
O(1)
Atomically sets 'key' to 'value' and returns the old value stored at 'key'.
Returns an error when 'key' exists but does not hold a string value.
## Design pattern
'GETSET' can be used together with 'INCR' for counting with atomic reset. For
example: a process may call 'INCR' against the key 'mycounter' every time some
event occurs, but from time to time we need to get the value of the counter and
reset it to zero atomically. This can be done using 'GETSET mycounter "0"':
@cli
INCR mycounter
GETSET mycounter "0"
GET mycounter
@return
@bulk-reply: the old value stored at 'key', or 'nil' when 'key' did not exist.
@examples
@cli
SET mykey "Hello"
GETSET mykey "World"
GET mykey`},
"set": {"set", "Set the string value of a key", "key value", "string", "0.07", `@complexity
O(1)
Set 'key' to hold the string 'value'. If 'key' already holds a value, it is
overwritten, regardless of its type.
@return
@status-reply: always 'OK' since 'SET' can't fail.
@examples
@cli
SET mykey "Hello"
GET mykey`},
"del": {"del", "Delete a key", "key [key ...]", "generic", "0.07", `@complexity
O(N) where N is the number of keys that will be removed. When a key to remove
holds a value other than a string, the individual complexity for this key is
O(M) where M is the number of elements in the list, set, sorted set or hash.
Removing a single key that holds a string value is O(1).
Removes the specified keys. A key is ignored if it does not exist.
@return
@integer-reply: The number of keys that were removed.
@examples
@cli
SET key1 "Hello"
SET key2 "World"
DEL key1 key2 key3`},
"strlen": {"strlen", "Get the length of the value stored in a key", "key", "string", "2.1.2", `@complexity
O(1)
Returns the length of the string value stored at 'key'.
An error is returned when 'key' holds a non-string value.
@return
@integer-reply: the length of the string at 'key', or '0' when 'key' does not exist.
@examples
@cli
SET mykey "Hello world"
STRLEN mykey
STRLEN nonexisting`},
"zrem": {"zrem", "Remove one or more members from a sorted set", "key member [member ...]", "sorted_set", "1.1", `@complexity
O(M log(N)) with N being the number of elements in the sorted set and M the number of elements to be removed.
Removes the specified members from the sorted set stored at 'key'. Non existing members are ignored.
An error is returned when 'key' exists and does not hold a sorted set.
@return
@integer-reply, specifically:
* The number of members removed from the sorted set, not including non existing members.
@history
* '>= 2.4': Accepts multiple elements. In Redis versions older than 2.4 it was possible to remove a single member per call.
@examples
@cli
ZADD myzset 1 "one"
ZADD myzset 2 "two"
ZADD myzset 3 "three"
ZREM myzset "two"
ZRANGE myzset 0 -1 WITHSCORES`},
"sunionstore": {"sunionstore", "Add multiple sets and store the resulting set in a key", "destination key [key ...]", "set", "0.091", `@complexity
O(N) where N is the total number of elements in all given sets.
This command is equal to 'SUNION', but instead of returning the resulting set,
it is stored in 'destination'.
If 'destination' already exists, it is overwritten.
@return
@integer-reply: the number of elements in the resulting set.`},
"persist": {"persist", "Remove the expiration from a key", "key", "generic", "2.1.2", `@complexity
O(1)
Remove the existing timeout on 'key'.
@return
@integer-reply, specifically:
* '1' if the timeout was removed.
* '0' if 'key' does not exist or does not have an associated timeout.
@examples
@cli
SET mykey "Hello"
EXPIRE mykey 10
TTL mykey
PERSIST mykey
TTL mykey`},
"config get": {"config get", "Get the value of a configuration parameter", "parameter", "server", "2.0", `@complexity
Not applicable.
@description
The 'CONFIG GET' command is used to read the configuration parameters of a running
Redis server. Not all the configuration parameters are supported.
The symmetric command used to alter the configuration at run time is
'CONFIG SET'.
'CONFIG GET' takes a single argument, that is glob style pattern. All the
configuration parameters matching this parameter are reported as a
list of key-value pairs. Example:
redis> config get *max-*-entries*
1) "hash-max-zipmap-entries"
2) "512"
3) "list-max-ziplist-entries"
4) "512"
5) "set-max-intset-entries"
6) "512"
You can obtain a list of all the supported configuration parameters typing
'CONFIG GET *' in an open 'redis-cli' prompt.
All the supported parameters have the same meaning of the equivalent
configuration parameter used in the [redis.conf](http://github.com/antirez/redis/raw/2.2/redis.conf) file, with the following important differences:
* Where bytes or other quantities are specified, it is not possible to use the redis.conf abbreviated form (10k 2gb ... and so forth), everything should be specified as a well formed 64 bit integer, in the base unit of the configuration directive.
* The save parameter is a single string of space separated integers. Every pair of integers represent a seconds/modifications threshold.
For instance what in redis.conf looks like:
save 900 1
save 300 10
that means, save after 900 seconds if there is at least 1 change to the
dataset, and after 300 seconds if there are at least 10 changes to the
datasets, will be reported by 'CONFIG GET' as "900 1 300 10".
@return
The return type of the command is a @bulk-reply.`},
"sinter": {"sinter", "Intersect multiple sets", "key [key ...]", "set", "0.07", `@complexity
O(N\*M) worst case where N is the cardinality of the smallest set and M is the
number of sets.
Returns the members of the set resulting from the intersection of all the given
sets.
For example:
key1 = {a,b,c,d}
key2 = {c}
key3 = {a,c,e}
SINTER key1 key2 key3 = {c}
Keys that do not exist are considered to be empty sets. With one of the keys
being an empty set, the resulting set is also empty (since set intersection
with an empty set always results in an empty set).
@return
@multi-bulk-reply: list with members of the resulting set.
@examples
@cli
SADD key1 "a"
SADD key1 "b"
SADD key1 "c"
SADD key2 "c"
SADD key2 "d"
SADD key2 "e"
SINTER key1 key2`},
"renamenx": {"renamenx", "Rename a key, only if the new key does not exist", "key newkey", "generic", "0.07", `@complexity
O(1)
Renames 'key' to 'newkey' if 'newkey' does not yet exist.
It returns an error under the same conditions as 'RENAME'.
@return
@integer-reply, specifically:
* '1' if 'key' was renamed to 'newkey'.
* '0' if 'newkey' already exists.
@examples
@cli
SET mykey "Hello"
SET myotherkey "World"
RENAMENX mykey myotherkey
GET myotherkey`},
"sismember": {"sismember", "Determine if a given value is a member of a set", "key member", "set", "0.07", `@complexity
O(1)
Returns if 'member' is a member of the set stored at 'key'.
@return