...

Source file src/github.com/redis/go-redis/v9/pubsub_commands.go

Documentation: github.com/redis/go-redis/v9

     1  package redis
     2  
     3  import "context"
     4  
     5  type PubSubCmdable interface {
     6  	Publish(ctx context.Context, channel string, message interface{}) *IntCmd
     7  	SPublish(ctx context.Context, channel string, message interface{}) *IntCmd
     8  	PubSubChannels(ctx context.Context, pattern string) *StringSliceCmd
     9  	PubSubNumSub(ctx context.Context, channels ...string) *MapStringIntCmd
    10  	PubSubNumPat(ctx context.Context) *IntCmd
    11  	PubSubShardChannels(ctx context.Context, pattern string) *StringSliceCmd
    12  	PubSubShardNumSub(ctx context.Context, channels ...string) *MapStringIntCmd
    13  }
    14  
    15  // Publish posts the message to the channel.
    16  func (c cmdable) Publish(ctx context.Context, channel string, message interface{}) *IntCmd {
    17  	cmd := NewIntCmd(ctx, "publish", channel, message)
    18  	_ = c(ctx, cmd)
    19  	return cmd
    20  }
    21  
    22  func (c cmdable) SPublish(ctx context.Context, channel string, message interface{}) *IntCmd {
    23  	cmd := NewIntCmd(ctx, "spublish", channel, message)
    24  	_ = c(ctx, cmd)
    25  	return cmd
    26  }
    27  
    28  func (c cmdable) PubSubChannels(ctx context.Context, pattern string) *StringSliceCmd {
    29  	args := []interface{}{"pubsub", "channels"}
    30  	if pattern != "*" {
    31  		args = append(args, pattern)
    32  	}
    33  	cmd := NewStringSliceCmd(ctx, args...)
    34  	_ = c(ctx, cmd)
    35  	return cmd
    36  }
    37  
    38  func (c cmdable) PubSubNumSub(ctx context.Context, channels ...string) *MapStringIntCmd {
    39  	args := make([]interface{}, 2+len(channels))
    40  	args[0] = "pubsub"
    41  	args[1] = "numsub"
    42  	for i, channel := range channels {
    43  		args[2+i] = channel
    44  	}
    45  	cmd := NewMapStringIntCmd(ctx, args...)
    46  	_ = c(ctx, cmd)
    47  	return cmd
    48  }
    49  
    50  func (c cmdable) PubSubShardChannels(ctx context.Context, pattern string) *StringSliceCmd {
    51  	args := []interface{}{"pubsub", "shardchannels"}
    52  	if pattern != "*" {
    53  		args = append(args, pattern)
    54  	}
    55  	cmd := NewStringSliceCmd(ctx, args...)
    56  	_ = c(ctx, cmd)
    57  	return cmd
    58  }
    59  
    60  func (c cmdable) PubSubShardNumSub(ctx context.Context, channels ...string) *MapStringIntCmd {
    61  	args := make([]interface{}, 2+len(channels))
    62  	args[0] = "pubsub"
    63  	args[1] = "shardnumsub"
    64  	for i, channel := range channels {
    65  		args[2+i] = channel
    66  	}
    67  	cmd := NewMapStringIntCmd(ctx, args...)
    68  	_ = c(ctx, cmd)
    69  	return cmd
    70  }
    71  
    72  func (c cmdable) PubSubNumPat(ctx context.Context) *IntCmd {
    73  	cmd := NewIntCmd(ctx, "pubsub", "numpat")
    74  	_ = c(ctx, cmd)
    75  	return cmd
    76  }
    77  

View as plain text