コード例 #1
0
ファイル: redis.go プロジェクト: ishan-anand/norse
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")
	}
}
コード例 #2
0
ファイル: memcache.go プロジェクト: harshadptl/norse
// 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")
	}
}
コード例 #3
0
ファイル: redis.go プロジェクト: ishan-anand/norse
// 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)
		defer pool.Put(conn)
		return conn.(*RedisConn).Do(cmd, args...)
	} else {
		return nil, errors.New("Redis: instance Not found")
	}
}
コード例 #4
0
ファイル: memcache.go プロジェクト: harshadptl/norse
// 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")
	}
}
コード例 #5
0
ファイル: memcache.go プロジェクト: harshadptl/norse
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")
	}
}
コード例 #6
0
ファイル: memcache.go プロジェクト: harshadptl/norse
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")
	}
}