Esempio n. 1
0
func (r *RedisStruct) Sismembers(redisInstance string, key string, members []string) ([]bool, error) {

	// Get and set in our pool; for redis we use our own pool
	pool, ok := redisPoolMap[redisInstance]
	// Increment and decrement counters using user specified functions.
	if ok {
		conn, err := pool.Get(redisCtx)
		if err != nil {
			return nil, err
		}
		r.fIncr(redisInstance)
		defer r.fDecr(redisInstance)
		defer pool.Put(conn)

		for _, member := range members {
			conn.(*RedisConn).Send("SISMEMBER", key, member)
		}
		conn.(*RedisConn).Flush()

		results := make([]bool, 0, len(members))
		for _, _ = range members {
			res, err := conn.(*RedisConn).Receive()
			if err != nil {
				return nil, err
			}
			val := res.(int64) != 0
			results = append(results, val)
		}
		return results, nil

	} else {
		return nil, errors.New("Redis: instance Not found")
	}
}
Esempio n. 2
0
// Execute, get connection from a pool
// fetch and return connection to a pool.
func (r *RedisStruct) Execute(redisInstance string, cmd string, args ...interface{}) (interface{}, error) {
	// Get and set in our pool; for redis we use our own pool
	pool, ok := redisPoolMap[redisInstance]
	// Increment and decrement counters using user specified functions.
	if ok {
		conn, err := pool.Get(redisCtx)
		if err != nil {
			return nil, err
		}
		r.fIncr(redisInstance)
		defer r.fDecr(redisInstance)
		ret, ferr := conn.(*RedisConn).Do(cmd, args...)
		if isNetworkError(ferr) {
			pool.Put(nil)
		} else {
			pool.Put(conn)
		}
		return ret, ferr
	} else {
		return nil, errors.New("Redis: instance Not found")
	}
}
Esempio n. 3
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(memCtx)
		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")
	}
}
Esempio n. 4
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(memCtx)
		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")
	}
}
Esempio n. 5
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(memCtx)
		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")
	}
}
Esempio n. 6
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(memCtx)
		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")
	}
}