mgosession

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2018 License: LGPL-3.0 Imports: 6 Imported by: 15

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.

Documentation

Overview

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.

Index

Constants

This section is empty.

Variables

Functions

This section is empty.

Types

type Logger

type Logger interface {
	// Debug logs a message at debug level.
	Debug(message string)
	// Info logs a message at info level.
	Info(message string)
}

Logger is used by mgosession to log information about sessions.

type Pool

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

Pool represents a pool of mgo sessions.

func NewPool

func NewPool(logger Logger, s *mgo.Session, maxSessions int) *Pool

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

All the sessions will be coped (with Session.Copy) from s.

The logger is used to log informational messages about the pool and may be nil if no logging is required.

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(logger Logger) *mgo.Session

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

The logger is used to log requests associated with the session request and may be nil if no logging is required.

Session may be called concurrently.

Jump to

Keyboard shortcuts

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