im

package
v0.0.0-...-d31700d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2022 License: MIT Imports: 10 Imported by: 0

README

im

Package im implement instant messages by long poll. Multiple node is supported by redis publish/subscribe mechanism.

var im = New("redis://@localhost/0", "im", nil, logger.New(os.Stderr))

// Push a new version of business "notify" for user "bob" in "demo" system.
if err := im.Push("demo", []string{"bob"}, "notify"); err != nil {
    log.Panic(err)
}

// Pull new versions of businesses "notify" and "chats" for user "bob" in "demo" system.
// It blocked until get a new version of the businesses or reach the one second timeout.
// Only businesses that have a new version is returned in the map,
// an empty map is returned if no businesses has a new version.
if versions, err := im.Pull("demo", "bob", map[string]string{
    "notify": "1", "chats": ""
}, time.Second); err != nil {
    log.Panic(err)
} else {
    // prints something like: map[notify:2 chats:1]
    fmt.Println(versions)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IM

type IM struct {
	// contains filtered or unexported fields
}

func New

func New(redisUrl, redisChannel string, redisPool *redis.Pool, log *logger.Logger) *IM

func (*IM) Pull

func (im *IM) Pull(
	system, user string, versions map[string]string, timeout time.Duration,
) (map[string]string, error)

func (*IM) Push

func (im *IM) Push(system string, users []string, business string) error

func (*IM) RegisterBusinesses

func (im *IM) RegisterBusinesses(values ...string)

func (*IM) RegisterSystems

func (im *IM) RegisterSystems(values ...string)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL