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.
client_setname
Apply client name to all nodes.
Note that this only updates the current nodes, it will not apply to new nodes. Use the "client_name" in Net::Async::Redis constructor/"configure" parameter to apply to all nodes.
multi
A MULTI
transaction on a Redis cluster works slightly differently from single-node setups.
issue
MULTI
on all nodesexecute the commands, distributing across nodes as usual
issue
EXEC
orDISCARD
as appropriate
Note that the coderef is called only once, even if there are multiple nodes involved.
Currently, there's no optimisation for limiting MULTI
to the nodes participating in the transaction.
METHODS - All nodes
These methods operate on all nodes at once, and return the data in hashref mapping node ID to the response.
METHODS - Any node
These methods operate pick a random node to operate on, returning the data as if this was a regular Net::Async::Redis instance.
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, 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, bitcount, bitfield, bitfield_ro, bitop, bitpos, blmove, blmpop, blpop, brpop, brpoplpush, bzmpop, bzpopmax, bzpopmin, client, client_caching, client_getname, client_getredir, client_id, client_info, client_kill, client_list, client_no, client_no_evict, client_pause, client_reply, client_tracking, client_trackinginfo, client_unblock, client_unpause, cluster, cluster_addslots, cluster_addslotsrange, cluster_bumpepoch, cluster_count, cluster_count_failure, 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, cluster_set_config, cluster_set_config_epoch, cluster_setslot, cluster_slaves, cluster_slots, command, command_count, command_docs, command_getkeys, command_getkeysandflags, command_info, command_list, config, config_get, config_resetstat, config_rewrite, config_set, copy, dbsize, decr, decrby, del, dump, echo, eval, eval_ro, evalsha, evalsha_ro, exists, expire, expireat, expiretime, failover, fcall, fcall_ro, flushall, flushdb, function, 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, keys, lastsave, latency, 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, memory_doctor, memory_malloc, memory_malloc_stats, memory_purge, memory_stats, memory_usage, mget, migrate, module, module_list, module_load, module_unload, monitor, move, mset, msetnx, object, object_encoding, object_freq, object_idletime, object_refcount, persist, pexpire, pexpireat, pexpiretime, pfadd, pfcount, pfdebug, pfmerge, pfselftest, ping, psetex, psubscribe, psync, pttl, publish, pubsub, pubsub_channels, pubsub_numpat, pubsub_numsub, pubsub_shardchannels, pubsub_shardnumsub, punsubscribe, quit, randomkey, readonly, readwrite, rename, renamenx, replconf, replicaof, reset, restore, restore_asking, rpop, rpoplpush, rpush, rpushx, sadd, scan, scard, script, script_debug, script_exists, script_flush, script_kill, script_load, sdiff, sdiffstore, select, set, setbit, setex, setnx, setrange, sinter, sintercard, sinterstore, sismember, slaveof, slowlog, smembers, smismember, smove, sort, sort_ro, spop, spublish, srandmember, srem, sscan, ssubscribe, strlen, subscribe, substr, sunion, sunionstore, sunsubscribe, swapdb, sync, touch, ttl, type, unlink, unsubscribe, unwatch, wait, watch, xack, xadd, xautoclaim, xclaim, xdel, xgroup, xgroup_create, xgroup_createconsumer, xgroup_delconsumer, xgroup_destroy, xgroup_setid, xinfo, 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, notifier_name, parent, remove_child, remove_from_parent
- Object::Pad::UNIVERSAL
AUTHOR
Tom Molesworth <TEAM@cpan.org>
plus contributors as mentioned in "CONTRIBUTORS" in Net::Async::Redis.
LICENSE
Copyright Tom Molesworth and others 2015-2024. Licensed under the same terms as Perl itself.