Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

77 rindas
2.2 KiB

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