2014-05-09 10:49:22 +04:00
|
|
|
package ledis
|
2014-05-03 10:55:12 +04:00
|
|
|
|
2014-05-14 12:35:49 +04:00
|
|
|
import ()
|
2014-05-06 09:32:38 +04:00
|
|
|
|
2014-05-03 10:55:12 +04:00
|
|
|
func lpushCommand(c *client) error {
|
2014-05-06 09:32:38 +04:00
|
|
|
args := c.args
|
|
|
|
if len(args) < 2 {
|
|
|
|
return ErrCmdParams
|
|
|
|
}
|
|
|
|
|
|
|
|
if n, err := c.app.list_lpush(args[0], args[1:]); err != nil {
|
|
|
|
return err
|
|
|
|
} else {
|
|
|
|
c.writeInteger(n)
|
|
|
|
}
|
|
|
|
|
2014-05-03 10:55:12 +04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func rpushCommand(c *client) error {
|
2014-05-06 09:32:38 +04:00
|
|
|
args := c.args
|
|
|
|
if len(args) < 2 {
|
|
|
|
return ErrCmdParams
|
|
|
|
}
|
|
|
|
|
|
|
|
if n, err := c.app.list_rpush(args[0], args[1:]); err != nil {
|
|
|
|
return err
|
|
|
|
} else {
|
|
|
|
c.writeInteger(n)
|
|
|
|
}
|
|
|
|
|
2014-05-03 10:55:12 +04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func lpopCommand(c *client) error {
|
2014-05-06 09:32:38 +04:00
|
|
|
args := c.args
|
|
|
|
if len(args) != 1 {
|
|
|
|
return ErrCmdParams
|
|
|
|
}
|
|
|
|
|
|
|
|
if v, err := c.app.list_lpop(args[0]); err != nil {
|
|
|
|
return err
|
|
|
|
} else {
|
|
|
|
c.writeBulk(v)
|
|
|
|
}
|
|
|
|
|
2014-05-03 10:55:12 +04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func rpopCommand(c *client) error {
|
2014-05-06 09:32:38 +04:00
|
|
|
args := c.args
|
|
|
|
if len(args) != 1 {
|
|
|
|
return ErrCmdParams
|
|
|
|
}
|
|
|
|
|
|
|
|
if v, err := c.app.list_rpop(args[0]); err != nil {
|
|
|
|
return err
|
|
|
|
} else {
|
|
|
|
c.writeBulk(v)
|
|
|
|
}
|
|
|
|
|
2014-05-03 10:55:12 +04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func llenCommand(c *client) error {
|
2014-05-06 09:32:38 +04:00
|
|
|
args := c.args
|
|
|
|
if len(args) != 1 {
|
|
|
|
return ErrCmdParams
|
|
|
|
}
|
|
|
|
|
|
|
|
if n, err := c.app.list_len(args[0]); err != nil {
|
|
|
|
return err
|
|
|
|
} else {
|
|
|
|
c.writeInteger(n)
|
|
|
|
}
|
|
|
|
|
2014-05-03 10:55:12 +04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func lindexCommand(c *client) error {
|
2014-05-06 09:32:38 +04:00
|
|
|
args := c.args
|
|
|
|
if len(args) != 2 {
|
|
|
|
return ErrCmdParams
|
|
|
|
}
|
|
|
|
|
2014-05-14 12:35:49 +04:00
|
|
|
index, err := StrInt64(args[1], nil)
|
2014-05-06 09:32:38 +04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2014-05-09 05:17:28 +04:00
|
|
|
if v, err := c.app.list_index(args[0], int32(index)); err != nil {
|
2014-05-06 09:32:38 +04:00
|
|
|
return err
|
|
|
|
} else {
|
|
|
|
c.writeBulk(v)
|
|
|
|
}
|
|
|
|
|
2014-05-03 10:55:12 +04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func lrangeCommand(c *client) error {
|
2014-05-06 09:32:38 +04:00
|
|
|
args := c.args
|
|
|
|
if len(args) != 3 {
|
|
|
|
return ErrCmdParams
|
|
|
|
}
|
|
|
|
|
|
|
|
var start int64
|
|
|
|
var stop int64
|
|
|
|
var err error
|
|
|
|
|
2014-05-14 12:35:49 +04:00
|
|
|
start, err = StrInt64(args[1], nil)
|
2014-05-06 09:32:38 +04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2014-05-14 12:35:49 +04:00
|
|
|
stop, err = StrInt64(args[2], nil)
|
2014-05-06 09:32:38 +04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2014-05-09 05:17:28 +04:00
|
|
|
if v, err := c.app.list_range(args[0], int32(start), int32(stop)); err != nil {
|
2014-05-06 09:32:38 +04:00
|
|
|
return err
|
|
|
|
} else {
|
|
|
|
c.writeArray(v)
|
|
|
|
}
|
|
|
|
|
2014-05-03 10:55:12 +04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2014-05-12 11:08:59 +04:00
|
|
|
func lclearCommand(c *client) error {
|
|
|
|
args := c.args
|
|
|
|
if len(args) != 1 {
|
|
|
|
return ErrCmdParams
|
|
|
|
}
|
|
|
|
|
|
|
|
if n, err := c.app.list_clear(args[0]); err != nil {
|
|
|
|
return err
|
|
|
|
} else {
|
|
|
|
c.writeInteger(n)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2014-05-03 10:55:12 +04:00
|
|
|
func init() {
|
|
|
|
register("lindex", lindexCommand)
|
|
|
|
register("llen", llenCommand)
|
|
|
|
register("lpop", lpopCommand)
|
|
|
|
register("lrange", lrangeCommand)
|
|
|
|
register("lpush", lpushCommand)
|
|
|
|
register("rpop", rpopCommand)
|
|
|
|
register("rpush", rpushCommand)
|
2014-05-12 11:08:59 +04:00
|
|
|
|
|
|
|
//ledisdb special command
|
|
|
|
|
|
|
|
register("lclear", lclearCommand)
|
|
|
|
|
2014-05-03 10:55:12 +04:00
|
|
|
}
|