mongo

package
v0.10.3 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

README

MongoDB KV-Store

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option struct {
	Timeout time.Duration
}

Option redis option

type Store

type Store struct {
	Database   *mongo.Database
	Collection *mongo.Collection
	Option     Option
}

Store redis store

func New

func New(c connector.Connector) (*Store, error)

New create a new store via connector

func (*Store) Clear

func (store *Store) Clear()

Clear is used to clear the cache

func (*Store) Del

func (store *Store) Del(key string) error

Del remove is used to purge a key from the store

func (*Store) DelMulti

func (store *Store) DelMulti(keys []string)

DelMulti mulit remove values

func (*Store) Get

func (store *Store) Get(key string) (value interface{}, ok bool)

Get looks up a key's value from the store.

func (*Store) GetDel

func (store *Store) GetDel(key string) (value interface{}, ok bool)

GetDel looks up a key's value from the cache, then remove it.

func (*Store) GetMulti

func (store *Store) GetMulti(keys []string) map[string]interface{}

GetMulti mulit get values

func (*Store) GetSet

func (store *Store) GetSet(key string, ttl time.Duration, getValue func(key string) (interface{}, error)) (interface{}, error)

GetSet looks up a key's value from the cache. if does not exist add to the cache

func (*Store) GetSetMulti

func (store *Store) GetSetMulti(keys []string, ttl time.Duration, getValue func(key string) (interface{}, error)) map[string]interface{}

GetSetMulti mulit get values, if does not exist add to the cache

func (*Store) Has

func (store *Store) Has(key string) bool

Has check if the store is exist ( without updating recency or frequency )

func (*Store) Keys

func (store *Store) Keys() []string

Keys returns all the cached keys

func (*Store) Len

func (store *Store) Len() int

Len returns the number of stored entries (**not O(1)**)

func (*Store) Set

func (store *Store) Set(key string, value interface{}, ttl time.Duration) error

Set adds a value to the store.

func (*Store) SetMulti

func (store *Store) SetMulti(values map[string]interface{}, ttl time.Duration)

SetMulti mulit set values

Jump to

Keyboard shortcuts

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