File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -1423,6 +1423,16 @@ func (c *ClusterClient) cmdsMoved(
14231423 return nil
14241424}
14251425
1426+ // NewTransation returns a transaction, the related slot is determined by key.
1427+ func (c * ClusterClient ) NewTransation (ctx context.Context , key string ) (* Tx , error ) {
1428+ slot := hashtag .Slot (key )
1429+ node , err := c .slotMasterNode (ctx , slot )
1430+ if err != nil {
1431+ return nil , err
1432+ }
1433+ return node .Client .newTx (ctx ), nil
1434+ }
1435+
14261436func (c * ClusterClient ) Watch (ctx context.Context , fn func (* Tx ) error , keys ... string ) error {
14271437 if len (keys ) == 0 {
14281438 return fmt .Errorf ("redis: Watch requires at least one key" )
Original file line number Diff line number Diff line change 88 "time"
99
1010 "github.com/go-redis/redis/v8/internal"
11+ "github.com/go-redis/redis/v8/internal/hashtag"
1112 "github.com/go-redis/redis/v8/internal/pool"
1213 "github.com/go-redis/redis/v8/internal/proto"
1314 "go.opentelemetry.io/otel/label"
@@ -790,3 +791,16 @@ func (c *Conn) TxPipeline() Pipeliner {
790791 pipe .init ()
791792 return & pipe
792793}
794+
795+ func AreKeysInSameSlot (keys ... string ) bool {
796+ if len (keys ) == 0 {
797+ return true
798+ }
799+ slot := hashtag .Slot (keys [0 ])
800+ for _ , key := range keys [1 :] {
801+ if hashtag .Slot (key ) != slot {
802+ return false
803+ }
804+ }
805+ return true
806+ }
You can’t perform that action at this time.
0 commit comments