# REPLICAOF

> Make this server a replica of another HotKV server, or stop replicating and become a primary again.

URL: https://docs.hotkv.com/commands/replicaof/

```
REPLICAOF host port
REPLICAOF NO ONE
```

- Group: Server
- Complexity: O(1)
- HotKV Cloud: all plans
- On-Premise: no license needed

`REPLICAOF host port` makes the server a replica of the HotKV server at `host`
and `port`, its client port. The replica copies the primary's data, then follows every
write. It replies `OK` at once and does the copy in the background; until it has
finished, commands that read or write data get `LOADING`. A replica that already follows
another server switches to the new one. Make it permanent with `replicaof host port` in the
configuration file. See [replication](https://docs.hotkv.com/operate/replication/index.md) for setting up replicas.

`REPLICAOF NO ONE` makes a replica stop following its primary and become a primary itself,
keeping its data. On a server that is already a primary it does nothing and replies
`OK`. `NO ONE` is matched case-insensitively.

Only a HotKV server can be the primary: a replica pointed at a Redis or Valkey
server stays in `master_link_status:down`, and the other way round too.

## Return value

| Case | Reply (RESP2 and RESP3) |
| --- | --- |
| `host port` accepted, or `NO ONE` succeeded, or the server already is a primary | Simple string `OK` |
| `NO ONE` failed | Error `ERR Replication could not start as primary, see the server log` |
| Cluster mode | Error `ERR REPLICAOF not allowed in cluster mode.` |

## Examples

```
127.0.0.1:8601> REPLICAOF 127.0.0.1 8600
OK
127.0.0.1:8601> ROLE
1) "slave"
2) "127.0.0.1"
3) (integer) 8600
4) "connected"
5) (integer) 38
127.0.0.1:8601> SET greeting hi
(error) READONLY You can't write against a read only replica.
127.0.0.1:8601> REPLICAOF NO ONE
OK
127.0.0.1:8601> SET greeting promoted
OK
127.0.0.1:8601> ROLE
1) "master"
2) (integer) 79
3) (empty array)
```

In HotKV Cloud, the CLI tab of the panel does not run `REPLICAOF`.

## Compatibility

Redis 7 and Valkey 8 accept both forms at runtime, and HotKV does too. A HotKV
replica cannot follow a Redis or Valkey primary. In cluster mode, use
[CLUSTER REPLICATE](https://docs.hotkv.com/commands/cluster-replicate/index.md) and
[CLUSTER FAILOVER](https://docs.hotkv.com/commands/cluster-failover/index.md), as in Redis.

## See also

[SLAVEOF](https://docs.hotkv.com/commands/slaveof/index.md), [ROLE](https://docs.hotkv.com/commands/role/index.md),
[REPLICATION.FAILOVER](https://docs.hotkv.com/commands/replication-failover/index.md), [FAILOVER](https://docs.hotkv.com/commands/failover/index.md),
[Replication](https://docs.hotkv.com/operate/replication/index.md)

In a cluster: [Replicas and failover](https://docs.hotkv.com/clustering/replicas-and-failover/index.md)