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