Last active
June 10, 2023 22:20
-
-
Save supercaracal/31f8dfeb52aca0be693290c797f1988d to your computer and use it in GitHub Desktop.
A naive example for Redis migration from a standalone server to a cluster
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'redis-cluster-client' | |
end | |
src = RedisClient.config(url: ENV.fetch('REDIS_URL')).new_client | |
dest = RedisClient.cluster(nodes: ENV.fetch('REDIS_CLUSTER_URL')).new_client | |
node = dest.instance_variable_get(:@router).instance_variable_get(:@node) | |
src.scan do |key| | |
slot = RedisClient::Cluster::KeySlotConverter.convert(key) | |
node_key = node.find_node_key_of_primary(slot) | |
host, port = RedisClient::Cluster::NodeKey.split(node_key) | |
src.blocking_call(10, 'MIGRATE', host, port, key, 0, 7, 'COPY', 'REPLACE') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment