cache

package module
v0.0.0-...-1442085 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2015 License: MIT Imports: 4 Imported by: 0

README

cache

Cache is the bottom layer to redis.

###To use this

go get github.com/LeeQY/cache

###The code

import (
	"github.com/LeeQY/cache"
)

// The redis address.
address := "localhost:6379"

// Open the connection pool.
// Pass in the address, max connections, idle duration.
Open(address, 1, 5*time.Second)

// Finally, close the connection pool.
defer Close()

// Check whether the key is existed.
exist, ok := cache.CheckCache(&key)

// Set a string cache.
ok = cache.SetStringCache(&key, &value)

// Set a bytes cache.
ok = cache.SetBytesCache(&key, &bytes)

// Get a string cache.
v, ok = cache.GetStringCache(&key)

// Get a bytes cache.
v, ok = cache.GetBytesCache(&key)

// Delete a cache.
ok = cache.DelCache(&key)

// Multiply set string caches with keys in one command.
ok = cache.MSetStringCache(&keys, &values)

// Multiply set bytes caches with keys in one command.
ok = cache.MSetBytesCache(&keys, &bytes)

// Multiply get string values in one command.
mv, err = cache.MGetStringCache(&keys)

// Multiply get bytes values in one command.
mv, err = cache.MGetBytesCache(&keys)

// Multiply delete keys in one command.
err = cache.MDelCache(&keys);

// Set a string cache with expiration
err = cache.SetStringCacheEX(&key, &value, ex)

// Set a bytes cache with expiration
err = cache.SetBytesCacheEX(&key, &bytes, ex)

// Update keys with expirations
err = cache.UpdateExpire(&keys, &exs)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckCache

func CheckCache(key *string) (bool, error)

Check whether a key is existed.

func Close

func Close()

Close the pool. Usually used when application ended.

func DelCache

func DelCache(key *string) error

Del the key

Return: error

func GetBytesCache

func GetBytesCache(key *string) ([]byte, error)

Get the cache bytes value for the key.

Return: value and ok

func GetCacheTTL

func GetCacheTTL(key *string) (int64, error)

Get a key's TTL.

Return -1 if no exp, -2 if not existed.

func GetStringCache

func GetStringCache(key *string) (*string, error)

Get the cache string value for the key.

Return: value and ok

func ListKeys

func ListKeys(offset int64, prefix *string) (int64, []string, error)

offset From where to scan. prefix The prefix string to scan.

Return: (offset, keys, error), if the offset is 0, means the scan is over.

func MDelCache

func MDelCache(keys []string) error

MDel the keys

Return: error

func MGetBytesCache

func MGetBytesCache(keys []string) ([][]byte, error)

MGet the cache bytes values for the keys.

Return: the values and ok. If the value for one is not exist, it will be nil

func MGetStringCache

func MGetStringCache(keys []string) ([]*string, error)

MGet the cache string values for the keys.

Return: the values and ok. If the value for one is not exist, it will be nil"

func MSetBytesCache

func MSetBytesCache(keys []string, values [][]byte) error

MSet the cache bytes values for the keys. Items for values can't be nil.

Return: error

func MSetStringCache

func MSetStringCache(keys, values []string) error

MSet the cache string values for the keys.

Return: error

func Open

func Open(addr string, max int, idle time.Duration)

Open the redis pool. If already open, which means "pool" is not nil, do nothing.

func SetBytesCache

func SetBytesCache(key *string, value []byte) error

Set a bytes cache.

Return: error

func SetBytesCacheEX

func SetBytesCacheEX(key *string, value []byte, ex uint64) error

Set a bytes cache with expiration in seconds.

Return: error

func SetStringCache

func SetStringCache(key, value *string) error

Set a string cache.

Return: error

func SetStringCacheEX

func SetStringCacheEX(key, value *string, ex uint64) error

Set a string cache with expiration in seconds.

Return: error

func UpdateExpiration

func UpdateExpiration(k []string, ex []uint64) error

Update a key's expiration.

Return: error

Types

This section is empty.

Jump to

Keyboard shortcuts

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