# CLUSTER REPLICATE

> Make the receiving node a replica of the given primary, or turn a replica back into an empty primary with NO ONE.

URL: https://docs.hotkv.com/commands/cluster-replicate/

```
CLUSTER REPLICATE node-id
CLUSTER REPLICATE NO ONE
```

- Group: Cluster
- Complexity: O(1)
- HotKV Cloud: not available
- On-Premise: no license needed

`CLUSTER REPLICATE node-id` turns the receiving node into a replica of the primary
with the given ID. The node starts copying the primary's data, saves its new
role to `nodes.conf`, and tells the other nodes. A replica that already
follows another primary switches to the new one. While the first copy runs, the
replica answers commands that read or write data with `LOADING`.

A primary can become a replica only while it is empty: it must serve no
slots and hold no keys (HotKV's AI feature data counts as keys here). Move
its slots away and empty it first.

`CLUSTER REPLICATE NO ONE` goes the other way. A replica stops following its primary and
becomes the primary of a shard of its own, with a new shard ID, no slots and no data: it
drops everything it had copied. Give it slots with
[CLUSTER ADDSLOTS](https://docs.hotkv.com/commands/cluster-addslots/index.md), or move slots to it
(see [Scaling a cluster](https://docs.hotkv.com/clustering/scaling/index.md)), or make it a replica again
with `CLUSTER REPLICATE node-id`. On a primary, `NO ONE` replies `OK` and changes
nothing.

In a cluster, use `CLUSTER REPLICATE` to set up replicas; `REPLICAOF`
belongs to non-cluster replication and is refused in cluster mode with `ERR REPLICAOF
not allowed in cluster mode.`

## Return value

Simple string `OK` in RESP2 and RESP3, or one of these errors:

| Case | Error |
| --- | --- |
| Unknown node ID | `ERR Unknown node <node-id>` |
| The node's own ID | `ERR Can't replicate myself` |
| The target is a replica | `ERR I can only replicate a master, not a replica.` |
| This node is a primary with slots or keys | `ERR To set a master the node must be empty and without assigned slots.` |
| Cluster mode is off | `ERR This instance has cluster support disabled` |

## Examples

```
127.0.0.1:7003> CLUSTER REPLICATE c5bcbe648892246dde31b5d78443297b493afb63
OK
127.0.0.1:7003> ROLE
1) "slave"
2) "127.0.0.1"
3) (integer) 7000
4) "connected"
5) (integer) 105
127.0.0.1:7003> CLUSTER REPLICATE NO ONE
OK
127.0.0.1:7003> ROLE
1) "master"
2) (integer) 123
3) (empty array)
```

Refused:

```
127.0.0.1:7000> CLUSTER REPLICATE ba074e3f3b7c3f622d2dc797baacec7229cb94ac
(error) ERR To set a master the node must be empty and without assigned slots.
127.0.0.1:7004> CLUSTER REPLICATE e7217a7e5c27c9b884f9edd0014a7b8c0a8f7056
(error) ERR I can only replicate a master, not a replica.
127.0.0.1:7001> CLUSTER REPLICATE e7217a7e5c27c9b884f9edd0014a7b8c0a8f7056
(error) ERR Can't replicate myself
```

## Compatibility

Same checks, replies and error strings as Redis 7 and Valkey 8. `NO ONE` is Valkey 9's
form.

## See also

[CLUSTER FAILOVER](https://docs.hotkv.com/commands/cluster-failover/index.md), [CLUSTER REPLICAS](https://docs.hotkv.com/commands/cluster-replicas/index.md),
[CLUSTER NODES](https://docs.hotkv.com/commands/cluster-nodes/index.md), [CLUSTER RESET](https://docs.hotkv.com/commands/cluster-reset/index.md),
[Replicas and failover](https://docs.hotkv.com/clustering/replicas-and-failover/index.md#add-a-replica)