NAME

Net::Async::Redis::Cluster - support for cluster routing

SYNOPSIS

 use IO::Async::Loop;
 use Net::Async::Redis::Cluster;
 my $loop = IO::Async::Loop->new;
 $loop->add(
  my $cluster = Net::Async::Redis::Cluster->new(
  )
 );
 await $cluster->bootstrap(
  host => 'redis.local',
 );
 print "Key: " . await $cluster->get('some_key');

DESCRIPTION

Provides access to a Redis cluster.

Usage is similar to Net::Async::Redis with the addition of a "bootstrap" step to find the initial client nodes:

 $loop->add(
  my $cluster = Net::Async::Redis::Cluster->new(
  )
 );
 await $cluster->bootstrap(
  host => 'redis.local',
 );
 print "Key: " . await $cluster->get('some_key');

Note that this adds some overhead to lookups, so you may be better served by options such as the https://github.com/twitter/twemproxy|twemproxy proxy routing dæmon, or a service mesh such as https://istio.io/|istio.

METHODS

bootstrap

Connects to a Redis server and attempts to discover the cluster node configuration.

Usage:

 try {
  await $cluster->bootstrap(
   host => 'redis-primary.local',
   port => 6379,
  );
 } catch {
  $log->errorf('Unable to bootstrap the Redis cluster: %s', $@);
 }

clientside_cache_events

Provides combined stream of clientside-cache events from all known Redis primary nodes.

watch_keyspace

"watch_keyspace" in Net::Async::Redis support for gathering notifications from all known nodes.

METHODS - Internal

hash_slot_for_key

Calculates the CRC16 hash slot for the given key.

Note that keys are expected as bytestrings, if you have a Unicode string you'd likely want to convert to UTF-8 first.

replace_nodes

Swap the existing node configuration out for a new arrayref of nodes.

node_list

Returns a list of the currently-configured nodes.

node_for_slot

Returns the appropriate Net::Async::Redis::Cluster::Node for the given hash key (slot).

register_moved_slot

When we get MOVED error we will use this sub to rebuild the slot cache

apply_slots_from_instance

Connect to a random instance in the cluster and execute CLUSTER SLOTS to get information about the slots and their distribution.

execute_command

Lookup the correct node for the key then execute the command on that node, if there is a mismatch between our slot hashes and Redis's hashes we will attempt to rebuild the slot hashes and try again

ryu

A Ryu::Async instance for source/sink creation.

INHERITED METHODS

Net::Async::Redis::Commands

acl_cat, acl_deluser, acl_genpass, acl_getuser, acl_help, acl_list, acl_load, acl_log, acl_save, acl_setuser, acl_users, acl_whoami, append, asking, auth, bgrewriteaof, bgsave, bitcount, bitfield, bitfield_ro, bitop, bitpos, blmove, blmpop, blpop, brpop, brpoplpush, bzpopmax, bzpopmin, client_caching, client_getname, client_getredir, client_id, client_info, client_kill, client_list, client_no_evict, client_pause, client_reply, client_setname, client_tracking, client_trackinginfo, client_unblock, client_unpause, cluster_addslots, cluster_bumpepoch, cluster_count_failure_reports, cluster_countkeysinslot, cluster_delslots, cluster_failover, cluster_flushslots, cluster_forget, cluster_getkeysinslot, cluster_info, cluster_keyslot, cluster_meet, cluster_myid, 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, copy, dbsize, debug_object, debug_segfault, decr, decrby, del, discard, dump, echo, eval, eval_ro, evalsha, evalsha_ro, exec, exists, expire, expireat, expiretime, failover, flushall, flushdb, geoadd, geodist, geohash, geopos, georadius, georadiusbymember, geosearch, geosearchstore, get, getbit, getdel, getex, getrange, getset, hdel, hello, hexists, hget, hgetall, hincrby, hincrbyfloat, hkeys, hlen, hmget, hmset, hrandfield, hscan, hset, hsetnx, hstrlen, hvals, incr, incrby, incrbyfloat, info, keys, lastsave, latency_doctor, latency_graph, latency_help, latency_history, latency_latest, latency_reset, lindex, linsert, llen, lmove, lmpop, lolwut, lpop, lpos, lpush, lpushx, lrange, lrem, lset, ltrim, memory_doctor, memory_help, memory_malloc_stats, memory_purge, memory_stats, memory_usage, mget, migrate, module_list, module_load, module_unload, monitor, move, mset, msetnx, multi, object, persist, pexpire, pexpireat, pexpiretime, pfadd, pfcount, pfmerge, ping, psetex, psubscribe, psync, pttl, publish, pubsub, punsubscribe, quit, randomkey, readonly, readwrite, rename, renamenx, replicaof, reset, 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, sintercard, sinterstore, sismember, slaveof, slowlog, smembers, smismember, smove, sort, sort_ro, spop, srandmember, srem, sscan, stralgo, strlen, subscribe, sunion, sunionstore, swapdb, sync, time, touch, ttl, type, unlink, unsubscribe, unwatch, wait, watch, xack, xadd, xautoclaim, xclaim, xdel, xgroup, xinfo, xlen, xpending, xrange, xread, xreadgroup, xrevrange, xtrim, zadd, zcard, zcount, zdiff, zdiffstore, zincrby, zinter, zintercard, zinterstore, zlexcount, zmscore, zpopmax, zpopmin, zrandmember, zrange, zrangebylex, zrangebyscore, zrangestore, zrank, zrem, zremrangebylex, zremrangebyrank, zremrangebyscore, zrevrange, zrevrangebylex, zrevrangebyscore, zrevrank, zscan, zscore, zunion, zunionstore

IO::Async::Notifier

add_child, adopt_future, adopted_futures, 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> plus contributors as mentioned in "CONTRIBUTORS" in Net::Async::Redis.

LICENSE

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