Documentation ¶
Overview ¶
Example (OpenSubscriptionFromURL) ¶
package main import ( "context" "log" "github.com/sraphs/gdk/pubsub" ) func main() { // PRAGMA: This example is used on github.com/sraphs/gdk; PRAGMA comments adjust how it is shown and can be ignored. // PRAGMA: On github.com/sraphs/gdk, add a blank import: _ "github.com/sraphs/gdk/pubsub/redispubsub" // PRAGMA: On github.com/sraphs/gdk, hide lines until the next blank line. ctx := context.Background() // pubsub.OpenSubscription creates a *pubsub.Subscription from a URL. // This URL will Dial the Redis server at the URL in the environment variable // REDIS_SERVER_URL and receive messages with nodeID "node-1" and subject "example.my-topic". subscription, err := pubsub.OpenSubscription(ctx, "redis://node-1?topic=my-topic") if err != nil { log.Fatal(err) } defer subscription.Shutdown(ctx) }
Output:
Example (OpenTopicFromURL) ¶
package main import ( "context" "log" "github.com/sraphs/gdk/pubsub" ) func main() { // PRAGMA: This example is used on github.com/sraphs/gdk; PRAGMA comments adjust how it is shown and can be ignored. // PRAGMA: On github.com/sraphs/gdk, add a blank import: _ "github.com/sraphs/gdk/pubsub/redispubsub" // PRAGMA: On github.com/sraphs/gdk, hide lines until the next blank line. ctx := context.Background() // pubsub.OpenTopic creates a *pubsub.Topic from a URL. // This URL will Dial the Redis server at the URL in the environment variable // REDIS_SERVER_URL and send messages with subject "example.my-topic". topic, err := pubsub.OpenTopic(ctx, "redis://example.my-topic") if err != nil { log.Fatal(err) } defer topic.Shutdown(ctx) }
Output:
Index ¶
Examples ¶
Constants ¶
const Scheme = "redis"
Scheme is the URL scheme redispubsub registers its URLOpeners under on pubsub.DefaultMux.
Variables ¶
This section is empty.
Functions ¶
func OpenSubscription ¶
func OpenSubscription(rc *redis.Client, nodeID string, channels []string, opts *SubscriptionOptions) (*pubsub.Subscription, error)
OpenSubscription returns a *pubsub.Subscription representing a Redis Subscribe. The channel is the Redis Channel to subscribe to; for more info, see https://redis.io/commands/pubsub-channels/.
Example ¶
// PRAGMA: This example is used on github.com/sraphs/gdk; PRAGMA comments adjust how it is shown and can be ignored. // PRAGMA: On github.com/sraphs/gdk, hide lines until the next blank line. ctx := context.Background() opt, err := redis.ParseURL("redis://localhost:6379") if err != nil { log.Fatal(err) } client := redis.NewClient(opt) defer client.Close() subscription, err := redispubsub.OpenSubscription(client, "node-1", []string{"example.my-topic"}, nil) if err != nil { log.Fatal(err) } defer subscription.Shutdown(ctx)
Output:
func OpenTopic ¶
func OpenTopic(rc *redis.Client, channel string, _ *TopicOptions) (*pubsub.Topic, error)
OpenTopic returns a *pubsub.Topic for use with Redis. The channel is the Redis Chanel; for more info, see https://redis.io/commands/pubsub-channels.
Example ¶
// PRAGMA: This example is used on github.com/sraphs/gdk; PRAGMA comments adjust how it is shown and can be ignored. // PRAGMA: On github.com/sraphs/gdk, hide lines until the next blank line. ctx := context.Background() opt, err := redis.ParseURL("redis://localhost:6379") if err != nil { log.Fatal(err) } client := redis.NewClient(opt) defer client.Close() topic, err := redispubsub.OpenTopic(client, "example.my-topic", nil) if err != nil { log.Fatal(err) } defer topic.Shutdown(ctx)
Output:
Types ¶
type SubscriptionOptions ¶
type SubscriptionOptions struct{}
SubscriptionOptions sets options for constructing a *pubsub.Subscription backed by Redis.
type TopicOptions ¶
type TopicOptions struct{}
TopicOptions sets options for constructing a *pubsub.Topic backed by Redis.
type URLOpener ¶
type URLOpener struct { // Client to use for communication with the server. Client *redis.Client // TopicOptions specifies the options to pass to OpenTopic. TopicOptions TopicOptions // SubscriptionOptions specifies the options to pass to OpenSubscription. SubscriptionOptions SubscriptionOptions }
URLOpener opens Redis URLs like "redis://my-topic".
The URL host+path is used as the subject.
No query parameters are supported.
func (*URLOpener) OpenSubscriptionURL ¶
func (o *URLOpener) OpenSubscriptionURL(ctx context.Context, u *url.URL) (*pubsub.Subscription, error)
OpenSubscriptionURL opens a pubsub.Subscription based on u.