1Redis(3pm) User Contributed Perl Documentation Redis(3pm)
2
3
4
6 Redis - Perl binding for Redis database
7
9 version 1.998
10
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 ## Enable auto-reconnect
32 ## Try to reconnect every 1s up to 60 seconds until success
33 ## Die if you can't after that
34 my $redis = Redis->new(reconnect => 60, every => 1_000_000);
35
36 ## Try each 100ms up to 2 seconds (every is in microseconds)
37 my $redis = Redis->new(reconnect => 2, every => 100_000);
38
39 ## Enable connection timeout (in seconds)
40 my $redis = Redis->new(cnx_timeout => 60);
41
42 ## Enable read timeout (in seconds)
43 my $redis = Redis->new(read_timeout => 0.5);
44
45 ## Enable write timeout (in seconds)
46 my $redis = Redis->new(write_timeout => 1.2);
47
48 ## Connect via a list of Sentinels to a given service
49 my $redis = Redis->new(sentinels => [ '127.0.0.1:12345' ], service => 'mymaster');
50
51 ## Same, but with connection, read and write timeout on the sentinel hosts
52 my $redis = Redis->new( sentinels => [ '127.0.0.1:12345' ], service => 'mymaster',
53 sentinels_cnx_timeout => 0.1,
54 sentinels_read_timeout => 1,
55 sentinels_write_timeout => 1,
56 );
57
58 ## Use all the regular Redis commands, they all accept a list of
59 ## arguments
60 ## See http://redis.io/commands for full list
61 $redis->get('key');
62 $redis->set('key' => 'value');
63 $redis->sort('list', 'DESC');
64 $redis->sort(qw{list LIMIT 0 5 ALPHA DESC});
65
66 ## Add a coderef argument to run a command in the background
67 $redis->sort(qw{list LIMIT 0 5 ALPHA DESC}, sub {
68 my ($reply, $error) = @_;
69 die "Oops, got an error: $error\n" if defined $error;
70 print "$_\n" for @$reply;
71 });
72 long_computation();
73 $redis->wait_all_responses;
74 ## or
75 $redis->wait_one_response();
76
77 ## Or run a large batch of commands in a pipeline
78 my %hash = _get_large_batch_of_commands();
79 $redis->hset('h', $_, $hash{$_}, sub {}) for keys %hash;
80 $redis->wait_all_responses;
81
82 ## Publish/Subscribe
83 $redis->subscribe(
84 'topic_1',
85 'topic_2',
86 sub {
87 my ($message, $topic, $subscribed_topic) = @_
88
89 ## $subscribed_topic can be different from topic if
90 ## you use psubscribe() with wildcards
91 }
92 );
93 $redis->psubscribe('nasdaq.*', sub {...});
94
95 ## Blocks and waits for messages, calls subscribe() callbacks
96 ## ... forever
97 my $timeout = 10;
98 $redis->wait_for_messages($timeout) while 1;
99
100 ## ... until some condition
101 my $keep_going = 1; ## other code will set to false to quit
102 $redis->wait_for_messages($timeout) while $keep_going;
103
104 $redis->publish('topic_1', 'message');
105
107 Pure perl bindings for <http://redis.io/>
108
109 This version supports protocol 2.x (multi-bulk) or later of Redis
110 available at <https://github.com/antirez/redis/>.
111
112 This documentation lists commands which are exercised in test suite,
113 but additional commands will work correctly since protocol specifies
114 enough information to support almost all commands with same piece of
115 code with a little help of "AUTOLOAD".
116
118 Usually, running a command will wait for a response. However, if
119 you're doing large numbers of requests, it can be more efficient to use
120 what Redis calls pipelining: send multiple commands to Redis without
121 waiting for a response, then wait for the responses that come in.
122
123 To use pipelining, add a coderef argument as the last argument to a
124 command method call:
125
126 $r->set('foo', 'bar', sub {});
127
128 Pending responses to pipelined commands are processed in a single
129 batch, as soon as at least one of the following conditions holds:
130
131 • A non-pipelined (synchronous) command is called on the same
132 connection
133
134 • A pub/sub subscription command (one of "subscribe", "unsubscribe",
135 "psubscribe", or "punsubscribe") is about to be called on the same
136 connection.
137
138 • One of "wait_all_responses" or "wait_one_response" methods is
139 called explicitly.
140
141 The coderef you supply to a pipelined command method is invoked once
142 the response is available. It takes two arguments, $reply and $error.
143 If $error is defined, it contains the text of an error reply sent by
144 the Redis server. Otherwise, $reply is the non-error reply. For almost
145 all commands, that means it's "undef", or a defined but non-reference
146 scalar, or an array ref of any of those; but see "keys", "info", and
147 "exec".
148
149 Note the contrast with synchronous commands, which throw an exception
150 on receipt of an error reply, or return a non-error reply directly.
151
152 The fact that pipelined commands never throw an exception can be
153 particularly useful for Redis transactions; see "exec".
154
156 There is no encoding feature anymore, it has been deprecated and
157 finally removed. This module consider that any data sent to the Redis
158 server is a binary data. And it doesn't do anything when getting data
159 from the Redis server.
160
161 So, if you are working with character strings, you should pre-encode or
162 post-decode it if needed !
163
165 new
166 my $r = Redis->new; # $ENV{REDIS_SERVER} or 127.0.0.1:6379
167
168 my $r = Redis->new( server => '192.168.0.1:6379', debug => 0 );
169 my $r = Redis->new( server => '192.168.0.1:6379', encoding => undef );
170 my $r = Redis->new( sock => '/path/to/sock' );
171 my $r = Redis->new( reconnect => 60, every => 5000 );
172 my $r = Redis->new( password => 'boo' );
173 my $r = Redis->new( on_connect => sub { my ($redis) = @_; ... } );
174 my $r = Redis->new( name => 'my_connection_name' );
175 my $r = Redis->new( name => sub { "cache-for-$$" });
176
177 my $redis = Redis->new(sentinels => [ '127.0.0.1:12345', '127.0.0.1:23456' ],
178 service => 'mymaster');
179
180 ## Connect via a list of Sentinels to a given service
181 my $redis = Redis->new(sentinels => [ '127.0.0.1:12345' ], service => 'mymaster');
182
183 ## Same, but with connection, read and write timeout on the sentinel hosts
184 my $redis = Redis->new( sentinels => [ '127.0.0.1:12345' ], service => 'mymaster',
185 sentinels_cnx_timeout => 0.1,
186 sentinels_read_timeout => 1,
187 sentinels_write_timeout => 1,
188 );
189
190 "server"
191
192 The "server" parameter specifies the Redis server we should connect to,
193 via TCP. Use the 'IP:PORT' format. If no "server" option is present, we
194 will attempt to use the "REDIS_SERVER" environment variable. If neither
195 of those options are present, it defaults to '127.0.0.1:6379'.
196
197 Alternatively you can use the "sock" parameter to specify the path of
198 the UNIX domain socket where the Redis server is listening.
199
200 Alternatively you can use the "sentinels" parameter and the "service"
201 parameter to specify a list of sentinels to contact and try to get the
202 address of the given service name. "sentinels" must be an ArrayRef and
203 "service" an Str.
204
205 The "REDIS_SERVER" can be used for UNIX domain sockets too. The
206 following formats are supported:
207
208 • /path/to/sock
209
210 • unix:/path/to/sock
211
212 • 127.0.0.1:11011
213
214 • tcp:127.0.0.1:11011
215
216 "reconnect", "every"
217
218 The "reconnect" option enables auto-reconnection mode. If we cannot
219 connect to the Redis server, or if a network write fails, we enter
220 retry mode. We will try a new connection every "every" microseconds (1
221 ms by default), up-to "reconnect" seconds.
222
223 Be aware that read errors will always thrown an exception, and will not
224 trigger a retry until the new command is sent.
225
226 If we cannot re-establish a connection after "reconnect" seconds, an
227 exception will be thrown.
228
229 "conservative_reconnect"
230
231 "conservative_reconnect" option makes sure that reconnection is only
232 attempted when no pending command is ongoing. For instance, if you're
233 doing "<$redis-"incr('key')>>, and if the server properly understood
234 and processed the command, but the network connection is dropped just
235 before the server replies : the command has been processed but the
236 client doesn't know it. In this situation, if reconnect is enabled, the
237 Redis client will reconnect and send the "incr" command *again*. If it
238 succeeds, at the end the key as been incremented *two* times. To avoid
239 this issue, you can set the "conservative_reconnect" option to a true
240 value. In this case, the client will reconnect only if no request is
241 pending. Otherwise it will die with the message: "reconnect disabled
242 while responses are pending and safe reconnect mode enabled".
243
244 "cnx_timeout"
245
246 The "cnx_timeout" option enables connection timeout. The Redis client
247 will wait at most that number of seconds (can be fractional) before
248 giving up connecting to a server.
249
250 "sentinels_cnx_timeout"
251
252 The "sentinels_cnx_timeout" option enables sentinel connection timeout.
253 When using the sentinels feature, Redis client will wait at most that
254 number of seconds (can be fractional) before giving up connecting to a
255 sentinel. Default: 0.1
256
257 "read_timeout"
258
259 The "read_timeout" option enables read timeout. The Redis client will
260 wait at most that number of seconds (can be fractional) before giving
261 up when reading from the server.
262
263 "sentinels_read_timeout"
264
265 The "sentinels_read_timeout" option enables sentinel read timeout. When
266 using the sentinels feature, the Redis client will wait at most that
267 number of seconds (can be fractional) before giving up when reading
268 from a sentinel server. Default: 1
269
270 "write_timeout"
271
272 The "write_timeout" option enables write timeout. The Redis client will
273 wait at most that number of seconds (can be fractional) before giving
274 up when reading from the server.
275
276 "sentinels_write_timeout"
277
278 The "sentinels_write_timeout" option enables sentinel write timeout.
279 When using the sentinels feature, the Redis client will wait at most
280 that number of seconds (can be fractional) before giving up when
281 reading from a sentinel server. Default: 1
282
283 "password"
284
285 If your Redis server requires authentication, you can use the
286 "password" attribute. After each established connection (at the start
287 or when reconnecting), the Redis "AUTH" command will be send to the
288 server. If the password is wrong, an exception will be thrown and
289 reconnect will be disabled.
290
291 "on_connect"
292
293 You can also provide a code reference that will be immediately after
294 each successful connection. The "on_connect" attribute is used to
295 provide the code reference, and it will be called with the first
296 parameter being the Redis object.
297
298 "no_auto_connect_on_new"
299
300 You can also provide "no_auto_connect_on_new" in which case "new" won't
301 call "$obj->connect" for you implicitly, you'll have to do that
302 yourself. This is useful for figuring out how long connection setup
303 takes so you can configure the "cnx_timeout" appropriately.
304
305 "no_sentinels_list_update"
306
307 You can also provide "no_sentinels_list_update". By default (that is,
308 without this option), when successfully contacting a sentinel server,
309 the Redis client will ask it for the list of sentinels known for the
310 given service, and merge it with its list of sentinels (in the
311 "sentinels" attribute). You can disable this behavior by setting
312 "no_sentinels_list_update" to a true value.
313
314 "name"
315
316 You can also set a name for each connection. This can be very useful
317 for debugging purposes, using the "CLIENT LIST" command. To set a
318 connection name, use the "name" parameter. You can use both a scalar
319 value or a CodeRef. If the latter, it will be called after each
320 connection, with the Redis object, and it should return the connection
321 name to use. If it returns a undefined value, Redis will not set the
322 connection name.
323
324 Please note that there are restrictions on the name you can set, the
325 most important of which is, no spaces. See the CLIENT SETNAME
326 documentation <http://redis.io/commands/client-setname> for all the
327 juicy details. This feature is safe to use with all versions of Redis
328 servers. If "CLIENT SETNAME" support is not available (Redis servers
329 2.6.9 and above only), the name parameter is ignored.
330
331 "debug"
332
333 The "debug" parameter enables debug information to STDERR, including
334 all interactions with the server. You can also enable debug with the
335 "REDIS_DEBUG" environment variable.
336
338 connect
339 $r->connect;
340
341 Connects to the Redis server. This is done by default when the obect is
342 constructed using "new()", unless "no_auto_connect_on_new" has been
343 set. See this option in the "new()" constructor.
344
345 quit
346 $r->quit;
347
348 Closes the connection to the server. The "quit" method does not support
349 pipelined operation.
350
351 ping
352 $r->ping || die "no server?";
353
354 The "ping" method does not support pipelined operation.
355
357 wait_all_responses
358 Waits until all pending pipelined responses have been received, and
359 invokes the pipeline callback for each one. See "PIPELINING".
360
361 wait_one_response
362 Waits until the first pending pipelined response has been received, and
363 invokes its callback. See "PIPELINING".
364
366 When one of "subscribe" or "psubscribe" is used, the Redis object will
367 enter PubSub mode. When in PubSub mode only commands in this section,
368 plus "quit", will be accepted.
369
370 If you plan on using PubSub and other Redis functions, you should use
371 two Redis objects, one dedicated to PubSub and the other for regular
372 commands.
373
374 All Pub/Sub commands receive a callback as the last parameter. This
375 callback receives three arguments:
376
377 • The published message.
378
379 • The topic over which the message was sent.
380
381 • The subscribed topic that matched the topic for the message. With
382 "subscribe" these last two are the same, always. But with
383 "psubscribe", this parameter tells you the pattern that matched.
384
385 See the Pub-Sub notes <http://redis.io/topics/pubsub> for more
386 information about the messages you will receive on your callbacks after
387 each "subscribe", "unsubscribe", "psubscribe" and "punsubscribe".
388
389 publish
390 $r->publish($topic, $message);
391
392 Publishes the $message to the $topic.
393
394 subscribe
395 $r->subscribe(
396 @topics_to_subscribe_to,
397 my $savecallback = sub {
398 my ($message, $topic, $subscribed_topic) = @_;
399 ...
400 },
401 );
402
403 Subscribe one or more topics. Messages published into one of them will
404 be received by Redis, and the specified callback will be executed.
405
406 unsubscribe
407 $r->unsubscribe(@topic_list, $savecallback);
408
409 Stops receiving messages via $savecallback for all the topics in
410 @topic_list. WARNING: it is important that you give the same calleback
411 that you used for subscribtion. The value of the CodeRef must be the
412 same, as this is how internally the code identifies it.
413
414 psubscribe
415 my @topic_matches = ('prefix1.*', 'prefix2.*');
416 $r->psubscribe(@topic_matches, my $savecallback = sub { my ($m, $t, $s) = @_; ... });
417
418 Subscribes a pattern of topics. All messages to topics that match the
419 pattern will be delivered to the callback.
420
421 punsubscribe
422 my @topic_matches = ('prefix1.*', 'prefix2.*');
423 $r->punsubscribe(@topic_matches, $savecallback);
424
425 Stops receiving messages via $savecallback for all the topics pattern
426 matches in @topic_list. WARNING: it is important that you give the same
427 calleback that you used for subscribtion. The value of the CodeRef must
428 be the same, as this is how internally the code identifies it.
429
430 is_subscriber
431 if ($r->is_subscriber) { say "We are in Pub/Sub mode!" }
432
433 Returns true if we are in Pub/Sub mode.
434
435 wait_for_messages
436 my $keep_going = 1; ## Set to false somewhere to leave the loop
437 my $timeout = 5;
438 $r->wait_for_messages($timeout) while $keep_going;
439
440 Blocks, waits for incoming messages and delivers them to the
441 appropriate callbacks.
442
443 Requires a single parameter, the number of seconds to wait for
444 messages. Use 0 to wait for ever. If a positive non-zero value is used,
445 it will return after that amount of seconds without a single
446 notification.
447
448 Please note that the timeout is not a commitment to return control to
449 the caller at most each "timeout" seconds, but more a idle timeout,
450 were control will return to the caller if Redis is idle (as in no
451 messages were received during the timeout period) for more than
452 "timeout" seconds.
453
454 The "wait_for_messages" call returns the number of messages processed
455 during the run.
456
458 methods that return multiple values
459 When a method returns more than one value, it checks the context and
460 returns either a list of values or an ArrayRef.
461
462 transaction-handling methods
463 Warning: the behaviour of the TRANSACTIONS commands when combined with
464 pipelining is still under discussion, and you should NOT use them at
465 the same time just now.
466
467 You can follow the discussion to see the open issues with this
468 <https://github.com/PerlRedis/perl-redis/issues/17>.
469
470 exec
471 my @individual_replies = $r->exec;
472
473 "exec" has special behaviour when run in a pipeline: the $reply
474 argument to the pipeline callback is an array ref whose elements are
475 themselves "[$reply, $error]" pairs. This means that you can
476 accurately detect errors yielded by any command in the transaction, and
477 without any exceptions being thrown.
478
479 keys
480 my @keys = $r->keys( '*glob_pattern*' );
481 my $keys = $r->keys( '*glob_pattern*' ); # count of matching keys
482
483 Note that synchronous "keys" calls in a scalar context return the
484 number of matching keys (not an array ref of matching keys as you might
485 expect). This does not apply in pipelined mode: assuming the server
486 returns a list of keys, as expected, it is always passed to the
487 pipeline callback as an array ref.
488
489 hashes
490 Hashes in Redis cannot be nested as in perl, if you want to store a
491 nested hash, you need to serialize the hash first. If you want to have
492 a named hash, you can use Redis-hashes. You will find an example in the
493 tests of this module t/01-basic.t
494
495 eval
496 Note that this commands sends the Lua script every time you call it.
497 See "evalsha" and "script_load" for an alternative.
498
499 info
500 my $info_hash = $r->info;
501
502 The "info" method is unique in that it decodes the server's response
503 into a hashref, if possible. This decoding happens in both synchronous
504 and pipelined modes.
505
507 del
508 $r->del(key [key ...])
509
510 Delete a key (see <http://redis.io/commands/del>)
511
512 dump
513 $r->dump(key)
514
515 Return a serialized version of the value stored at the specified key.
516 (see <http://redis.io/commands/dump>)
517
518 exists
519 $r->exists(key)
520
521 Determine if a key exists (see <http://redis.io/commands/exists>)
522
523 expire
524 $r->expire(key, seconds)
525
526 Set a key's time to live in seconds (see
527 <http://redis.io/commands/expire>)
528
529 expireat
530 $r->expireat(key, timestamp)
531
532 Set the expiration for a key as a UNIX timestamp (see
533 <http://redis.io/commands/expireat>)
534
535 keys
536 $r->keys(pattern)
537
538 Find all keys matching the given pattern (see
539 <http://redis.io/commands/keys>)
540
541 migrate
542 $r->migrate(host, port, key, destination-db, timeout, [COPY], [REPLACE])
543
544 Atomically transfer a key from a Redis instance to another one. (see
545 <http://redis.io/commands/migrate>)
546
547 move
548 $r->move(key, db)
549
550 Move a key to another database (see <http://redis.io/commands/move>)
551
552 object
553 $r->object(subcommand, [arguments [arguments ...]])
554
555 Inspect the internals of Redis objects (see
556 <http://redis.io/commands/object>)
557
558 persist
559 $r->persist(key)
560
561 Remove the expiration from a key (see
562 <http://redis.io/commands/persist>)
563
564 pexpire
565 $r->pexpire(key, milliseconds)
566
567 Set a key's time to live in milliseconds (see
568 <http://redis.io/commands/pexpire>)
569
570 pexpireat
571 $r->pexpireat(key, milliseconds-timestamp)
572
573 Set the expiration for a key as a UNIX timestamp specified in
574 milliseconds (see <http://redis.io/commands/pexpireat>)
575
576 pttl
577 $r->pttl(key)
578
579 Get the time to live for a key in milliseconds (see
580 <http://redis.io/commands/pttl>)
581
582 randomkey
583 $r->randomkey()
584
585 Return a random key from the keyspace (see
586 <http://redis.io/commands/randomkey>)
587
588 rename
589 $r->rename(key, newkey)
590
591 Rename a key (see <http://redis.io/commands/rename>)
592
593 renamenx
594 $r->renamenx(key, newkey)
595
596 Rename a key, only if the new key does not exist (see
597 <http://redis.io/commands/renamenx>)
598
599 restore
600 $r->restore(key, ttl, serialized-value)
601
602 Create a key using the provided serialized value, previously obtained
603 using DUMP. (see <http://redis.io/commands/restore>)
604
605 scan
606 $r->scan(cursor, [MATCH pattern], [COUNT count])
607
608 Incrementally iterate the keys space (see
609 <http://redis.io/commands/scan>)
610
611 sort
612 $r->sort(key, [BY pattern], [LIMIT offset count], [GET pattern [GET pattern ...]], [ASC|DESC], [ALPHA], [STORE destination])
613
614 Sort the elements in a list, set or sorted set (see
615 <http://redis.io/commands/sort>)
616
617 ttl
618 $r->ttl(key)
619
620 Get the time to live for a key (see <http://redis.io/commands/ttl>)
621
622 type
623 $r->type(key)
624
625 Determine the type stored at key (see <http://redis.io/commands/type>)
626
628 append
629 $r->append(key, value)
630
631 Append a value to a key (see <http://redis.io/commands/append>)
632
633 bitcount
634 $r->bitcount(key, [start end])
635
636 Count set bits in a string (see <http://redis.io/commands/bitcount>)
637
638 bitop
639 $r->bitop(operation, destkey, key [key ...])
640
641 Perform bitwise operations between strings (see
642 <http://redis.io/commands/bitop>)
643
644 bitpos
645 $r->bitpos(key, bit, [start], [end])
646
647 Find first bit set or clear in a string (see
648 <http://redis.io/commands/bitpos>)
649
650 blpop
651 $r->blpop(key [key ...], timeout)
652
653 Remove and get the first element in a list, or block until one is
654 available (see <http://redis.io/commands/blpop>)
655
656 brpop
657 $r->brpop(key [key ...], timeout)
658
659 Remove and get the last element in a list, or block until one is
660 available (see <http://redis.io/commands/brpop>)
661
662 brpoplpush
663 $r->brpoplpush(source, destination, timeout)
664
665 Pop a value from a list, push it to another list and return it; or
666 block until one is available (see
667 <http://redis.io/commands/brpoplpush>)
668
669 decr
670 $r->decr(key)
671
672 Decrement the integer value of a key by one (see
673 <http://redis.io/commands/decr>)
674
675 decrby
676 $r->decrby(key, decrement)
677
678 Decrement the integer value of a key by the given number (see
679 <http://redis.io/commands/decrby>)
680
681 get
682 $r->get(key)
683
684 Get the value of a key (see <http://redis.io/commands/get>)
685
686 getbit
687 $r->getbit(key, offset)
688
689 Returns the bit value at offset in the string value stored at key (see
690 <http://redis.io/commands/getbit>)
691
692 getrange
693 $r->getrange(key, start, end)
694
695 Get a substring of the string stored at a key (see
696 <http://redis.io/commands/getrange>)
697
698 getset
699 $r->getset(key, value)
700
701 Set the string value of a key and return its old value (see
702 <http://redis.io/commands/getset>)
703
704 incr
705 $r->incr(key)
706
707 Increment the integer value of a key by one (see
708 <http://redis.io/commands/incr>)
709
710 incrby
711 $r->incrby(key, increment)
712
713 Increment the integer value of a key by the given amount (see
714 <http://redis.io/commands/incrby>)
715
716 incrbyfloat
717 $r->incrbyfloat(key, increment)
718
719 Increment the float value of a key by the given amount (see
720 <http://redis.io/commands/incrbyfloat>)
721
722 mget
723 $r->mget(key [key ...])
724
725 Get the values of all the given keys (see
726 <http://redis.io/commands/mget>)
727
728 mset
729 $r->mset(key value [key value ...])
730
731 Set multiple keys to multiple values (see
732 <http://redis.io/commands/mset>)
733
734 msetnx
735 $r->msetnx(key value [key value ...])
736
737 Set multiple keys to multiple values, only if none of the keys exist
738 (see <http://redis.io/commands/msetnx>)
739
740 psetex
741 $r->psetex(key, milliseconds, value)
742
743 Set the value and expiration in milliseconds of a key (see
744 <http://redis.io/commands/psetex>)
745
746 set
747 $r->set(key, value, ['EX', seconds], ['PX', milliseconds], ['NX'|'XX'])
748
749 Set the string value of a key (see <http://redis.io/commands/set>).
750 Example:
751
752 $r->set('key', 'test', 'EX', 60, 'NX')
753
754 setbit
755 $r->setbit(key, offset, value)
756
757 Sets or clears the bit at offset in the string value stored at key (see
758 <http://redis.io/commands/setbit>)
759
760 setex
761 $r->setex(key, seconds, value)
762
763 Set the value and expiration of a key (see
764 <http://redis.io/commands/setex>)
765
766 setnx
767 $r->setnx(key, value)
768
769 Set the value of a key, only if the key does not exist (see
770 <http://redis.io/commands/setnx>)
771
772 setrange
773 $r->setrange(key, offset, value)
774
775 Overwrite part of a string at key starting at the specified offset (see
776 <http://redis.io/commands/setrange>)
777
778 strlen
779 $r->strlen(key)
780
781 Get the length of the value stored in a key (see
782 <http://redis.io/commands/strlen>)
783
785 hdel
786 $r->hdel(key, field [field ...])
787
788 Delete one or more hash fields (see <http://redis.io/commands/hdel>)
789
790 hexists
791 $r->hexists(key, field)
792
793 Determine if a hash field exists (see
794 <http://redis.io/commands/hexists>)
795
796 hget
797 $r->hget(key, field)
798
799 Get the value of a hash field (see <http://redis.io/commands/hget>)
800
801 hgetall
802 $r->hgetall(key)
803
804 Get all the fields and values in a hash (see
805 <http://redis.io/commands/hgetall>)
806
807 hincrby
808 $r->hincrby(key, field, increment)
809
810 Increment the integer value of a hash field by the given number (see
811 <http://redis.io/commands/hincrby>)
812
813 hincrbyfloat
814 $r->hincrbyfloat(key, field, increment)
815
816 Increment the float value of a hash field by the given amount (see
817 <http://redis.io/commands/hincrbyfloat>)
818
819 hkeys
820 $r->hkeys(key)
821
822 Get all the fields in a hash (see <http://redis.io/commands/hkeys>)
823
824 hlen
825 $r->hlen(key)
826
827 Get the number of fields in a hash (see
828 <http://redis.io/commands/hlen>)
829
830 hmget
831 $r->hmget(key, field [field ...])
832
833 Get the values of all the given hash fields (see
834 <http://redis.io/commands/hmget>)
835
836 hmset
837 $r->hmset(key, field value [field value ...])
838
839 Set multiple hash fields to multiple values (see
840 <http://redis.io/commands/hmset>)
841
842 hscan
843 $r->hscan(key, cursor, [MATCH pattern], [COUNT count])
844
845 Incrementally iterate hash fields and associated values (see
846 <http://redis.io/commands/hscan>)
847
848 hset
849 $r->hset(key, field, value)
850
851 Set the string value of a hash field (see
852 <http://redis.io/commands/hset>)
853
854 hsetnx
855 $r->hsetnx(key, field, value)
856
857 Set the value of a hash field, only if the field does not exist (see
858 <http://redis.io/commands/hsetnx>)
859
860 hvals
861 $r->hvals(key)
862
863 Get all the values in a hash (see <http://redis.io/commands/hvals>)
864
866 sadd
867 $r->sadd(key, member [member ...])
868
869 Add one or more members to a set (see <http://redis.io/commands/sadd>)
870
871 scard
872 $r->scard(key)
873
874 Get the number of members in a set (see
875 <http://redis.io/commands/scard>)
876
877 sdiff
878 $r->sdiff(key [key ...])
879
880 Subtract multiple sets (see <http://redis.io/commands/sdiff>)
881
882 sdiffstore
883 $r->sdiffstore(destination, key [key ...])
884
885 Subtract multiple sets and store the resulting set in a key (see
886 <http://redis.io/commands/sdiffstore>)
887
888 sinter
889 $r->sinter(key [key ...])
890
891 Intersect multiple sets (see <http://redis.io/commands/sinter>)
892
893 sinterstore
894 $r->sinterstore(destination, key [key ...])
895
896 Intersect multiple sets and store the resulting set in a key (see
897 <http://redis.io/commands/sinterstore>)
898
899 sismember
900 $r->sismember(key, member)
901
902 Determine if a given value is a member of a set (see
903 <http://redis.io/commands/sismember>)
904
905 smembers
906 $r->smembers(key)
907
908 Get all the members in a set (see <http://redis.io/commands/smembers>)
909
910 smove
911 $r->smove(source, destination, member)
912
913 Move a member from one set to another (see
914 <http://redis.io/commands/smove>)
915
916 spop
917 $r->spop(key)
918
919 Remove and return a random member from a set (see
920 <http://redis.io/commands/spop>)
921
922 srandmember
923 $r->srandmember(key, [count])
924
925 Get one or multiple random members from a set (see
926 <http://redis.io/commands/srandmember>)
927
928 srem
929 $r->srem(key, member [member ...])
930
931 Remove one or more members from a set (see
932 <http://redis.io/commands/srem>)
933
934 sscan
935 $r->sscan(key, cursor, [MATCH pattern], [COUNT count])
936
937 Incrementally iterate Set elements (see
938 <http://redis.io/commands/sscan>)
939
940 sunion
941 $r->sunion(key [key ...])
942
943 Add multiple sets (see <http://redis.io/commands/sunion>)
944
945 sunionstore
946 $r->sunionstore(destination, key [key ...])
947
948 Add multiple sets and store the resulting set in a key (see
949 <http://redis.io/commands/sunionstore>)
950
952 zadd
953 $r->zadd(key, score member [score member ...])
954
955 Add one or more members to a sorted set, or update its score if it
956 already exists (see <http://redis.io/commands/zadd>)
957
958 zcard
959 $r->zcard(key)
960
961 Get the number of members in a sorted set (see
962 <http://redis.io/commands/zcard>)
963
964 zcount
965 $r->zcount(key, min, max)
966
967 Count the members in a sorted set with scores within the given values
968 (see <http://redis.io/commands/zcount>)
969
970 zincrby
971 $r->zincrby(key, increment, member)
972
973 Increment the score of a member in a sorted set (see
974 <http://redis.io/commands/zincrby>)
975
976 zinterstore
977 $r->zinterstore(destination, numkeys, key [key ...], [WEIGHTS weight [weight ...]], [AGGREGATE SUM|MIN|MAX])
978
979 Intersect multiple sorted sets and store the resulting sorted set in a
980 new key (see <http://redis.io/commands/zinterstore>)
981
982 zlexcount
983 $r->zlexcount(key, min, max)
984
985 Count the number of members in a sorted set between a given
986 lexicographical range (see <http://redis.io/commands/zlexcount>)
987
988 zrange
989 $r->zrange(key, start, stop, [WITHSCORES])
990
991 Return a range of members in a sorted set, by index (see
992 <http://redis.io/commands/zrange>)
993
994 zrangebylex
995 $r->zrangebylex(key, min, max, [LIMIT offset count])
996
997 Return a range of members in a sorted set, by lexicographical range
998 (see <http://redis.io/commands/zrangebylex>)
999
1000 zrangebyscore
1001 $r->zrangebyscore(key, min, max, [WITHSCORES], [LIMIT offset count])
1002
1003 Return a range of members in a sorted set, by score (see
1004 <http://redis.io/commands/zrangebyscore>)
1005
1006 zrank
1007 $r->zrank(key, member)
1008
1009 Determine the index of a member in a sorted set (see
1010 <http://redis.io/commands/zrank>)
1011
1012 zrem
1013 $r->zrem(key, member [member ...])
1014
1015 Remove one or more members from a sorted set (see
1016 <http://redis.io/commands/zrem>)
1017
1018 zremrangebylex
1019 $r->zremrangebylex(key, min, max)
1020
1021 Remove all members in a sorted set between the given lexicographical
1022 range (see <http://redis.io/commands/zremrangebylex>)
1023
1024 zremrangebyrank
1025 $r->zremrangebyrank(key, start, stop)
1026
1027 Remove all members in a sorted set within the given indexes (see
1028 <http://redis.io/commands/zremrangebyrank>)
1029
1030 zremrangebyscore
1031 $r->zremrangebyscore(key, min, max)
1032
1033 Remove all members in a sorted set within the given scores (see
1034 <http://redis.io/commands/zremrangebyscore>)
1035
1036 zrevrange
1037 $r->zrevrange(key, start, stop, [WITHSCORES])
1038
1039 Return a range of members in a sorted set, by index, with scores
1040 ordered from high to low (see <http://redis.io/commands/zrevrange>)
1041
1042 zrevrangebylex
1043 $r->zrevrangebylex(key, max, min, [LIMIT offset count])
1044
1045 Return a range of members in a sorted set, by lexicographical range,
1046 ordered from higher to lower strings. (see
1047 <http://redis.io/commands/zrevrangebylex>)
1048
1049 zrevrangebyscore
1050 $r->zrevrangebyscore(key, max, min, [WITHSCORES], [LIMIT offset count])
1051
1052 Return a range of members in a sorted set, by score, with scores
1053 ordered from high to low (see
1054 <http://redis.io/commands/zrevrangebyscore>)
1055
1056 zrevrank
1057 $r->zrevrank(key, member)
1058
1059 Determine the index of a member in a sorted set, with scores ordered
1060 from high to low (see <http://redis.io/commands/zrevrank>)
1061
1062 zscan
1063 $r->zscan(key, cursor, [MATCH pattern], [COUNT count])
1064
1065 Incrementally iterate sorted sets elements and associated scores (see
1066 <http://redis.io/commands/zscan>)
1067
1068 zscore
1069 $r->zscore(key, member)
1070
1071 Get the score associated with the given member in a sorted set (see
1072 <http://redis.io/commands/zscore>)
1073
1074 zunionstore
1075 $r->zunionstore(destination, numkeys, key [key ...], [WEIGHTS weight [weight ...]], [AGGREGATE SUM|MIN|MAX])
1076
1077 Add multiple sorted sets and store the resulting sorted set in a new
1078 key (see <http://redis.io/commands/zunionstore>)
1079
1081 pfadd
1082 $r->pfadd(key, element [element ...])
1083
1084 Adds the specified elements to the specified HyperLogLog. (see
1085 <http://redis.io/commands/pfadd>)
1086
1087 pfcount
1088 $r->pfcount(key [key ...])
1089
1090 Return the approximated cardinality of the set(s) observed by the
1091 HyperLogLog at key(s). (see <http://redis.io/commands/pfcount>)
1092
1093 pfmerge
1094 $r->pfmerge(destkey, sourcekey [sourcekey ...])
1095
1096 Merge N different HyperLogLogs into a single one. (see
1097 <http://redis.io/commands/pfmerge>)
1098
1100 pubsub
1101 $r->pubsub(subcommand, [argument [argument ...]])
1102
1103 Inspect the state of the Pub/Sub subsystem (see
1104 <http://redis.io/commands/pubsub>)
1105
1107 discard
1108 $r->discard()
1109
1110 Discard all commands issued after MULTI (see
1111 <http://redis.io/commands/discard>)
1112
1113 exec
1114 $r->exec()
1115
1116 Execute all commands issued after MULTI (see
1117 <http://redis.io/commands/exec>)
1118
1119 multi
1120 $r->multi()
1121
1122 Mark the start of a transaction block (see
1123 <http://redis.io/commands/multi>)
1124
1125 unwatch
1126 $r->unwatch()
1127
1128 Forget about all watched keys (see <http://redis.io/commands/unwatch>)
1129
1130 watch
1131 $r->watch(key [key ...])
1132
1133 Watch the given keys to determine execution of the MULTI/EXEC block
1134 (see <http://redis.io/commands/watch>)
1135
1137 eval
1138 $r->eval(script, numkeys, key [key ...], arg [arg ...])
1139
1140 Execute a Lua script server side (see <http://redis.io/commands/eval>)
1141
1142 evalsha
1143 $r->evalsha(sha1, numkeys, key [key ...], arg [arg ...])
1144
1145 Execute a Lua script server side (see
1146 <http://redis.io/commands/evalsha>)
1147
1148 script_exists
1149 $r->script_exists(script [script ...])
1150
1151 Check existence of scripts in the script cache. (see
1152 <http://redis.io/commands/script-exists>)
1153
1154 script_flush
1155 $r->script_flush()
1156
1157 Remove all the scripts from the script cache. (see
1158 <http://redis.io/commands/script-flush>)
1159
1160 script_kill
1161 $r->script_kill()
1162
1163 Kill the script currently in execution. (see
1164 <http://redis.io/commands/script-kill>)
1165
1166 script_load
1167 $r->script_load(script)
1168
1169 Load the specified Lua script into the script cache. (see
1170 <http://redis.io/commands/script-load>)
1171
1173 auth
1174 $r->auth(password)
1175
1176 Authenticate to the server (see <http://redis.io/commands/auth>)
1177
1178 echo
1179 $r->echo(message)
1180
1181 Echo the given string (see <http://redis.io/commands/echo>)
1182
1183 ping
1184 $r->ping()
1185
1186 Ping the server (see <http://redis.io/commands/ping>)
1187
1188 quit
1189 $r->quit()
1190
1191 Close the connection (see <http://redis.io/commands/quit>)
1192
1193 select
1194 $r->select(index)
1195
1196 Change the selected database for the current connection (see
1197 <http://redis.io/commands/select>)
1198
1200 bgrewriteaof
1201 $r->bgrewriteaof()
1202
1203 Asynchronously rewrite the append-only file (see
1204 <http://redis.io/commands/bgrewriteaof>)
1205
1206 bgsave
1207 $r->bgsave()
1208
1209 Asynchronously save the dataset to disk (see
1210 <http://redis.io/commands/bgsave>)
1211
1212 client_getname
1213 $r->client_getname()
1214
1215 Get the current connection name (see
1216 <http://redis.io/commands/client-getname>)
1217
1218 client_kill
1219 $r->client_kill([ip:port], [ID client-id], [TYPE normal|slave|pubsub], [ADDR ip:port], [SKIPME yes/no])
1220
1221 Kill the connection of a client (see
1222 <http://redis.io/commands/client-kill>)
1223
1224 client_list
1225 $r->client_list()
1226
1227 Get the list of client connections (see
1228 <http://redis.io/commands/client-list>)
1229
1230 client_pause
1231 $r->client_pause(timeout)
1232
1233 Stop processing commands from clients for some time (see
1234 <http://redis.io/commands/client-pause>)
1235
1236 client_setname
1237 $r->client_setname(connection-name)
1238
1239 Set the current connection name (see
1240 <http://redis.io/commands/client-setname>)
1241
1242 cluster_slots
1243 $r->cluster_slots()
1244
1245 Get array of Cluster slot to node mappings (see
1246 <http://redis.io/commands/cluster-slots>)
1247
1248 command
1249 $r->command()
1250
1251 Get array of Redis command details (see
1252 <http://redis.io/commands/command>)
1253
1254 command_count
1255 $r->command_count()
1256
1257 Get total number of Redis commands (see
1258 <http://redis.io/commands/command-count>)
1259
1260 command_getkeys
1261 $r->command_getkeys()
1262
1263 Extract keys given a full Redis command (see
1264 <http://redis.io/commands/command-getkeys>)
1265
1266 command_info
1267 $r->command_info(command-name [command-name ...])
1268
1269 Get array of specific Redis command details (see
1270 <http://redis.io/commands/command-info>)
1271
1272 config_get
1273 $r->config_get(parameter)
1274
1275 Get the value of a configuration parameter (see
1276 <http://redis.io/commands/config-get>)
1277
1278 config_resetstat
1279 $r->config_resetstat()
1280
1281 Reset the stats returned by INFO (see
1282 <http://redis.io/commands/config-resetstat>)
1283
1284 config_rewrite
1285 $r->config_rewrite()
1286
1287 Rewrite the configuration file with the in memory configuration (see
1288 <http://redis.io/commands/config-rewrite>)
1289
1290 config_set
1291 $r->config_set(parameter, value)
1292
1293 Set a configuration parameter to the given value (see
1294 <http://redis.io/commands/config-set>)
1295
1296 dbsize
1297 $r->dbsize()
1298
1299 Return the number of keys in the selected database (see
1300 <http://redis.io/commands/dbsize>)
1301
1302 debug_object
1303 $r->debug_object(key)
1304
1305 Get debugging information about a key (see
1306 <http://redis.io/commands/debug-object>)
1307
1308 debug_segfault
1309 $r->debug_segfault()
1310
1311 Make the server crash (see <http://redis.io/commands/debug-segfault>)
1312
1313 flushall
1314 $r->flushall()
1315
1316 Remove all keys from all databases (see
1317 <http://redis.io/commands/flushall>)
1318
1319 flushdb
1320 $r->flushdb()
1321
1322 Remove all keys from the current database (see
1323 <http://redis.io/commands/flushdb>)
1324
1325 info
1326 $r->info([section])
1327
1328 Get information and statistics about the server (see
1329 <http://redis.io/commands/info>)
1330
1331 lastsave
1332 $r->lastsave()
1333
1334 Get the UNIX time stamp of the last successful save to disk (see
1335 <http://redis.io/commands/lastsave>)
1336
1337 lindex
1338 $r->lindex(key, index)
1339
1340 Get an element from a list by its index (see
1341 <http://redis.io/commands/lindex>)
1342
1343 linsert
1344 $r->linsert(key, BEFORE|AFTER, pivot, value)
1345
1346 Insert an element before or after another element in a list (see
1347 <http://redis.io/commands/linsert>)
1348
1349 llen
1350 $r->llen(key)
1351
1352 Get the length of a list (see <http://redis.io/commands/llen>)
1353
1354 lpop
1355 $r->lpop(key)
1356
1357 Remove and get the first element in a list (see
1358 <http://redis.io/commands/lpop>)
1359
1360 lpush
1361 $r->lpush(key, value [value ...])
1362
1363 Prepend one or multiple values to a list (see
1364 <http://redis.io/commands/lpush>)
1365
1366 lpushx
1367 $r->lpushx(key, value)
1368
1369 Prepend a value to a list, only if the list exists (see
1370 <http://redis.io/commands/lpushx>)
1371
1372 lrange
1373 $r->lrange(key, start, stop)
1374
1375 Get a range of elements from a list (see
1376 <http://redis.io/commands/lrange>)
1377
1378 lrem
1379 $r->lrem(key, count, value)
1380
1381 Remove elements from a list (see <http://redis.io/commands/lrem>)
1382
1383 lset
1384 $r->lset(key, index, value)
1385
1386 Set the value of an element in a list by its index (see
1387 <http://redis.io/commands/lset>)
1388
1389 ltrim
1390 $r->ltrim(key, start, stop)
1391
1392 Trim a list to the specified range (see
1393 <http://redis.io/commands/ltrim>)
1394
1395 monitor
1396 $r->monitor()
1397
1398 Listen for all requests received by the server in real time (see
1399 <http://redis.io/commands/monitor>)
1400
1401 role
1402 $r->role()
1403
1404 Return the role of the instance in the context of replication (see
1405 <http://redis.io/commands/role>)
1406
1407 rpop
1408 $r->rpop(key)
1409
1410 Remove and get the last element in a list (see
1411 <http://redis.io/commands/rpop>)
1412
1413 rpoplpush
1414 $r->rpoplpush(source, destination)
1415
1416 Remove the last element in a list, append it to another list and return
1417 it (see <http://redis.io/commands/rpoplpush>)
1418
1419 rpush
1420 $r->rpush(key, value [value ...])
1421
1422 Append one or multiple values to a list (see
1423 <http://redis.io/commands/rpush>)
1424
1425 rpushx
1426 $r->rpushx(key, value)
1427
1428 Append a value to a list, only if the list exists (see
1429 <http://redis.io/commands/rpushx>)
1430
1431 save
1432 $r->save()
1433
1434 Synchronously save the dataset to disk (see
1435 <http://redis.io/commands/save>)
1436
1437 shutdown
1438 $r->shutdown([NOSAVE], [SAVE])
1439
1440 Synchronously save the dataset to disk and then shut down the server
1441 (see <http://redis.io/commands/shutdown>)
1442
1443 slaveof
1444 $r->slaveof(host, port)
1445
1446 Make the server a slave of another instance, or promote it as master
1447 (see <http://redis.io/commands/slaveof>)
1448
1449 slowlog
1450 $r->slowlog(subcommand, [argument])
1451
1452 Manages the Redis slow queries log (see
1453 <http://redis.io/commands/slowlog>)
1454
1455 sync
1456 $r->sync()
1457
1458 Internal command used for replication (see
1459 <http://redis.io/commands/sync>)
1460
1461 time
1462 $r->time()
1463
1464 Return the current server time (see <http://redis.io/commands/time>)
1465
1467 The following persons contributed to this project (random order):
1468
1469 • Aaron Crane (pipelining and AUTOLOAD caching support)
1470
1471 • Dirk Vleugels
1472
1473 • Flavio Poletti
1474
1475 • Jeremy Zawodny
1476
1477 • sunnavy at bestpractical.com
1478
1479 • Thiago Berlitz Rondon
1480
1481 • Ulrich Habel
1482
1483 • Ivan Kruglov
1484
1485 • Steffen Mueller <smueller@cpan.org>
1486
1488 • Pedro Melo <melo@cpan.org>
1489
1490 • Damien Krotkine <dams@cpan.org>
1491
1493 This software is Copyright (c) 2015 by Pedro Melo, Damien Krotkine.
1494
1495 This is free software, licensed under:
1496
1497 The Artistic License 2.0 (GPL Compatible)
1498
1499
1500
1501perl v5.34.0 2021-07-22 Redis(3pm)