mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-05 16:57:06 +08:00
42 lines
1.2 KiB
Go
42 lines
1.2 KiB
Go
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)
|
|
}
|