github.com/juju/mgosession/v2
go get github.com/juju/mgosession/v2

github.com/juju/mgosession/v2

Session pooling for the mgo package

by juju

v2.0.0 (see all)License:LGPL-3.0
go get github.com/juju/mgosession/v2
Readme

mgosession

-- import "github.com/juju/mgosession"

Package mgosession provides multiplexing for MongoDB sessions. It is designed so that many concurrent operations can be performed without using one MongoDB socket connection for each operation.

Usage

var Clock clock.Clock = clock.WallClock

type Pool

type Pool struct {
}

Pool represents a pool of mgo sessions.

func NewPool

func NewPool(ctx context.Context, s *mgo.Session, maxSessions int) *Pool

NewPool returns a session pool that maintains a maximum of maxSessions sessions available for reuse.

func (*Pool) Close

func (p *Pool) Close()

Close closes the pool. It may be called concurrently with other Pool methods, but once called, a call to Session will panic.

func (*Pool) Reset

func (p *Pool) Reset()

Reset resets the session pool so that no existing sessions will be reused. This should be called when an unexpected error has been encountered using a session.

func (*Pool) Session

func (p *Pool) Session(ctx context.Context) *mgo.Session

Session returns a new session from the pool. It may reuse an existing session that has not been marked with DoNotReuse.

Session may be called concurrently.

GitHub Stars

11

LAST COMMIT

1yr ago

MAINTAINERS

0

CONTRIBUTORS

5

OPEN ISSUES

0

OPEN PRs

0
VersionTagPublished
v2.0.0
1yr ago
No alternatives found
No tutorials found
Add a tutorial