.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "AnyEvent::Redis 3pm" .TH AnyEvent::Redis 3pm 2024-03-04 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME AnyEvent::Redis \- Non\-blocking Redis client .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use AnyEvent::Redis; \& \& my $redis = AnyEvent::Redis\->new( \& host => \*(Aq127.0.0.1\*(Aq, \& port => 6379, \& encoding => \*(Aqutf8\*(Aq, \& on_error => sub { warn @_ }, \& on_cleanup => sub { warn "Connection closed: @_" }, \& ); \& \& # callback based \& $redis\->set( \*(Aqfoo\*(Aq=> \*(Aqbar\*(Aq, sub { warn "SET!" } ); \& $redis\->get( \*(Aqfoo\*(Aq, sub { my $value = shift } ); \& \& my ($key, $value) = (\*(Aqlist_key\*(Aq, 123); \& $redis\->lpush( $key, $value ); \& $redis\->lpop( $key, sub { my $value = shift }); \& \& # condvar based \& my $cv = $redis\->lpop( $key ); \& $cv\->cb(sub { my $value = $_[0]\->recv }); .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" AnyEvent::Redis is a non-blocking (event-driven) Redis client. .PP This module is an AnyEvent user; you must install and use a supported event loop. .SH "ESTABLISHING A CONNECTION" .IX Header "ESTABLISHING A CONNECTION" To create a new connection, use the \fBnew()\fR method with the following attributes: .IP "host => " 4 .IX Item "host => " \&\fBRequired.\fR The hostname or literal address of the server. .IP "port => " 4 .IX Item "port => " Optional. The server port. .IP "encoding => " 4 .IX Item "encoding => " Optional. Encode and decode data (when storing and retrieving, respectively) according to \fIENCODING\fR (\f(CW"utf8"\fR is recommended or see Encode::Supported for details on possible \fIENCODING\fR values). .Sp Omit if you intend to handle raw binary data with this connection. .ie n .IP "on_error => $cb\->($errmsg)" 4 .el .IP "on_error => \f(CW$cb\fR\->($errmsg)" 4 .IX Item "on_error => $cb->($errmsg)" Optional. Callback that will be fired if a connection or database-level error occurs. The error message will be passed to the callback as the sole argument. .ie n .IP "on_cleanup => $cb\->($errmsg)" 4 .el .IP "on_cleanup => \f(CW$cb\fR\->($errmsg)" 4 .IX Item "on_cleanup => $cb->($errmsg)" Optional. Callback that will be fired if a connection error occurs. The error message will be passed to the callback as the sole argument. After this callback, errors will be reported for all outstanding requests. .SH METHODS .IX Header "METHODS" All methods supported by your version of Redis should be supported. .SS "Normal commands" .IX Subsection "Normal commands" There are two alternative approaches for handling results from commands: .IP \(bu 4 AnyEvent::CondVar based: .Sp .Vb 3 \& my $cv = $redis\->command( \& # arguments to command \& ); \& \& # Then... \& my $res; \& eval { \& # Could die() \& $res = $cv\->recv; \& }; \& warn $@ if $@; \& \& # or... \& $cv\->cb(sub { \& my ($cv) = @_; \& my ($result, $err) = $cv\->recv \& }); .Ve .IP \(bu 4 Callback: .Sp .Vb 5 \& $redis\->command( \& # arguments, \& sub { \& my ($result, $err) = @_; \& }); .Ve .Sp (Callback is a wrapper around the \f(CW$cv\fR approach.) .SS "Transactions (MULTI/EXEC)" .IX Subsection "Transactions (MULTI/EXEC)" Redis transactions begin with a "multi" command and end with an "exec" command. Commands in between are not executed immediately when they're sent. On receipt of the "exec", the server executes all the saved commands atomically, and returns all their results as one bulk reply. .PP After a transaction is finished, results for each individual command are reported in the usual way. Thus, by the time any of these callbacks is called, the entire transaction is finished for better or worse. .PP Results of the "exec" (containing all the other results) will be returned as an array reference containing all of the individual results. This may in some cases make callbacks on the individual commands unnecessary, or vice versa. In this bulk reply, errors reported for each individual command are represented by objects of class \f(CW\*(C`AnyEvent::Redis::Error\*(C'\fR, which will respond to a \f(CW\*(C`\->message\*(C'\fR method call with that error message. .PP It is not permitted to nest transactions. This module does not permit subscription-related commands in a transaction. .SS Subscriptions .IX Subsection "Subscriptions" The subscription methods (\f(CW\*(C`subscribe\*(C'\fR and \f(CW\*(C`psubscribe\*(C'\fR) must be used with a callback: .PP .Vb 4 \& my $cv = $redis\->subscribe("test", sub { \& my ($message, $channel[, $actual_channel]) = @_; \& # ($actual_channel is provided for pattern subscriptions.) \& }); .Ve .PP The \f(CW$cv\fR condition will be met on unsubscribing from the channel. .PP Due to limitations of the Redis protocol the only valid commands on a connection with an active subscription are subscribe and unsubscribe commands. .SS "Common methods" .IX Subsection "Common methods" .IP \(bu 4 get .IP \(bu 4 set .IP \(bu 4 hset .IP \(bu 4 hget .IP \(bu 4 lpush .IP \(bu 4 lpop .PP The Redis command reference () lists all commands Redis supports. .SH REQUIREMENTS .IX Header "REQUIREMENTS" This requires Redis >= 1.2. .SH COPYRIGHT .IX Header "COPYRIGHT" Tatsuhiko Miyagawa 2009\- .SH LICENSE .IX Header "LICENSE" This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .SH AUTHORS .IX Header "AUTHORS" Tatsuhiko Miyagawa .PP David Leadbeater .PP Chia-liang Kao .PP franck cuny .PP Lee Aylward .PP Joshua Barratt .PP Jeremy Zawodny .PP Leon Brocard .PP Michael S. Fischer .PP Chip Salzenberg .SH "SEE ALSO" .IX Header "SEE ALSO" Redis, AnyEvent