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_dryrun, acl_genpass, acl_getuser, 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, bzmpop, 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_addslotsrange, cluster_bumpepoch, cluster_count_failure_reports, cluster_countkeysinslot, cluster_delslots, cluster_delslotsrange, cluster_failover, cluster_flushslots, cluster_forget, cluster_getkeysinslot, cluster_info, cluster_keyslot, cluster_links, 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_docs, command_getkeys, command_info, command_list, config_get, config_resetstat, config_rewrite, config_set, copy, dbsize, decr, decrby, del, discard, dump, echo, eval, eval_ro, evalsha, evalsha_ro, exec, exists, expire, expireat, expiretime, failover, fcall, fcall_ro, flushall, flushdb, function_delete, function_dump, function_flush, function_kill, function_list, function_load, function_restore, function_stats, geoadd, geodist, geohash, geopos, georadius, georadius_ro, georadiusbymember, georadiusbymember_ro, 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_histogram, latency_history, latency_latest, latency_reset, lcs, lindex, linsert, llen, lmove, lmpop, lolwut, lpop, lpos, lpush, lpushx, lrange, lrem, lset, ltrim, memory_doctor, memory_malloc_stats, memory_purge, memory_stats, memory_usage, mget, migrate, module_list, module_load, module_unload, monitor, move, mset, msetnx, multi, object_encoding, object_freq, object_idletime, object_refcount, persist, pexpire, pexpireat, pexpiretime, pfadd, pfcount, pfdebug, pfmerge, pfselftest, ping, psetex, psubscribe, psync, pttl, publish, pubsub_channels, pubsub_numpat, pubsub_numsub, pubsub_shardchannels, punsubscribe, quit, randomkey, readonly, readwrite, rename, renamenx, replconf, replicaof, reset, restore, restore_asking, 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_get, slowlog_len, slowlog_reset, smembers, smismember, smove, sort, sort_ro, spop, spublish, srandmember, srem, sscan, ssubscribe, strlen, subscribe, substr, sunion, sunionstore, sunsubscribe, swapdb, sync, time, touch, ttl, type, unlink, unsubscribe, unwatch, wait, watch, xack, xadd, xautoclaim, xclaim, xdel, xgroup_create, xgroup_createconsumer, xgroup_delconsumer, xgroup_destroy, xgroup_setid, xinfo_consumers, xinfo_groups, xinfo_stream, xlen, xpending, xrange, xread, xreadgroup, xrevrange, xsetid, xtrim, zadd, zcard, zcount, zdiff, zdiffstore, zincrby, zinter, zintercard, zinterstore, zlexcount, zmpop, 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-2022. Licensed under the same terms as Perl itself.