package cluster import ( "github.com/hdt3213/godis/interface/redis" "github.com/hdt3213/godis/redis/reply" ) // Rename renames a key, the origin and the destination must within the same node func Rename(cluster *Cluster, c redis.Connection, args [][]byte) redis.Reply { if len(args) != 3 { return reply.MakeErrReply("ERR wrong number of arguments for 'rename' command") } src := string(args[1]) dest := string(args[2]) srcPeer := cluster.peerPicker.PickNode(src) destPeer := cluster.peerPicker.PickNode(dest) if srcPeer != destPeer { return reply.MakeErrReply("ERR rename must within one slot in cluster mode") } return cluster.relay(srcPeer, c, args) } // RenameNx renames a key, only if the new key does not exist. // The origin and the destination must within the same node func RenameNx(cluster *Cluster, c redis.Connection, args [][]byte) redis.Reply { if len(args) != 3 { return reply.MakeErrReply("ERR wrong number of arguments for 'renamenx' command") } src := string(args[1]) dest := string(args[2]) srcPeer := cluster.peerPicker.PickNode(src) destPeer := cluster.peerPicker.PickNode(dest) if srcPeer != destPeer { return reply.MakeErrReply("ERR rename must within one slot in cluster mode") } return cluster.relay(srcPeer, c, args) }