Skip to content

Commit 5ff11a8

Browse files
authored
docs: delete housekeeping matters from an example code for readability (#212)
1 parent 19f66a4 commit 5ff11a8

File tree

1 file changed

+6
-23
lines changed

1 file changed

+6
-23
lines changed

README.md

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ You can see more information in the YAML file for GItHub actions.
224224

225225
## Migration
226226
This library might help you if you want to migrate your Redis from a standalone server to a cluster.
227+
Here is an example code.
227228

228229
```ruby
229230
# frozen_string_literal: true
@@ -235,38 +236,20 @@ gemfile do
235236
gem 'redis-cluster-client'
236237
end
237238

238-
src = RedisClient.config(
239-
host: ENV.fetch('REDIS_HOST'),
240-
port: ENV.fetch('REDIS_PORT')
241-
).new_client
242-
243-
dest = RedisClient.cluster(
244-
host: ENV.fetch('REDIS_CLUSTER_HOST'),
245-
port: ENV.fetch('REDIS_CLUSTER_PORT')
246-
).new_client
247-
248-
node = dest.instance_variable_get(:@router)
249-
.instance_variable_get(:@node)
239+
src = RedisClient.config(url: ENV.fetch('REDIS_URL')).new_client
240+
dest = RedisClient.cluster(nodes: ENV.fetch('REDIS_CLUSTER_URL')).new_client
241+
node = dest.instance_variable_get(:@router).instance_variable_get(:@node)
250242

251243
src.scan do |key|
252244
slot = ::RedisClient::Cluster::KeySlotConverter.convert(key)
253245
node_key = node.find_node_key_of_primary(slot)
254246
host, port = ::RedisClient::Cluster::NodeKey.split(node_key)
255-
256-
if host.nil? || port.nil? || key.nil?
257-
print "WARN: host=#{host}, port=#{port}, key=#{key}: could not get the destination node\n"
258-
next
259-
end
260-
261247
src.blocking_call(10, 'MIGRATE', host, port, key, 0, 7, 'COPY', 'REPLACE')
262-
rescue ::RedisClient::Error => e
263-
print "ERROR: host=#{host}, port=#{port}, key=#{key}: (#{e.class}) #{e.message}\n"
264248
end
265249
```
266250

267-
The above example is too naive.
268-
It may not be enough performance in the production environment that has tons of keys.
269-
Since [MIGRATE](https://redis.io/commands/migrate/) command does locking internally, we can use [DUMP](https://redis.io/commands/dump/) and [RESTORE](https://redis.io/commands/restore/) commands instead.
251+
It needs more enhancement to be enough performance in the production environment that has tons of keys.
252+
Also, it should handle errors.
270253

271254
## See also
272255
* https://redis.io/docs/reference/cluster-spec/

0 commit comments

Comments
 (0)