The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

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

SYNOPSIS

    use Net::Async::Redis;
    use IO::Async::Loop;
    my $loop = IO::Async::Loop->new;
    $loop->add(my $redis = Net::Async::Redis->new);
    $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;

    # ... or with Future::AsyncAwait
    await $redis->connect;
    my $value = await $redis->get('some_key');
    $value ||= await $redis->set(some_key => 'some_value');
    print "Value: $value";

DESCRIPTION

See Net::Async::Redis::Commands for the full list of commands.

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.

subscribe

Subscribes to one or more channels.

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->map('payload')
            ->take(5)
            ->say
            ->completion
    })->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

connect

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

SEE ALSO

Some other Redis implementations on CPAN:

INHERITED METHODS

Net::Async::Redis::Commands

append, auth, bgrewriteaof, bgsave, bitcount, bitfield, bitop, bitpos, blpop, brpop, brpoplpush, bzpopmax, bzpopmin, client_getname, client_id, client_kill, client_list, client_pause, client_reply, client_setname, client_unblock, cluster_addslots, cluster_count_failure_reports, cluster_countkeysinslot, cluster_delslots, cluster_failover, cluster_forget, cluster_getkeysinslot, cluster_info, cluster_keyslot, cluster_meet, cluster_nodes, cluster_replicas, cluster_replicate, cluster_reset, cluster_saveconfig, cluster_set_config_epoch, cluster_setslot, cluster_slaves, cluster_slots, command, command_count, command_getkeys, command_info, config_get, config_resetstat, config_rewrite, config_set, dbsize, debug_object, debug_segfault, decr, decrby, del, dump, echo, eval, evalsha, exists, expire, expireat, flushall, flushdb, geoadd, geodist, geohash, geopos, georadius, georadiusbymember, get, getbit, getrange, getset, hdel, hexists, hget, hgetall, hincrby, hincrbyfloat, hkeys, hlen, hmget, hmset, hscan, hset, hsetnx, hstrlen, hvals, incr, incrby, incrbyfloat, info, lastsave, lindex, linsert, llen, lpop, lpush, lpushx, lrange, lrem, lset, ltrim, memory_doctor, memory_help, memory_malloc_stats, memory_purge, memory_stats, memory_usage, mget, migrate, monitor, move, mset, msetnx, object, persist, pexpire, pexpireat, pfadd, pfcount, pfmerge, ping, psetex, pttl, publish, pubsub, punsubscribe, quit, randomkey, readonly, readwrite, rename, renamenx, replicaof, restore, role, rpop, rpoplpush, rpush, rpushx, sadd, save, scan, scard, script_debug, script_exists, script_flush, script_kill, script_load, sdiff, sdiffstore, select, set, setbit, setex, setnx, setrange, shutdown, sinter, sinterstore, sismember, slaveof, slowlog, smembers, smove, sort, spop, srandmember, srem, sscan, strlen, sunion, sunionstore, swapdb, sync, time, touch, ttl, type, unlink, unsubscribe, unwatch, wait, watch, xack, xadd, xclaim, xdel, xgroup, xinfo, xlen, xpending, xrange, xread, xreadgroup, xrevrange, xtrim, zadd, zcard, zcount, zincrby, zinterstore, zlexcount, zpopmax, zpopmin, zrange, zrangebylex, zrangebyscore, zrank, zrem, zremrangebylex, zremrangebyrank, zremrangebyscore, zrevrange, zrevrangebylex, zrevrangebyscore, zrevrank, zscan, zscore, zunionstore

IO::Async::Notifier

add_child, adopt_future, can_event, children, configure_unknown, debug_printf, get_loop, invoke_error, invoke_event, loop, make_event_cb, maybe_invoke_event, maybe_make_event_cb, new, notifier_name, parent, remove_child, remove_from_parent

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-2018. Licensed under the same terms as Perl itself.