mantle

package
v0.0.0-...-2fd7b23 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2015 License: MIT Imports: 10 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultMemcacheIpAndHost = []string{"localhost:11211"}
View Source
var DefaultRedisConfig = []string{"localhost:6379"}

default host:port to connect

View Source
var MemcachePoolSize = 50
View Source
var MySQLPoolSize = 15

default pool size

View Source
var RedisPoolSize = 50

default pool size

Functions

func CreateMemcacheConnection

func CreateMemcacheConnection(Instance interface{}) (pools.Resource, error)

func CreateMySQLConnection

func CreateMySQLConnection(Instance interface{}) (pools.Resource, error)

This method creates a MySQL connection CreateMySQLConnection is passed as a callback to pools Instance:

This is a reference to a struct MySQL instance
Connect needs some params like db, hostAndPorts
These params are read from this instance rederence

func CreateRedisConnection

func CreateRedisConnection(Instance interface{}) (pools.Resource, error)

This method creates a redis connection CreateRedisConnection is passed as a callback to pools Instance:

This is a reference to a struct redis instance
Connect needs some params like db, hostAndPorts
These params are read from this instance rederence

Types

type MemConn

type MemConn struct {
	*memcache.Client
}

func (*MemConn) Close

func (m *MemConn) Close()

type Memcache

type Memcache struct {
	Settings PoolSettings
	// contains filtered or unexported fields
}

func (*Memcache) Configure

func (m *Memcache) Configure(settings PoolSettings)

func (*Memcache) Delete

func (m *Memcache) Delete(keys ...interface{}) (int, error)

func (*Memcache) Execute

func (m *Memcache) Execute(cmd string, args ...interface{}) (interface{}, error)

func (*Memcache) Expire

func (m *Memcache) Expire(key string, duration int) (bool, error)

func (*Memcache) Get

func (m *Memcache) Get(key string) (string, error)

func (*Memcache) GetClient

func (m *Memcache) GetClient() *MemConn

func (*Memcache) MGet

func (m *Memcache) MGet(keys ...interface{}) ([]string, error)

func (*Memcache) MSet

func (m *Memcache) MSet(keyValMap map[string]interface{}) (bool, error)

func (*Memcache) PutClient

func (m *Memcache) PutClient(c *MemConn)

func (*Memcache) SAdd

func (m *Memcache) SAdd(key string, values ...interface{}) (bool, error)

Raise unimplemented error

func (*Memcache) SRem

func (m *Memcache) SRem(key string, value string) (bool, error)

Raise unimplemented error

func (*Memcache) Set

func (m *Memcache) Set(key string, value interface{}) (bool, error)

func (*Memcache) SetDefaults

func (m *Memcache) SetDefaults()

func (*Memcache) Setex

func (m *Memcache) Setex(key string, duration int, val interface{}) (bool, error)

func (*Memcache) Sismember

func (m *Memcache) Sismember(key string, member string) (bool, error)

Raise unimplemented error

func (*Memcache) Sismembers

func (m *Memcache) Sismembers(key string, members []string) ([]bool, error)

func (*Memcache) Smembers

func (m *Memcache) Smembers(key string) ([]string, error)

All Set methods raise unimplemented error. Raise unimplemented error

func (*Memcache) StatsJSON

func (m *Memcache) StatsJSON() string

type MySQL

type MySQL struct {
	Settings PoolSettings
	// contains filtered or unexported fields
}

func (*MySQL) Configure

func (m *MySQL) Configure(settings PoolSettings)

func (*MySQL) GetConn

func (m *MySQL) GetConn() (*MySQLConn, error)

Gets a connection from pool and converts to MySQLConn type If all the connections are in use, timeout the present request after a minute

func (*MySQL) PutConn

func (m *MySQL) PutConn(c *MySQLConn)

Puts MySQL connection back to pool

func (*MySQL) Select

func (m *MySQL) Select(query string) ([]map[string]interface{}, error)

Execute all the methods for a SQL query over here Execute MySQL commands; Also has support for select * from table Gets a client from pool, executes a cmd, puts conn back in pool

func (*MySQL) SetDefaults

func (m *MySQL) SetDefaults()

type MySQLConn

type MySQLConn struct {
	sql.DB
}

Wrapping MySQL connection sql.db returns a db connection pointer

func (*MySQLConn) Close

func (m *MySQLConn) Close()

Close a MySQL connection

type PoolSettings

type PoolSettings struct {
	HostAndPorts []string
	Capacity     int
	MaxCapacity  int
	Options      map[string]string
	Timeout      time.Duration
}

This struct has all the generic settings that are required for creating a pool

type Redis

type Redis struct {
	Settings PoolSettings
	// contains filtered or unexported fields
}

func (*Redis) Configure

func (r *Redis) Configure(settings PoolSettings)

func (*Redis) Delete

func (r *Redis) Delete(keys ...interface{}) (int, error)

func (*Redis) Execute

func (r *Redis) Execute(cmd string, args ...interface{}) (interface{}, error)

Generic method to execute any redis call Gets a client from pool, executes a cmd, puts conn back in pool

func (*Redis) Expire

func (r *Redis) Expire(key string, duration int) (bool, error)

func (*Redis) Get

func (r *Redis) Get(key string) (string, error)

func (*Redis) GetClient

func (r *Redis) GetClient() (*RedisConn, error)

Gets a connection from pool and converts to RedisConn type If all the connections are in use, timeout the present request after a minute

func (*Redis) MGet

func (r *Redis) MGet(keys ...interface{}) ([]string, error)

func (*Redis) MSet

func (r *Redis) MSet(mapOfKeyVal map[string]interface{}) (bool, error)

func (*Redis) PutClient

func (r *Redis) PutClient(c *RedisConn)

Puts a connection back to pool

func (*Redis) SAdd

func (r *Redis) SAdd(key string, values ...interface{}) (bool, error)

redis SADD implementation

func (*Redis) SRem

func (r *Redis) SRem(key string, value string) (bool, error)

redis SREM implementation

func (*Redis) Set

func (r *Redis) Set(key string, value interface{}) (bool, error)

func (*Redis) SetDefaults

func (r *Redis) SetDefaults()

Add default settings if they are missing

func (*Redis) Setex

func (r *Redis) Setex(key string, duration int, val interface{}) (bool, error)

func (*Redis) Sismember

func (r *Redis) Sismember(key string, member string) (bool, error)

redis SISMEMBER implementation

func (*Redis) Sismembers

func (r *Redis) Sismembers(key string, members []string) ([]bool, error)

func (*Redis) Smembers

func (r *Redis) Smembers(key string) ([]string, error)

redis SMEMBERS implementation

func (*Redis) StatsJSON

func (r *Redis) StatsJSON() string

type RedisConn

type RedisConn struct {
	redis.Conn
}

Wrapping redigo redis connection

Pool expects a Object which defines
Close() and doesn't return anything, but
redigo.Redis#Close() returns error, hence this wrapper
around redis.Conn

func (*RedisConn) Close

func (r *RedisConn) Close()

Close a redis connection

type ResourcePool

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

Wraps pool

func NewPool

func NewPool(connect dialAndConnect, instance interface{}, settings PoolSettings) *ResourcePool
  • Creats an instance of pool Params: connect: A callback which creates a connection to datastore instace: An instance of backend(redis instance) settings: configurations needed to create a pool

func (*ResourcePool) GetConn

func (rp *ResourcePool) GetConn(to time.Duration) (pools.Resource, error)

Gets a connection from pool

func (*ResourcePool) PutConn

func (rp *ResourcePool) PutConn(conn pools.Resource)

Puts a connection back in pool

func (*ResourcePool) StatsJSON

func (rp *ResourcePool) StatsJSON() string

Jump to

Keyboard shortcuts

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