NAME

    Net::Async::Redis - talk to Redis servers via IO::Async

SYNOPSIS

        use Net::Async::Redis;
        use Future::AsyncAwait;
        use IO::Async::Loop;
        my $loop = IO::Async::Loop->new;
        $loop->add(my $redis = Net::Async::Redis->new);
        (async sub {
         await $redis->connect;
         my $value = await $redis->get('some_key');
         $value ||= await $redis->set(some_key => 'some_value');
         print "Value: $value";
        })->()->get;
    
        # You can also use ->then chaining, see L<Future> for more details
        $redis->connect->then(sub {
            $redis->get('some_key')
        })->then(sub {
            my $value = shift;
            return Future->done($value) if $value;
            $redis->set(some_key => 'some_value')
        })->on_done(sub {
            print "Value: " . shift;
        })->get;

DESCRIPTION

    Provides client access for dealing with Redis servers.

    See Net::Async::Redis::Commands for the full list of commands, this
    list is autogenerated from the official documentation here:

    https://redis.io/commands

    Note that this module uses Future::AsyncAwait.

METHODS

    NOTE: For a full list of the Redis methods supported by this module,
    please see Net::Async::Redis::Commands.

METHODS - Subscriptions

    See https://redis.io/topics/pubsub for more details on this topic.
    There's also more details on the internal implementation in Redis here:
    https://making.pusher.com/redis-pubsub-under-the-hood/.

 psubscribe

    Subscribes to a pattern.

    Returns a Future which resolves to a Net::Async::Redis::Subscription
    instance.

 subscribe

    Subscribes to one or more channels.

    Returns a Future which resolves to a Net::Async::Redis::Subscription
    instance.

    Example:

     # Subscribe to 'notifications' channel,
     # print the first 5 messages, then unsubscribe
     $redis->subscribe('notifications')
        ->then(sub {
            my $sub = shift;
            $sub->events
                ->map('payload')
                ->take(5)
                ->say
                ->completed
        })->then(sub {
            $redis->unsubscribe('notifications')
        })->get

METHODS - Transactions

 multi

    Executes the given code in a Redis MULTI transaction.

    This will cause each of the requests to be queued, then executed in a
    single atomic transaction.

    Example:

     $redis->multi(sub {
      my $tx = shift;
      $tx->incr('some::key')->on_done(sub { print "Final value for incremented key was " . shift . "\n"; });
      $tx->set('other::key => 'test data')
     })->then(sub {
      my ($success, $failure) = @_;
      return Future->fail("Had $failure failures, expecting everything to succeed") if $failure;
      print "$success succeeded\m";
      return Future->done;
     })->retain;

METHODS - Generic

 keys

 watch_keyspace

    A convenience wrapper around the keyspace notifications API.

    Provides the necessary setup to establish a PSUBSCRIBE subscription on
    the __keyspace@*__ namespace, setting the configuration required for
    this to start emitting events, and then calls $code with each event.

    Note that this will switch the connection into pubsub mode, so it will
    no longer be available for any other activity.

    Resolves to a Ryu::Source instance.

 endpoint

    The string describing the remote endpoint.

 local_endpoint

    A string describing the local endpoint, usually host:port.

 connect

    Connects to the Redis server.

 connected

    Establishes a connection if needed, otherwise returns an
    immediately-available Future instance.

 on_message

    Called for each incoming message.

    Passes off the work to "handle_pubsub_message" or the next queue item,
    depending on whether we're dealing with subscriptions at the moment.

 stream

    Represents the IO::Async::Stream instance for the active Redis
    connection.

 pipeline_depth

    Number of requests awaiting responses before we start queuing. This
    defaults to an arbitrary value of 100 requests.

    Note that this does not apply when in transaction (MULTI) mode.

    See https://redis.io/topics/pipelining for more details on this
    concept.

METHODS - Deprecated

    This are still supported, but no longer recommended.

METHODS - Internal

 notify_close

    Called when the socket is closed.

 command_label

    Generate a label for the given command list.

 stream_read_len

    Defines the buffer size when reading from a Redis connection.

    Defaults to 1MB, reduce this if you're dealing with a lot of
    connections and want to minimise memory usage. Alternatively, if you're
    reading large amounts of data and spend too much time in needless
    epoll_wait calls, try a larger value.

 stream_write_len

    The buffer size when writing to Redis connections, in bytes. Defaults
    to 1MB.

    See "stream_read_len".

SEE ALSO

    Some other Redis implementations on CPAN:

      * Mojo::Redis2 - nonblocking, using the Mojolicious framework,
      actively maintained

      * MojoX::Redis

      * RedisDB

      * Cache::Redis

      * Redis::Fast

      * Redis::Jet

      * Redis

AUTHOR

    Tom Molesworth <TEAM@cpan.org>, with patches and input from
    BINARY@cpan.org, PEVANS@cpan.org and @eyadof.

LICENSE

    Copyright Tom Molesworth and others 2015-2020. Licensed under the same
    terms as Perl itself.

