forked from mirror/ledisdb
list block pop support milliseconds timeout
This commit is contained in:
parent
c30979e5b5
commit
f715de3561
|
@ -494,15 +494,15 @@ func (db *DB) lEncodeMaxKey() []byte {
|
|||
return ek
|
||||
}
|
||||
|
||||
func (db *DB) BLPop(keys [][]byte, timeout int) ([]interface{}, error) {
|
||||
func (db *DB) BLPop(keys [][]byte, timeout time.Duration) ([]interface{}, error) {
|
||||
return db.lblockPop(keys, listHeadSeq, timeout)
|
||||
}
|
||||
|
||||
func (db *DB) BRPop(keys [][]byte, timeout int) ([]interface{}, error) {
|
||||
func (db *DB) BRPop(keys [][]byte, timeout time.Duration) ([]interface{}, error) {
|
||||
return db.lblockPop(keys, listTailSeq, timeout)
|
||||
}
|
||||
|
||||
func (db *DB) lblockPop(keys [][]byte, whereSeq int32, timeout int) ([]interface{}, error) {
|
||||
func (db *DB) lblockPop(keys [][]byte, whereSeq int32, timeout time.Duration) ([]interface{}, error) {
|
||||
ch := make(chan []byte)
|
||||
|
||||
bkeys := [][]byte{}
|
||||
|
@ -530,7 +530,7 @@ func (db *DB) lblockPop(keys [][]byte, whereSeq int32, timeout int) ([]interface
|
|||
}
|
||||
}()
|
||||
|
||||
deadT := time.Now().Add(time.Duration(timeout) * time.Second)
|
||||
deadT := time.Now().Add(timeout)
|
||||
|
||||
for {
|
||||
if timeout == 0 {
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"github.com/siddontang/go/hack"
|
||||
"github.com/siddontang/ledisdb/ledis"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
func lpushCommand(c *client) error {
|
||||
|
@ -280,17 +281,20 @@ func brpopCommand(c *client) error {
|
|||
|
||||
}
|
||||
|
||||
func lParseBPopArgs(c *client) (keys [][]byte, timeout int, err error) {
|
||||
func lParseBPopArgs(c *client) (keys [][]byte, timeout time.Duration, err error) {
|
||||
args := c.args
|
||||
if len(args) < 2 {
|
||||
err = ErrCmdParams
|
||||
return
|
||||
}
|
||||
|
||||
if timeout, err = strconv.Atoi(hack.String(args[len(args)-1])); err != nil {
|
||||
var t float64
|
||||
if t, err = strconv.ParseFloat(hack.String(args[len(args)-1]), 64); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
timeout = time.Duration(t * float64(time.Second))
|
||||
|
||||
keys = args[0 : len(args)-1]
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue