kv

package
v0.0.0-...-ef20d85 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RedisConfig

type RedisConfig struct {
	// Network "tcp"
	Network string
	// Addr "127.0.0.1:6379"
	Addr string
	// Password string .If no password then no 'AUTH'. Default ""
	Password string
	// If Database is empty "" then no 'SELECT'. Default ""
	Database string
	// MaxIdle 0 no limit
	MaxIdle int
	// MaxActive 0 no limit
	MaxActive int
	// IdleTimeout  time.Duration(5) * time.Minute
	IdleTimeout time.Duration
}

var ( ErrRedisClosed an error with message 'Redis is already closed' ErrRedisClosed = errors.New("Redis is already closed") ErrKeyNotFound an error with message 'Key $thekey doesn't found' ErrKeyNotFound = errors.New("Key '%s' doesn't found") )

type Service

type Service struct {
	// // Connected is true when the Service has already connected
	// Connected bool
	// // Config the redis config for this redis
	Redis redis.Conn
}

Service the Redis service, contains the config and the redis Pool

func NewService

func NewService(cli redis.Conn) *Service

func (*Service) AllExist

func (r *Service) AllExist(keys ...string) (bool, error)

func (*Service) Close

func (r *Service) Close() error

func (*Service) Delete

func (r *Service) Delete(key string) error

Delete removes redis entry by specific key

func (*Service) Exists

func (r *Service) Exists(key string) (bool, error)

func (*Service) Expire

func (r *Service) Expire(key string, newSecondsLifeTime int64) error

func (*Service) Expires

func (r *Service) Expires(seconds int64, keys ...string) error

func (*Service) Get

func (r *Service) Get(key interface{}) (interface{}, error)

func (*Service) GetAll

func (r *Service) GetAll() (interface{}, error)

GetAll returns all redis entries using the "SCAN" command (2.8+).

func (*Service) GetBytes

func (r *Service) GetBytes(key string) ([]byte, error)

GetBytes returns value, err by its key you can use utils.Deserialize((.GetBytes("yourkey"),&theobject{}) returns nil and a filled error if something wrong happens

func (*Service) GetJson

func (r *Service) GetJson(key string, out interface{}) error

func (*Service) GetMap

func (r *Service) GetMap(key string) (map[string]interface{}, error)

func (*Service) HGet

func (r *Service) HGet(key, field string, result interface{}) error

func (*Service) HGetAsMap

func (r *Service) HGetAsMap(key, field string) (map[string]interface{}, error)

func (*Service) HMGet

func (r *Service) HMGet(key string, result interface{}, fields ...string) error

func (*Service) HMGetAll

func (r *Service) HMGetAll(key string, result interface{}) error

result: *map[string]interface{}

func (*Service) HMSet

func (r *Service) HMSet(key string, kvs map[string]interface{}, secondsLifetime int64) error

func (*Service) HSet

func (r *Service) HSet(key, field string, value interface{}, secondsLifetime int64) (err error)

func (*Service) LGet

func (r *Service) LGet(key string, index int, value interface{}) error

func (*Service) LGetAll

func (r *Service) LGetAll(key string, result interface{}) error

result : is a list point ,eg result = &a ; a is var a []Obj

func (*Service) LLen

func (r *Service) LLen(key string) (int, error)

func (*Service) LSet

func (r *Service) LSet(key string, objs interface{}, secondsLifetime int64) error

objs : a list , eg. []xxx

func (*Service) PingPong

func (r *Service) PingPong() (bool, error)

PingPong sends a ping and receives a pong, if no pong received then returns false and filled error

func (*Service) Publish

func (r *Service) Publish(channel string, msg interface{}) (int, error)

func (*Service) Set

func (r *Service) Set(key interface{}, value interface{}, seconds int) error

Get returns value, err by its key returns nil and a filled error if something bad happened.

func (*Service) SetJson

func (r *Service) SetJson(key string, value interface{}, secondsLifetime int64) (err error)

func (*Service) Subscribe

func (r *Service) Subscribe(channel string) (*redis.PubSubConn, error)

func (*Service) TTL

func (r *Service) TTL(key string) (seconds int64, hasExpiration bool, found bool)

TTL returns the seconds to expire, if the key has expiration and error if action failed. Read more at: https://redis.io/commands/ttl

type ServiceFactory

type ServiceFactory struct {
	Config *RedisConfig
	Pool   *redis.Pool
}
var MainRedis *ServiceFactory

func NewFactory

func NewFactory(Config *RedisConfig) *ServiceFactory

func (*ServiceFactory) Get

func (s *ServiceFactory) Get() *Service

Jump to

Keyboard shortcuts

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