mongo2

package module
v3.0.0-...-1524b23 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2023 License: GPL-3.0 Imports: 11 Imported by: 0

README

MongoDB

【注意】使用MongoDB时,若需设置过期时间,只能在 NewMongoBackend() 函数中设置

Installation

go get -u github.com/gojuukaze/YTask/drives/mongo2/v3

Backend

package main

import (
    "github.com/gojuukaze/YTask/drives/mongo2/v3"
)

func main() {
	backend := mongo2.NewMongoBackend("127.0.0.1", "27017", "", "", "test", "test", 200)
	// ...
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

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

func NewMongoBackend

func NewMongoBackend(host, port, user, password, db, collection string, exTime int) Backend

NewMongoBackend

  • exTime: Expiration time in seconds. <=0: no expiration.

func (*Backend) Activate

func (r *Backend) Activate()

func (Backend) Clone

func (r Backend) Clone() backends.BackendInterface

func (*Backend) GetPoolSize

func (r *Backend) GetPoolSize() int

func (*Backend) GetResult

func (r *Backend) GetResult(key string) (message.Result, error)

func (*Backend) SetPoolSize

func (r *Backend) SetPoolSize(n int)

func (*Backend) SetResult

func (r *Backend) SetResult(result message.Result, exTime int) error

type Client

type Client struct {
	Uri        string
	DB         string
	Collection string
	Expires    int
	// contains filtered or unexported fields
}

func NewMongoClient

func NewMongoClient(host, port, user, password, db, collection string, expires int) *Client

NewMongoClient 经测试mongo-driver会自动断线重连,且自带连接池,但貌似设置连接池大小没有作用,因此就不需要poolSize选项了

func (*Client) Get

func (c *Client) Get(key string) (Result, error)

======================= high api =======================

func (*Client) GetClient

func (c *Client) GetClient(ctx context.Context) (*mongo.Client, error)

func (*Client) GetCollection

func (c *Client) GetCollection() *mongo.Collection

func (*Client) Init

func (c *Client) Init() error

func (*Client) InitIndex

func (c *Client) InitIndex(ctx context.Context, index mongo.IndexView) error

func (*Client) Set

func (c *Client) Set(key string, value []byte) error

type Result

type Result struct {
	Id         string    `json:"_id" bson:"_id"`
	Data       []byte    `json:"data" bson:"data"`
	CreateTime time.Time `json:"create_time" bson:"create_time"`
}

Jump to

Keyboard shortcuts

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