示例#1
0
文件: reply_test.go 项目: cyx/busl
func ExampleBool() {
	c, err := dial()
	if err != nil {
		panic(err)
	}
	defer c.Close()

	c.Do("SET", "foo", 1)
	exists, _ := redis.Bool(c.Do("EXISTS", "foo"))
	fmt.Printf("%#v\n", exists)
	// Output:
	// true
}
示例#2
0
文件: io.go 项目: cyx/busl
func ReaderDone(rd io.Reader) bool {
	r, ok := rd.(*reader)
	if !ok {
		return false
	}

	if r.closed {
		return true
	}

	conn := redisPool.Get()
	defer conn.Close()

	done, _ := redis.Bool(conn.Do("EXISTS", r.channel.doneId()))
	return done
}
示例#3
0
文件: io.go 项目: cyx/busl
func (r *reader) fetch(length int) ([]byte, error) {
	conn := redisPool.Get()
	defer conn.Close()

	start, end := r.offset, r.offset+int64(length)

	conn.Send("MULTI")
	conn.Send("GETRANGE", r.channel.id(), start, end-1)
	conn.Send("STRLEN", r.channel.id())
	conn.Send("EXISTS", r.channel.doneId())
	conn.Send("EXPIRE", r.channel.id(), redisChannelExpire)

	list, err := redis.Values(conn.Do("EXEC"))
	data, err := redis.Bytes(list[0], err)
	size, err := redis.Int64(list[1], err)
	done, err := redis.Bool(list[2], err)

	if r.buffered = end < size; !r.buffered && done {
		err = io.EOF
	}

	return data, err
}