1Redis(3pm)            User Contributed Perl Documentation           Redis(3pm)
2
3
4

NAME

6       Redis - Perl binding for Redis database
7

VERSION

9       version 2.000
10

SYNOPSIS

12           ## Defaults to $ENV{REDIS_SERVER} or 127.0.0.1:6379
13           my $redis = Redis->new;
14
15           my $redis = Redis->new(server => 'redis.example.com:8080');
16
17           ## Set the connection name (requires Redis 2.6.9)
18           my $redis = Redis->new(
19             server => 'redis.example.com:8080',
20             name => 'my_connection_name',
21           );
22           my $generation = 0;
23           my $redis = Redis->new(
24             server => 'redis.example.com:8080',
25             name => sub { "cache-$$-".++$generation },
26           );
27
28           ## Use UNIX domain socket
29           my $redis = Redis->new(sock => '/path/to/socket');
30
31           ## Connect to Redis over a secure SSL/TLS channel.  See
32           ## IO::Socket::SSL documentation for more information
33           ## about SSL_verify_mode parameter.
34           my $redis = Redis->new(
35               server => 'redis.tls.example.com:8080',
36               ssl => 1,
37               SSL_verify_mode => SSL_VERIFY_PEER,
38           );
39
40           ## Enable auto-reconnect
41           ## Try to reconnect every 1s up to 60 seconds until success
42           ## Die if you can't after that
43           my $redis = Redis->new(reconnect => 60, every => 1_000_000);
44
45           ## Try each 100ms up to 2 seconds (every is in microseconds)
46           my $redis = Redis->new(reconnect => 2, every => 100_000);
47
48           ## Enable connection timeout (in seconds)
49           my $redis = Redis->new(cnx_timeout => 60);
50
51           ## Enable read timeout (in seconds)
52           my $redis = Redis->new(read_timeout => 0.5);
53
54           ## Enable write timeout (in seconds)
55           my $redis = Redis->new(write_timeout => 1.2);
56
57           ## Connect via a list of Sentinels to a given service
58           my $redis = Redis->new(sentinels => [ '127.0.0.1:12345' ], service => 'mymaster');
59
60           ## Same, but with connection, read and write timeout on the sentinel hosts
61           my $redis = Redis->new( sentinels => [ '127.0.0.1:12345' ], service => 'mymaster',
62                                   sentinels_cnx_timeout => 0.1,
63                                   sentinels_read_timeout => 1,
64                                   sentinels_write_timeout => 1,
65                                 );
66
67           ## Use all the regular Redis commands, they all accept a list of
68           ## arguments
69           ## See https://redis.io/commands for full list
70           $redis->get('key');
71           $redis->set('key' => 'value');
72           $redis->sort('list', 'DESC');
73           $redis->sort(qw{list LIMIT 0 5 ALPHA DESC});
74
75           ## Add a coderef argument to run a command in the background
76           $redis->sort(qw{list LIMIT 0 5 ALPHA DESC}, sub {
77             my ($reply, $error) = @_;
78             die "Oops, got an error: $error\n" if defined $error;
79             print "$_\n" for @$reply;
80           });
81           long_computation();
82           $redis->wait_all_responses;
83           ## or
84           $redis->wait_one_response();
85
86           ## Or run a large batch of commands in a pipeline
87           my %hash = _get_large_batch_of_commands();
88           $redis->hset('h', $_, $hash{$_}, sub {}) for keys %hash;
89           $redis->wait_all_responses;
90
91           ## Publish/Subscribe
92           $redis->subscribe(
93             'topic_1',
94             'topic_2',
95             sub {
96               my ($message, $topic, $subscribed_topic) = @_
97
98                 ## $subscribed_topic can be different from topic if
99                 ## you use psubscribe() with wildcards
100             }
101           );
102           $redis->psubscribe('nasdaq.*', sub {...});
103
104           ## Blocks and waits for messages, calls subscribe() callbacks
105           ##  ... forever
106           my $timeout = 10;
107           $redis->wait_for_messages($timeout) while 1;
108
109           ##  ... until some condition
110           my $keep_going = 1; ## other code will set to false to quit
111           $redis->wait_for_messages($timeout) while $keep_going;
112
113           $redis->publish('topic_1', 'message');
114

DESCRIPTION

116       Pure perl bindings for <https://redis.io/>
117
118       This version supports protocol 2.x (multi-bulk) or later of Redis
119       available at <https://github.com/antirez/redis/>.
120
121       This documentation lists commands which are exercised in test suite,
122       but additional commands will work correctly since protocol specifies
123       enough information to support almost all commands with same piece of
124       code with a little help of "AUTOLOAD".
125

PIPELINING

127       Usually, running a command will wait for a response.  However, if
128       you're doing large numbers of requests, it can be more efficient to use
129       what Redis calls pipelining: send multiple commands to Redis without
130       waiting for a response, then wait for the responses that come in.
131
132       To use pipelining, add a coderef argument as the last argument to a
133       command method call:
134
135         $r->set('foo', 'bar', sub {});
136
137       Pending responses to pipelined commands are processed in a single
138       batch, as soon as at least one of the following conditions holds:
139
140       •   A non-pipelined (synchronous) command is called on the same
141           connection
142
143       •   A pub/sub subscription command (one of "subscribe", "unsubscribe",
144           "psubscribe", or "punsubscribe") is about to be called on the same
145           connection.
146
147       •   One of "wait_all_responses" or "wait_one_response" methods is
148           called explicitly.
149
150       The coderef you supply to a pipelined command method is invoked once
151       the response is available.  It takes two arguments, $reply and $error.
152       If $error is defined, it contains the text of an error reply sent by
153       the Redis server.  Otherwise, $reply is the non-error reply. For almost
154       all commands, that means it's "undef", or a defined but non-reference
155       scalar, or an array ref of any of those; but see "keys", "info", and
156       "exec".
157
158       Note the contrast with synchronous commands, which throw an exception
159       on receipt of an error reply, or return a non-error reply directly.
160
161       The fact that pipelined commands never throw an exception can be
162       particularly useful for Redis transactions; see "exec".
163

ENCODING

165       There is no encoding feature anymore, it has been deprecated and
166       finally removed. This module consider that any data sent to the Redis
167       server is a binary data.  And it doesn't do anything when getting data
168       from the Redis server.
169
170       So, if you are working with character strings, you should pre-encode or
171       post-decode it if needed !
172

CONSTRUCTOR

174   new
175           my $r = Redis->new; # $ENV{REDIS_SERVER} or 127.0.0.1:6379
176
177           my $r = Redis->new( server => '192.168.0.1:6379', debug => 0 );
178           my $r = Redis->new( server => '192.168.0.1:6379', encoding => undef );
179           my $r = Redis->new( server => '192.168.0.1:6379', ssl => 1, SSL_verify_mode => SSL_VERIFY_PEER );
180           my $r = Redis->new( sock => '/path/to/sock' );
181           my $r = Redis->new( reconnect => 60, every => 5000 );
182           my $r = Redis->new( password => 'boo' );
183           my $r = Redis->new( on_connect => sub { my ($redis) = @_; ... } );
184           my $r = Redis->new( name => 'my_connection_name' );
185           my $r = Redis->new( name => sub { "cache-for-$$" });
186
187           my $redis = Redis->new(sentinels => [ '127.0.0.1:12345', '127.0.0.1:23456' ],
188                                  service => 'mymaster');
189
190           ## Connect via a list of Sentinels to a given service
191           my $redis = Redis->new(sentinels => [ '127.0.0.1:12345' ], service => 'mymaster');
192
193           ## Same, but with connection, read and write timeout on the sentinel hosts
194           my $redis = Redis->new( sentinels => [ '127.0.0.1:12345' ], service => 'mymaster',
195                                   sentinels_cnx_timeout => 0.1,
196                                   sentinels_read_timeout => 1,
197                                   sentinels_write_timeout => 1,
198                                 );
199
200       "server"
201
202       The "server" parameter specifies the Redis server we should connect to,
203       via TCP. Use the 'IP:PORT' format. If no "server" option is present, we
204       will attempt to use the "REDIS_SERVER" environment variable. If neither
205       of those options are present, it defaults to '127.0.0.1:6379'.
206
207       Alternatively you can use the "sock" parameter to specify the path of
208       the UNIX domain socket where the Redis server is listening.
209
210       Alternatively you can use the "sentinels" parameter and the "service"
211       parameter to specify a list of sentinels to contact and try to get the
212       address of the given service name. "sentinels" must be an ArrayRef and
213       "service" an Str.
214
215       The "REDIS_SERVER" can be used for UNIX domain sockets too. The
216       following formats are supported:
217
218       •   /path/to/sock
219
220       •   unix:/path/to/sock
221
222       •   127.0.0.1:11011
223
224       •   tcp:127.0.0.1:11011
225
226       "reconnect", "every"
227
228       The "reconnect" option enables auto-reconnection mode. If we cannot
229       connect to the Redis server, or if a network write fails, we enter
230       retry mode.  We will try a new connection every "every" microseconds (1
231       ms by default), up-to "reconnect" seconds.
232
233       Be aware that read errors will always thrown an exception, and will not
234       trigger a retry until the new command is sent.
235
236       If we cannot re-establish a connection after "reconnect" seconds, an
237       exception will be thrown.
238
239       "conservative_reconnect"
240
241       "conservative_reconnect" option makes sure that reconnection is only
242       attempted when no pending command is ongoing. For instance, if you're
243       doing "<$redis-"incr('key')>>, and if the server properly understood
244       and processed the command, but the network connection is dropped just
245       before the server replies : the command has been processed but the
246       client doesn't know it. In this situation, if reconnect is enabled, the
247       Redis client will reconnect and send the "incr" command *again*. If it
248       succeeds, at the end the key as been incremented *two* times. To avoid
249       this issue, you can set the "conservative_reconnect" option to a true
250       value. In this case, the client will reconnect only if no request is
251       pending. Otherwise it will die with the message: "reconnect disabled
252       while responses are pending and safe reconnect mode enabled".
253
254       "cnx_timeout"
255
256       The "cnx_timeout" option enables connection timeout. The Redis client
257       will wait at most that number of seconds (can be fractional) before
258       giving up connecting to a server.
259
260       "sentinels_cnx_timeout"
261
262       The "sentinels_cnx_timeout" option enables sentinel connection timeout.
263       When using the sentinels feature, Redis client will wait at most that
264       number of seconds (can be fractional) before giving up connecting to a
265       sentinel.  Default: 0.1
266
267       "read_timeout"
268
269       The "read_timeout" option enables read timeout. The Redis client will
270       wait at most that number of seconds (can be fractional) before giving
271       up when reading from the server.
272
273       "sentinels_read_timeout"
274
275       The "sentinels_read_timeout" option enables sentinel read timeout. When
276       using the sentinels feature, the Redis client will wait at most that
277       number of seconds (can be fractional) before giving up when reading
278       from a sentinel server. Default: 1
279
280       "write_timeout"
281
282       The "write_timeout" option enables write timeout. The Redis client will
283       wait at most that number of seconds (can be fractional) before giving
284       up when reading from the server.
285
286       "sentinels_write_timeout"
287
288       The "sentinels_write_timeout" option enables sentinel write timeout.
289       When using the sentinels feature, the Redis client will wait at most
290       that number of seconds (can be fractional) before giving up when
291       reading from a sentinel server. Default: 1
292
293       "password"
294
295       If your Redis server requires authentication, you can use the
296       "password" attribute. After each established connection (at the start
297       or when reconnecting), the Redis "AUTH" command will be send to the
298       server. If the password is wrong, an exception will be thrown and
299       reconnect will be disabled.
300
301       "on_connect"
302
303       You can also provide a code reference that will be immediately after
304       each successful connection. The "on_connect" attribute is used to
305       provide the code reference, and it will be called with the first
306       parameter being the Redis object.
307
308       "no_auto_connect_on_new"
309
310       You can also provide "no_auto_connect_on_new" in which case "new" won't
311       call "$obj->connect" for you implicitly, you'll have to do that
312       yourself. This is useful for figuring out how long connection setup
313       takes so you can configure the "cnx_timeout" appropriately.
314
315       "no_sentinels_list_update"
316
317       You can also provide "no_sentinels_list_update". By default (that is,
318       without this option), when successfully contacting a sentinel server,
319       the Redis client will ask it for the list of sentinels known for the
320       given service, and merge it with its list of sentinels (in the
321       "sentinels" attribute). You can disable this behavior by setting
322       "no_sentinels_list_update" to a true value.
323
324       "name"
325
326       You can also set a name for each connection. This can be very useful
327       for debugging purposes, using the "CLIENT LIST" command. To set a
328       connection name, use the "name" parameter. You can use both a scalar
329       value or a CodeRef. If the latter, it will be called after each
330       connection, with the Redis object, and it should return the connection
331       name to use. If it returns a undefined value, Redis will not set the
332       connection name.
333
334       Please note that there are restrictions on the name you can set, the
335       most important of which is, no spaces. See the CLIENT SETNAME
336       documentation <https://redis.io/commands/client-setname> for all the
337       juicy details. This feature is safe to use with all versions of Redis
338       servers. If "CLIENT SETNAME" support is not available (Redis servers
339       2.6.9 and above only), the name parameter is ignored.
340
341       "ssl"
342
343       You can connect to Redis over SSL/TLS by setting this flag if the
344       target Redis server or cluster has been setup to support SSL/TLS.  This
345       requires IO::Socket::SSL to be installed on the client.  It's off by
346       default.
347
348       "SSL_verify_mode"
349
350       This parameter will be applied when "ssl" flag is set.  It sets the
351       verification mode for the peer certificate.  It's compatible with the
352       parameter with the same name in IO::Socket::SSL.
353
354       "debug"
355
356       The "debug" parameter enables debug information to STDERR, including
357       all interactions with the server. You can also enable debug with the
358       "REDIS_DEBUG" environment variable.
359

CONNECTION HANDLING

361   connect
362         $r->connect;
363
364       Connects to the Redis server. This is done by default when the obect is
365       constructed using new(), unless "no_auto_connect_on_new" has been set.
366       See this option in the new() constructor.
367
368   quit
369         $r->quit;
370
371       Closes the connection to the server. The "quit" method does not support
372       pipelined operation.
373
374   ping
375         $r->ping || die "no server?";
376
377       The "ping" method does not support pipelined operation.
378

PIPELINE MANAGEMENT

380   wait_all_responses
381       Waits until all pending pipelined responses have been received, and
382       invokes the pipeline callback for each one.  See "PIPELINING".
383
384   wait_one_response
385       Waits until the first pending pipelined response has been received, and
386       invokes its callback.  See "PIPELINING".
387

PUBLISH/SUBSCRIBE COMMANDS

389       When one of "subscribe" or "psubscribe" is used, the Redis object will
390       enter PubSub mode. When in PubSub mode only commands in this section,
391       plus "quit", will be accepted.
392
393       If you plan on using PubSub and other Redis functions, you should use
394       two Redis objects, one dedicated to PubSub and the other for regular
395       commands.
396
397       All Pub/Sub commands receive a callback as the last parameter. This
398       callback receives three arguments:
399
400       •   The published message.
401
402       •   The topic over which the message was sent.
403
404       •   The subscribed topic that matched the topic for the message. With
405           "subscribe" these last two are the same, always. But with
406           "psubscribe", this parameter tells you the pattern that matched.
407
408       See the Pub-Sub notes <https://redis.io/topics/pubsub> for more
409       information about the messages you will receive on your callbacks after
410       each "subscribe", "unsubscribe", "psubscribe" and "punsubscribe".
411
412   publish
413         $r->publish($topic, $message);
414
415       Publishes the $message to the $topic.
416
417   subscribe
418         $r->subscribe(
419             @topics_to_subscribe_to,
420             my $savecallback = sub {
421               my ($message, $topic, $subscribed_topic) = @_;
422               ...
423             },
424         );
425
426       Subscribe one or more topics. Messages published into one of them will
427       be received by Redis, and the specified callback will be executed.
428
429   unsubscribe
430         $r->unsubscribe(@topic_list, $savecallback);
431
432       Stops receiving messages via $savecallback for all the topics in
433       @topic_list. WARNING: it is important that you give the same calleback
434       that you used for subscribtion. The value of the CodeRef must be the
435       same, as this is how internally the code identifies it.
436
437   psubscribe
438         my @topic_matches = ('prefix1.*', 'prefix2.*');
439         $r->psubscribe(@topic_matches, my $savecallback = sub { my ($m, $t, $s) = @_; ... });
440
441       Subscribes a pattern of topics. All messages to topics that match the
442       pattern will be delivered to the callback.
443
444   punsubscribe
445         my @topic_matches = ('prefix1.*', 'prefix2.*');
446         $r->punsubscribe(@topic_matches, $savecallback);
447
448       Stops receiving messages via $savecallback for all the topics pattern
449       matches in @topic_list. WARNING: it is important that you give the same
450       calleback that you used for subscribtion. The value of the CodeRef must
451       be the same, as this is how internally the code identifies it.
452
453   is_subscriber
454         if ($r->is_subscriber) { say "We are in Pub/Sub mode!" }
455
456       Returns true if we are in Pub/Sub mode.
457
458   wait_for_messages
459         my $keep_going = 1; ## Set to false somewhere to leave the loop
460         my $timeout = 5;
461         $r->wait_for_messages($timeout) while $keep_going;
462
463       Blocks, waits for incoming messages and delivers them to the
464       appropriate callbacks.
465
466       Requires a single parameter, the number of seconds to wait for
467       messages. Use 0 to wait for ever. If a positive non-zero value is used,
468       it will return after that amount of seconds without a single
469       notification.
470
471       Please note that the timeout is not a commitment to return control to
472       the caller at most each "timeout" seconds, but more a idle timeout,
473       were control will return to the caller if Redis is idle (as in no
474       messages were received during the timeout period) for more than
475       "timeout" seconds.
476
477       The "wait_for_messages" call returns the number of messages processed
478       during the run.
479

IMPORTANT NOTES ON METHODS

481   methods that return multiple values
482       When a method returns more than one value, it checks the context and
483       returns either a list of values or an ArrayRef.
484
485   transaction-handling methods
486       Warning: the behaviour of the TRANSACTIONS commands when combined with
487       pipelining is still under discussion, and you should NOT use them at
488       the same time just now.
489
490       You can follow the discussion to see the open issues with this
491       <https://github.com/PerlRedis/perl-redis/issues/17>.
492
493   exec
494         my @individual_replies = $r->exec;
495
496       "exec" has special behaviour when run in a pipeline: the $reply
497       argument to the pipeline callback is an array ref whose elements are
498       themselves "[$reply, $error]" pairs.  This means that you can
499       accurately detect errors yielded by any command in the transaction, and
500       without any exceptions being thrown.
501
502   keys
503         my @keys = $r->keys( '*glob_pattern*' );
504         my $keys = $r->keys( '*glob_pattern*' ); # count of matching keys
505
506       Note that synchronous "keys" calls in a scalar context return the
507       number of matching keys (not an array ref of matching keys as you might
508       expect).  This does not apply in pipelined mode: assuming the server
509       returns a list of keys, as expected, it is always passed to the
510       pipeline callback as an array ref.
511
512   hashes
513       Hashes in Redis cannot be nested as in perl, if you want to store a
514       nested hash, you need to serialize the hash first. If you want to have
515       a named hash, you can use Redis-hashes. You will find an example in the
516       tests of this module t/01-basic.t
517
518   eval
519       Note that this commands sends the Lua script every time you call it.
520       See "evalsha" and "script_load" for an alternative.
521
522   info
523         my $info_hash = $r->info;
524
525       The "info" method is unique in that it decodes the server's response
526       into a hashref, if possible. This decoding happens in both synchronous
527       and pipelined modes.
528

KEYS

530   del
531         $r->del(key [key ...])
532
533       Delete a key (see <https://redis.io/commands/del>)
534
535   dump
536         $r->dump(key)
537
538       Return a serialized version of the value stored at the specified key.
539       (see <https://redis.io/commands/dump>)
540
541   exists
542         $r->exists(key)
543
544       Determine if a key exists (see <https://redis.io/commands/exists>)
545
546   expire
547         $r->expire(key, seconds)
548
549       Set a key's time to live in seconds (see
550       <https://redis.io/commands/expire>)
551
552   expireat
553         $r->expireat(key, timestamp)
554
555       Set the expiration for a key as a UNIX timestamp (see
556       <https://redis.io/commands/expireat>)
557
558   keys
559         $r->keys(pattern)
560
561       Find all keys matching the given pattern (see
562       <https://redis.io/commands/keys>)
563
564   migrate
565         $r->migrate(host, port, key, destination-db, timeout, [COPY], [REPLACE])
566
567       Atomically transfer a key from a Redis instance to another one. (see
568       <https://redis.io/commands/migrate>)
569
570   move
571         $r->move(key, db)
572
573       Move a key to another database (see <https://redis.io/commands/move>)
574
575   object
576         $r->object(subcommand, [arguments [arguments ...]])
577
578       Inspect the internals of Redis objects (see
579       <https://redis.io/commands/object>)
580
581   persist
582         $r->persist(key)
583
584       Remove the expiration from a key (see
585       <https://redis.io/commands/persist>)
586
587   pexpire
588         $r->pexpire(key, milliseconds)
589
590       Set a key's time to live in milliseconds (see
591       <https://redis.io/commands/pexpire>)
592
593   pexpireat
594         $r->pexpireat(key, milliseconds-timestamp)
595
596       Set the expiration for a key as a UNIX timestamp specified in
597       milliseconds (see <https://redis.io/commands/pexpireat>)
598
599   pttl
600         $r->pttl(key)
601
602       Get the time to live for a key in milliseconds (see
603       <https://redis.io/commands/pttl>)
604
605   randomkey
606         $r->randomkey()
607
608       Return a random key from the keyspace (see
609       <https://redis.io/commands/randomkey>)
610
611   rename
612         $r->rename(key, newkey)
613
614       Rename a key (see <https://redis.io/commands/rename>)
615
616   renamenx
617         $r->renamenx(key, newkey)
618
619       Rename a key, only if the new key does not exist (see
620       <https://redis.io/commands/renamenx>)
621
622   restore
623         $r->restore(key, ttl, serialized-value)
624
625       Create a key using the provided serialized value, previously obtained
626       using DUMP. (see <https://redis.io/commands/restore>)
627
628   scan
629         $r->scan(cursor, [MATCH pattern], [COUNT count])
630
631       Incrementally iterate the keys space (see
632       <https://redis.io/commands/scan>)
633
634   sort
635         $r->sort(key, [BY pattern], [LIMIT offset count], [GET pattern [GET pattern ...]], [ASC|DESC], [ALPHA], [STORE destination])
636
637       Sort the elements in a list, set or sorted set (see
638       <https://redis.io/commands/sort>)
639
640   ttl
641         $r->ttl(key)
642
643       Get the time to live for a key (see <https://redis.io/commands/ttl>)
644
645   type
646         $r->type(key)
647
648       Determine the type stored at key (see <https://redis.io/commands/type>)
649

STRINGS

651   append
652         $r->append(key, value)
653
654       Append a value to a key (see <https://redis.io/commands/append>)
655
656   bitcount
657         $r->bitcount(key, [start end])
658
659       Count set bits in a string (see <https://redis.io/commands/bitcount>)
660
661   bitop
662         $r->bitop(operation, destkey, key [key ...])
663
664       Perform bitwise operations between strings (see
665       <https://redis.io/commands/bitop>)
666
667   bitpos
668         $r->bitpos(key, bit, [start], [end])
669
670       Find first bit set or clear in a string (see
671       <https://redis.io/commands/bitpos>)
672
673   blpop
674         $r->blpop(key [key ...], timeout)
675
676       Remove and get the first element in a list, or block until one is
677       available (see <https://redis.io/commands/blpop>)
678
679   brpop
680         $r->brpop(key [key ...], timeout)
681
682       Remove and get the last element in a list, or block until one is
683       available (see <https://redis.io/commands/brpop>)
684
685   brpoplpush
686         $r->brpoplpush(source, destination, timeout)
687
688       Pop a value from a list, push it to another list and return it; or
689       block until one is available (see
690       <https://redis.io/commands/brpoplpush>)
691
692   decr
693         $r->decr(key)
694
695       Decrement the integer value of a key by one (see
696       <https://redis.io/commands/decr>)
697
698   decrby
699         $r->decrby(key, decrement)
700
701       Decrement the integer value of a key by the given number (see
702       <https://redis.io/commands/decrby>)
703
704   get
705         $r->get(key)
706
707       Get the value of a key (see <https://redis.io/commands/get>)
708
709   getbit
710         $r->getbit(key, offset)
711
712       Returns the bit value at offset in the string value stored at key (see
713       <https://redis.io/commands/getbit>)
714
715   getrange
716         $r->getrange(key, start, end)
717
718       Get a substring of the string stored at a key (see
719       <https://redis.io/commands/getrange>)
720
721   getset
722         $r->getset(key, value)
723
724       Set the string value of a key and return its old value (see
725       <https://redis.io/commands/getset>)
726
727   incr
728         $r->incr(key)
729
730       Increment the integer value of a key by one (see
731       <https://redis.io/commands/incr>)
732
733   incrby
734         $r->incrby(key, increment)
735
736       Increment the integer value of a key by the given amount (see
737       <https://redis.io/commands/incrby>)
738
739   incrbyfloat
740         $r->incrbyfloat(key, increment)
741
742       Increment the float value of a key by the given amount (see
743       <https://redis.io/commands/incrbyfloat>)
744
745   mget
746         $r->mget(key [key ...])
747
748       Get the values of all the given keys (see
749       <https://redis.io/commands/mget>)
750
751   mset
752         $r->mset(key value [key value ...])
753
754       Set multiple keys to multiple values (see
755       <https://redis.io/commands/mset>)
756
757   msetnx
758         $r->msetnx(key value [key value ...])
759
760       Set multiple keys to multiple values, only if none of the keys exist
761       (see <https://redis.io/commands/msetnx>)
762
763   psetex
764         $r->psetex(key, milliseconds, value)
765
766       Set the value and expiration in milliseconds of a key (see
767       <https://redis.io/commands/psetex>)
768
769   set
770         $r->set(key, value, ['EX',  seconds], ['PX', milliseconds], ['NX'|'XX'])
771
772       Set the string value of a key (see <https://redis.io/commands/set>).
773       Example:
774
775         $r->set('key', 'test', 'EX', 60, 'NX')
776
777   setbit
778         $r->setbit(key, offset, value)
779
780       Sets or clears the bit at offset in the string value stored at key (see
781       <https://redis.io/commands/setbit>)
782
783   setex
784         $r->setex(key, seconds, value)
785
786       Set the value and expiration of a key (see
787       <https://redis.io/commands/setex>)
788
789   setnx
790         $r->setnx(key, value)
791
792       Set the value of a key, only if the key does not exist (see
793       <https://redis.io/commands/setnx>)
794
795   setrange
796         $r->setrange(key, offset, value)
797
798       Overwrite part of a string at key starting at the specified offset (see
799       <https://redis.io/commands/setrange>)
800
801   strlen
802         $r->strlen(key)
803
804       Get the length of the value stored in a key (see
805       <https://redis.io/commands/strlen>)
806

HASHES

808   hdel
809         $r->hdel(key, field [field ...])
810
811       Delete one or more hash fields (see <https://redis.io/commands/hdel>)
812
813   hexists
814         $r->hexists(key, field)
815
816       Determine if a hash field exists (see
817       <https://redis.io/commands/hexists>)
818
819   hget
820         $r->hget(key, field)
821
822       Get the value of a hash field (see <https://redis.io/commands/hget>)
823
824   hgetall
825         $r->hgetall(key)
826
827       Get all the fields and values in a hash (see
828       <https://redis.io/commands/hgetall>)
829
830   hincrby
831         $r->hincrby(key, field, increment)
832
833       Increment the integer value of a hash field by the given number (see
834       <https://redis.io/commands/hincrby>)
835
836   hincrbyfloat
837         $r->hincrbyfloat(key, field, increment)
838
839       Increment the float value of a hash field by the given amount (see
840       <https://redis.io/commands/hincrbyfloat>)
841
842   hkeys
843         $r->hkeys(key)
844
845       Get all the fields in a hash (see <https://redis.io/commands/hkeys>)
846
847   hlen
848         $r->hlen(key)
849
850       Get the number of fields in a hash (see
851       <https://redis.io/commands/hlen>)
852
853   hmget
854         $r->hmget(key, field [field ...])
855
856       Get the values of all the given hash fields (see
857       <https://redis.io/commands/hmget>)
858
859   hmset
860         $r->hmset(key, field value [field value ...])
861
862       Set multiple hash fields to multiple values (see
863       <https://redis.io/commands/hmset>)
864
865   hscan
866         $r->hscan(key, cursor, [MATCH pattern], [COUNT count])
867
868       Incrementally iterate hash fields and associated values (see
869       <https://redis.io/commands/hscan>)
870
871   hset
872         $r->hset(key, field, value)
873
874       Set the string value of a hash field (see
875       <https://redis.io/commands/hset>)
876
877   hsetnx
878         $r->hsetnx(key, field, value)
879
880       Set the value of a hash field, only if the field does not exist (see
881       <https://redis.io/commands/hsetnx>)
882
883   hvals
884         $r->hvals(key)
885
886       Get all the values in a hash (see <https://redis.io/commands/hvals>)
887

SETS

889   sadd
890         $r->sadd(key, member [member ...])
891
892       Add one or more members to a set (see <https://redis.io/commands/sadd>)
893
894   scard
895         $r->scard(key)
896
897       Get the number of members in a set (see
898       <https://redis.io/commands/scard>)
899
900   sdiff
901         $r->sdiff(key [key ...])
902
903       Subtract multiple sets (see <https://redis.io/commands/sdiff>)
904
905   sdiffstore
906         $r->sdiffstore(destination, key [key ...])
907
908       Subtract multiple sets and store the resulting set in a key (see
909       <https://redis.io/commands/sdiffstore>)
910
911   sinter
912         $r->sinter(key [key ...])
913
914       Intersect multiple sets (see <https://redis.io/commands/sinter>)
915
916   sinterstore
917         $r->sinterstore(destination, key [key ...])
918
919       Intersect multiple sets and store the resulting set in a key (see
920       <https://redis.io/commands/sinterstore>)
921
922   sismember
923         $r->sismember(key, member)
924
925       Determine if a given value is a member of a set (see
926       <https://redis.io/commands/sismember>)
927
928   smembers
929         $r->smembers(key)
930
931       Get all the members in a set (see <https://redis.io/commands/smembers>)
932
933   smove
934         $r->smove(source, destination, member)
935
936       Move a member from one set to another (see
937       <https://redis.io/commands/smove>)
938
939   spop
940         $r->spop(key)
941
942       Remove and return a random member from a set (see
943       <https://redis.io/commands/spop>)
944
945   srandmember
946         $r->srandmember(key, [count])
947
948       Get one or multiple random members from a set (see
949       <https://redis.io/commands/srandmember>)
950
951   srem
952         $r->srem(key, member [member ...])
953
954       Remove one or more members from a set (see
955       <https://redis.io/commands/srem>)
956
957   sscan
958         $r->sscan(key, cursor, [MATCH pattern], [COUNT count])
959
960       Incrementally iterate Set elements (see
961       <https://redis.io/commands/sscan>)
962
963   sunion
964         $r->sunion(key [key ...])
965
966       Add multiple sets (see <https://redis.io/commands/sunion>)
967
968   sunionstore
969         $r->sunionstore(destination, key [key ...])
970
971       Add multiple sets and store the resulting set in a key (see
972       <https://redis.io/commands/sunionstore>)
973

SORTED SETS

975   zadd
976         $r->zadd(key, score member [score member ...])
977
978       Add one or more members to a sorted set, or update its score if it
979       already exists (see <https://redis.io/commands/zadd>)
980
981   zcard
982         $r->zcard(key)
983
984       Get the number of members in a sorted set (see
985       <https://redis.io/commands/zcard>)
986
987   zcount
988         $r->zcount(key, min, max)
989
990       Count the members in a sorted set with scores within the given values
991       (see <https://redis.io/commands/zcount>)
992
993   zincrby
994         $r->zincrby(key, increment, member)
995
996       Increment the score of a member in a sorted set (see
997       <https://redis.io/commands/zincrby>)
998
999   zinterstore
1000         $r->zinterstore(destination, numkeys, key [key ...], [WEIGHTS weight [weight ...]], [AGGREGATE SUM|MIN|MAX])
1001
1002       Intersect multiple sorted sets and store the resulting sorted set in a
1003       new key (see <https://redis.io/commands/zinterstore>)
1004
1005   zlexcount
1006         $r->zlexcount(key, min, max)
1007
1008       Count the number of members in a sorted set between a given
1009       lexicographical range (see <https://redis.io/commands/zlexcount>)
1010
1011   zrange
1012         $r->zrange(key, start, stop, [WITHSCORES])
1013
1014       Return a range of members in a sorted set, by index (see
1015       <https://redis.io/commands/zrange>)
1016
1017   zrangebylex
1018         $r->zrangebylex(key, min, max, [LIMIT offset count])
1019
1020       Return a range of members in a sorted set, by lexicographical range
1021       (see <https://redis.io/commands/zrangebylex>)
1022
1023   zrangebyscore
1024         $r->zrangebyscore(key, min, max, [WITHSCORES], [LIMIT offset count])
1025
1026       Return a range of members in a sorted set, by score (see
1027       <https://redis.io/commands/zrangebyscore>)
1028
1029   zrank
1030         $r->zrank(key, member)
1031
1032       Determine the index of a member in a sorted set (see
1033       <https://redis.io/commands/zrank>)
1034
1035   zrem
1036         $r->zrem(key, member [member ...])
1037
1038       Remove one or more members from a sorted set (see
1039       <https://redis.io/commands/zrem>)
1040
1041   zremrangebylex
1042         $r->zremrangebylex(key, min, max)
1043
1044       Remove all members in a sorted set between the given lexicographical
1045       range (see <https://redis.io/commands/zremrangebylex>)
1046
1047   zremrangebyrank
1048         $r->zremrangebyrank(key, start, stop)
1049
1050       Remove all members in a sorted set within the given indexes (see
1051       <https://redis.io/commands/zremrangebyrank>)
1052
1053   zremrangebyscore
1054         $r->zremrangebyscore(key, min, max)
1055
1056       Remove all members in a sorted set within the given scores (see
1057       <https://redis.io/commands/zremrangebyscore>)
1058
1059   zrevrange
1060         $r->zrevrange(key, start, stop, [WITHSCORES])
1061
1062       Return a range of members in a sorted set, by index, with scores
1063       ordered from high to low (see <https://redis.io/commands/zrevrange>)
1064
1065   zrevrangebylex
1066         $r->zrevrangebylex(key, max, min, [LIMIT offset count])
1067
1068       Return a range of members in a sorted set, by lexicographical range,
1069       ordered from higher to lower strings. (see
1070       <https://redis.io/commands/zrevrangebylex>)
1071
1072   zrevrangebyscore
1073         $r->zrevrangebyscore(key, max, min, [WITHSCORES], [LIMIT offset count])
1074
1075       Return a range of members in a sorted set, by score, with scores
1076       ordered from high to low (see
1077       <https://redis.io/commands/zrevrangebyscore>)
1078
1079   zrevrank
1080         $r->zrevrank(key, member)
1081
1082       Determine the index of a member in a sorted set, with scores ordered
1083       from high to low (see <https://redis.io/commands/zrevrank>)
1084
1085   zscan
1086         $r->zscan(key, cursor, [MATCH pattern], [COUNT count])
1087
1088       Incrementally iterate sorted sets elements and associated scores (see
1089       <https://redis.io/commands/zscan>)
1090
1091   zscore
1092         $r->zscore(key, member)
1093
1094       Get the score associated with the given member in a sorted set (see
1095       <https://redis.io/commands/zscore>)
1096
1097   zunionstore
1098         $r->zunionstore(destination, numkeys, key [key ...], [WEIGHTS weight [weight ...]], [AGGREGATE SUM|MIN|MAX])
1099
1100       Add multiple sorted sets and store the resulting sorted set in a new
1101       key (see <https://redis.io/commands/zunionstore>)
1102

HYPERLOGLOG

1104   pfadd
1105         $r->pfadd(key, element [element ...])
1106
1107       Adds the specified elements to the specified HyperLogLog. (see
1108       <https://redis.io/commands/pfadd>)
1109
1110   pfcount
1111         $r->pfcount(key [key ...])
1112
1113       Return the approximated cardinality of the set(s) observed by the
1114       HyperLogLog at key(s). (see <https://redis.io/commands/pfcount>)
1115
1116   pfmerge
1117         $r->pfmerge(destkey, sourcekey [sourcekey ...])
1118
1119       Merge N different HyperLogLogs into a single one. (see
1120       <https://redis.io/commands/pfmerge>)
1121

PUB/SUB

1123   pubsub
1124         $r->pubsub(subcommand, [argument [argument ...]])
1125
1126       Inspect the state of the Pub/Sub subsystem (see
1127       <https://redis.io/commands/pubsub>)
1128

TRANSACTIONS

1130   discard
1131         $r->discard()
1132
1133       Discard all commands issued after MULTI (see
1134       <https://redis.io/commands/discard>)
1135
1136   exec
1137         $r->exec()
1138
1139       Execute all commands issued after MULTI (see
1140       <https://redis.io/commands/exec>)
1141
1142   multi
1143         $r->multi()
1144
1145       Mark the start of a transaction block (see
1146       <https://redis.io/commands/multi>)
1147
1148   unwatch
1149         $r->unwatch()
1150
1151       Forget about all watched keys (see <https://redis.io/commands/unwatch>)
1152
1153   watch
1154         $r->watch(key [key ...])
1155
1156       Watch the given keys to determine execution of the MULTI/EXEC block
1157       (see <https://redis.io/commands/watch>)
1158

SCRIPTING

1160   eval
1161         $r->eval(script, numkeys, key [key ...], arg [arg ...])
1162
1163       Execute a Lua script server side (see <https://redis.io/commands/eval>)
1164
1165   evalsha
1166         $r->evalsha(sha1, numkeys, key [key ...], arg [arg ...])
1167
1168       Execute a Lua script server side (see
1169       <https://redis.io/commands/evalsha>)
1170
1171   script_exists
1172         $r->script_exists(script [script ...])
1173
1174       Check existence of scripts in the script cache. (see
1175       <https://redis.io/commands/script-exists>)
1176
1177   script_flush
1178         $r->script_flush()
1179
1180       Remove all the scripts from the script cache. (see
1181       <https://redis.io/commands/script-flush>)
1182
1183   script_kill
1184         $r->script_kill()
1185
1186       Kill the script currently in execution. (see
1187       <https://redis.io/commands/script-kill>)
1188
1189   script_load
1190         $r->script_load(script)
1191
1192       Load the specified Lua script into the script cache. (see
1193       <https://redis.io/commands/script-load>)
1194

CONNECTION

1196   auth
1197         $r->auth(password)
1198
1199       Authenticate to the server (see <https://redis.io/commands/auth>)
1200
1201         $r->auth(username, password)
1202
1203       Authenticate to the server using Redis 6.0+ ACL System (see
1204       <https://redis.io/commands/auth>)
1205
1206   echo
1207         $r->echo(message)
1208
1209       Echo the given string (see <https://redis.io/commands/echo>)
1210
1211   ping
1212         $r->ping()
1213
1214       Ping the server (see <https://redis.io/commands/ping>)
1215
1216   quit
1217         $r->quit()
1218
1219       Close the connection (see <https://redis.io/commands/quit>)
1220
1221   select
1222         $r->select(index)
1223
1224       Change the selected database for the current connection (see
1225       <https://redis.io/commands/select>)
1226

SERVER

1228   bgrewriteaof
1229         $r->bgrewriteaof()
1230
1231       Asynchronously rewrite the append-only file (see
1232       <https://redis.io/commands/bgrewriteaof>)
1233
1234   bgsave
1235         $r->bgsave()
1236
1237       Asynchronously save the dataset to disk (see
1238       <https://redis.io/commands/bgsave>)
1239
1240   client_getname
1241         $r->client_getname()
1242
1243       Get the current connection name (see
1244       <https://redis.io/commands/client-getname>)
1245
1246   client_kill
1247         $r->client_kill([ip:port], [ID client-id], [TYPE normal|slave|pubsub], [ADDR ip:port], [SKIPME yes/no])
1248
1249       Kill the connection of a client (see
1250       <https://redis.io/commands/client-kill>)
1251
1252   client_list
1253         $r->client_list()
1254
1255       Get the list of client connections (see
1256       <https://redis.io/commands/client-list>)
1257
1258   client_pause
1259         $r->client_pause(timeout)
1260
1261       Stop processing commands from clients for some time (see
1262       <https://redis.io/commands/client-pause>)
1263
1264   client_setname
1265         $r->client_setname(connection-name)
1266
1267       Set the current connection name (see
1268       <https://redis.io/commands/client-setname>)
1269
1270   cluster_slots
1271         $r->cluster_slots()
1272
1273       Get array of Cluster slot to node mappings (see
1274       <https://redis.io/commands/cluster-slots>)
1275
1276   command
1277         $r->command()
1278
1279       Get array of Redis command details (see
1280       <https://redis.io/commands/command>)
1281
1282   command_count
1283         $r->command_count()
1284
1285       Get total number of Redis commands (see
1286       <https://redis.io/commands/command-count>)
1287
1288   command_getkeys
1289         $r->command_getkeys()
1290
1291       Extract keys given a full Redis command (see
1292       <https://redis.io/commands/command-getkeys>)
1293
1294   command_info
1295         $r->command_info(command-name [command-name ...])
1296
1297       Get array of specific Redis command details (see
1298       <https://redis.io/commands/command-info>)
1299
1300   config_get
1301         $r->config_get(parameter)
1302
1303       Get the value of a configuration parameter (see
1304       <https://redis.io/commands/config-get>)
1305
1306   config_resetstat
1307         $r->config_resetstat()
1308
1309       Reset the stats returned by INFO (see
1310       <https://redis.io/commands/config-resetstat>)
1311
1312   config_rewrite
1313         $r->config_rewrite()
1314
1315       Rewrite the configuration file with the in memory configuration (see
1316       <https://redis.io/commands/config-rewrite>)
1317
1318   config_set
1319         $r->config_set(parameter, value)
1320
1321       Set a configuration parameter to the given value (see
1322       <https://redis.io/commands/config-set>)
1323
1324   dbsize
1325         $r->dbsize()
1326
1327       Return the number of keys in the selected database (see
1328       <https://redis.io/commands/dbsize>)
1329
1330   debug_object
1331         $r->debug_object(key)
1332
1333       Get debugging information about a key (see
1334       <https://redis.io/commands/debug-object>)
1335
1336   debug_segfault
1337         $r->debug_segfault()
1338
1339       Make the server crash (see <https://redis.io/commands/debug-segfault>)
1340
1341   flushall
1342         $r->flushall()
1343
1344       Remove all keys from all databases (see
1345       <https://redis.io/commands/flushall>)
1346
1347   flushdb
1348         $r->flushdb()
1349
1350       Remove all keys from the current database (see
1351       <https://redis.io/commands/flushdb>)
1352
1353   info
1354         $r->info([section])
1355
1356       Get information and statistics about the server (see
1357       <https://redis.io/commands/info>)
1358
1359   lastsave
1360         $r->lastsave()
1361
1362       Get the UNIX time stamp of the last successful save to disk (see
1363       <https://redis.io/commands/lastsave>)
1364
1365   lindex
1366         $r->lindex(key, index)
1367
1368       Get an element from a list by its index (see
1369       <https://redis.io/commands/lindex>)
1370
1371   linsert
1372         $r->linsert(key, BEFORE|AFTER, pivot, value)
1373
1374       Insert an element before or after another element in a list (see
1375       <https://redis.io/commands/linsert>)
1376
1377   llen
1378         $r->llen(key)
1379
1380       Get the length of a list (see <https://redis.io/commands/llen>)
1381
1382   lpop
1383         $r->lpop(key)
1384
1385       Remove and get the first element in a list (see
1386       <https://redis.io/commands/lpop>)
1387
1388   lpush
1389         $r->lpush(key, value [value ...])
1390
1391       Prepend one or multiple values to a list (see
1392       <https://redis.io/commands/lpush>)
1393
1394   lpushx
1395         $r->lpushx(key, value)
1396
1397       Prepend a value to a list, only if the list exists (see
1398       <https://redis.io/commands/lpushx>)
1399
1400   lrange
1401         $r->lrange(key, start, stop)
1402
1403       Get a range of elements from a list (see
1404       <https://redis.io/commands/lrange>)
1405
1406   lrem
1407         $r->lrem(key, count, value)
1408
1409       Remove elements from a list (see <https://redis.io/commands/lrem>)
1410
1411   lset
1412         $r->lset(key, index, value)
1413
1414       Set the value of an element in a list by its index (see
1415       <https://redis.io/commands/lset>)
1416
1417   ltrim
1418         $r->ltrim(key, start, stop)
1419
1420       Trim a list to the specified range (see
1421       <https://redis.io/commands/ltrim>)
1422
1423   monitor
1424         $r->monitor()
1425
1426       Listen for all requests received by the server in real time (see
1427       <https://redis.io/commands/monitor>)
1428
1429   role
1430         $r->role()
1431
1432       Return the role of the instance in the context of replication (see
1433       <https://redis.io/commands/role>)
1434
1435   rpop
1436         $r->rpop(key)
1437
1438       Remove and get the last element in a list (see
1439       <https://redis.io/commands/rpop>)
1440
1441   rpoplpush
1442         $r->rpoplpush(source, destination)
1443
1444       Remove the last element in a list, append it to another list and return
1445       it (see <https://redis.io/commands/rpoplpush>)
1446
1447   rpush
1448         $r->rpush(key, value [value ...])
1449
1450       Append one or multiple values to a list (see
1451       <https://redis.io/commands/rpush>)
1452
1453   rpushx
1454         $r->rpushx(key, value)
1455
1456       Append a value to a list, only if the list exists (see
1457       <https://redis.io/commands/rpushx>)
1458
1459   save
1460         $r->save()
1461
1462       Synchronously save the dataset to disk (see
1463       <https://redis.io/commands/save>)
1464
1465   shutdown
1466         $r->shutdown([NOSAVE], [SAVE])
1467
1468       Synchronously save the dataset to disk and then shut down the server
1469       (see <https://redis.io/commands/shutdown>)
1470
1471   slaveof
1472         $r->slaveof(host, port)
1473
1474       Make the server a slave of another instance, or promote it as master
1475       (see <https://redis.io/commands/slaveof>)
1476
1477   slowlog
1478         $r->slowlog(subcommand, [argument])
1479
1480       Manages the Redis slow queries log (see
1481       <https://redis.io/commands/slowlog>)
1482
1483   sync
1484         $r->sync()
1485
1486       Internal command used for replication (see
1487       <https://redis.io/commands/sync>)
1488
1489   time
1490         $r->time()
1491
1492       Return the current server time (see <https://redis.io/commands/time>)
1493

ACKNOWLEDGEMENTS

1495       The following persons contributed to this project (random order):
1496
1497       •   Aaron Crane (pipelining and AUTOLOAD caching support)
1498
1499       •   Dirk Vleugels
1500
1501       •   Flavio Poletti
1502
1503       •   Jeremy Zawodny
1504
1505       •   sunnavy at bestpractical.com
1506
1507       •   Thiago Berlitz Rondon
1508
1509       •   Ulrich Habel
1510
1511       •   Ivan Kruglov
1512
1513       •   Steffen Mueller <smueller@cpan.org>
1514

AUTHORS

1516       •   Pedro Melo <melo@cpan.org>
1517
1518       •   Damien Krotkine <dams@cpan.org>
1519
1521       This software is Copyright (c) 2015 by Pedro Melo, Damien Krotkine.
1522
1523       This is free software, licensed under:
1524
1525         The Artistic License 2.0 (GPL Compatible)
1526
1527
1528
1529perl v5.36.0                      2023-01-20                        Redis(3pm)
Impressum