rediscache

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: May 13, 2016 License: MIT Imports: 6 Imported by: 0

README

eurekache redis

Requirements

Depends on the garyburd/redigo library for Redis client.

Installation

Install eurekache and required packages using go get command:

$ go get github.com/garyburd/redigo

Usage

// create redis cache
redisHost := "127.0.0.1:6379"
expiredTTL := 5 * 60 * 1000 // 5 minutes (millisecond)
keyPrefix := "myapp:" // added key prefix before set on redis
dbNumber := 1 // redis db number

pool := &redis.Pool{
    Dial: func() (redis.Conn, error) {
        return redis.Dial("tcp", redisHost)
    },
}

rc := NewRedisCache(pool)
rc.SetTTL(expiredTTL)
rc.SetPrefix(keyPrefix)
rc.Select(dbNumber)

cache := eurekache.New()
cache.SetCacheSources([]cache{rc})

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RedisCache

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

RedisCache is a cache source for Redis and contains redis.Pool

func NewRedisCache

func NewRedisCache(pool *redis.Pool) *RedisCache

NewRedisCache returns initialized RedisCache with given redis.Pool

func (*RedisCache) Get

func (c *RedisCache) Get(key string, data interface{}) bool

Get searches cache by given key from redis and returns flag of cache is existed or not. when cache hit, data is assigned.

func (*RedisCache) GetGobBytes

func (c *RedisCache) GetGobBytes(key string) ([]byte, bool)

GetGobBytes searches cache by given key from redis and returns gob-encoded value.

func (*RedisCache) GetInterface

func (c *RedisCache) GetInterface(key string) (interface{}, bool)

GetInterface searches cache by given key from redis and returns interface value.

func (*RedisCache) Select

func (c *RedisCache) Select(num int)

Select sets db number for redis-server

func (*RedisCache) Set

func (c *RedisCache) Set(key string, data interface{}) error

Set sets data into redis. data is wrapped by gob-encoded Item

func (*RedisCache) SetExpire

func (c *RedisCache) SetExpire(key string, data interface{}, ttl int64) error

SetExpire sets data into redis with TTL. data is wrapped by gob-encoded Item

func (*RedisCache) SetPrefix

func (c *RedisCache) SetPrefix(prefix string)

SetPrefix sets the prefix used for adding prefix into key name

func (*RedisCache) SetTTL

func (c *RedisCache) SetTTL(ttl int64)

SetTTL sets default TTL (milliseconds)

Jump to

Keyboard shortcuts

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