github.com/gogf/gf/v2@v2.7.4/database/gredis/gredis_redis_group_pubsub.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/gogf/gf.
     6  
     7  package gredis
     8  
     9  import (
    10  	"context"
    11  	"fmt"
    12  )
    13  
    14  // IGroupPubSub manages redis pub/sub operations.
    15  // Implements see redis.GroupPubSub.
    16  type IGroupPubSub interface {
    17  	Publish(ctx context.Context, channel string, message interface{}) (int64, error)
    18  	Subscribe(ctx context.Context, channel string, channels ...string) (Conn, []*Subscription, error)
    19  	PSubscribe(ctx context.Context, pattern string, patterns ...string) (Conn, []*Subscription, error)
    20  }
    21  
    22  // Message received as result of a PUBLISH command issued by another client.
    23  type Message struct {
    24  	Channel      string
    25  	Pattern      string
    26  	Payload      string
    27  	PayloadSlice []string
    28  }
    29  
    30  // Subscription received after a successful subscription to channel.
    31  type Subscription struct {
    32  	Kind    string // Can be "subscribe", "unsubscribe", "psubscribe" or "punsubscribe".
    33  	Channel string // Channel name we have subscribed to.
    34  	Count   int    // Number of channels we are currently subscribed to.
    35  }
    36  
    37  // String converts current object to a readable string.
    38  func (m *Subscription) String() string {
    39  	return fmt.Sprintf("%s: %s", m.Kind, m.Channel)
    40  }