Exemplo n.º 1
0
// Memcache Set,
func (m *MemcacheStruct) Set(memcacheInstance string, key string, value string) (string, error) {
	// Get and set in our pool; for memcache we use our own pool
	pool, ok := memPoolMap[memcacheInstance]
	// Increment and decrement counters using user specified functions.
	m.fIncr(memcacheInstance)
	defer m.fDecr(memcacheInstance)
	if ok {
		conn, _ := pool.Get(time.Second)
		defer pool.Put(conn)
		byteArr := []byte(value)
		conn.(*MemcacheConn).Set(&memcache.Item{Key: key, Value: byteArr})
		return "", nil
	} else {
		return "", errors.New("Memcache: instance Not found")
	}
}
Exemplo n.º 2
0
// Memcache Get,
func (m *MemcacheStruct) Get(memcacheInstance string, key string) (string, error) {
	// Get and set in our pool; for memcache we use our own pool
	pool, ok := memPoolMap[memcacheInstance]
	// Increment and decrement counters using user specified functions.
	m.fIncr(memcacheInstance)
	defer m.fDecr(memcacheInstance)
	if ok {
		conn, _ := pool.Get(time.Second)
		defer pool.Put(conn)
		value, err := conn.(*MemcacheConn).Get(key)
		if err != nil {
			return "", err
		}
		return string(value.Value), err
	} else {
		return "", errors.New("Memcache: instance Not found")
	}
}
Exemplo n.º 3
0
func (m *MemcacheStruct) Expire(memcacheInstance string, key string, duration int) (bool, error) {
	// Get and set in our pool; for memcache we use our own pool
	pool, ok := memPoolMap[memcacheInstance]
	// Increment and decrement counters using user specified functions.
	m.fIncr(memcacheInstance)
	defer m.fDecr(memcacheInstance)
	if ok {
		conn, _ := pool.Get(time.Second)
		defer pool.Put(conn)
		err := conn.(*MemcacheConn).Touch(key, int32(duration))
		if err != nil {
			return false, err
		}
		return true, nil
	} else {
		return true, errors.New("Memcache: instance Not found")
	}
}
Exemplo n.º 4
0
func (m *MemcacheStruct) Setex(memcacheInstance string, key string, duration int, val string) (bool, error) {
	// Get and set in our pool; for memcache we use our own pool
	pool, ok := memPoolMap[memcacheInstance]
	// Increment and decrement counters using user specified functions.
	m.fIncr(memcacheInstance)
	defer m.fDecr(memcacheInstance)
	if ok {
		conn, _ := pool.Get(time.Second)
		defer pool.Put(conn)
		resp := conn.(*MemcacheConn).Set(&memcache.Item{Key: key, Value: []byte(val)})
		if resp != nil {
			return false, resp
		} else {
			err := conn.(*MemcacheConn).Touch(key, int32(duration))
			if err != nil {
				return false, err
			}
			return true, nil
		}
	} else {
		return false, errors.New("Memcache: instance Not found")
	}
}