Skip to content

Commit

Permalink
Dev backup.
Browse files Browse the repository at this point in the history
  • Loading branch information
duoduo committed Mar 8, 2012
1 parent e97dddb commit 3b837dc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
13 changes: 8 additions & 5 deletions client.go
Expand Up @@ -13,6 +13,7 @@ const (
CR_BYTE byte = byte('\r')
LF_BYTE byte = byte('\n')
COUNT_BYTE byte = byte('*')
ARG_BYTE byte = byte('$')
READ_BUF = (1024 * 16)
MAX_ARGC = (1024 * 1024)
)
Expand Down Expand Up @@ -166,11 +167,13 @@ func (c *Client) ReadRequest() {
lineBuf, isPrefix, err = reader.ReadLine()
fmt.Printf("ERROR: ", err)
fmt.Printf("\n\nBufLength: %d Line %d: %s", len(lineBuf), line, lineBuf)

request.Argv[line] = lineBuf
// New line if isPrefix == false
if !isPrefix {
line++
if lineBuf[0] != ARG_BYTE {
fmt.Printf("Setting ARGV%s", line)
request.Argv[line] = lineBuf
// New line if isPrefix == false
if !isPrefix {
line++
}
}
}

Expand Down
9 changes: 5 additions & 4 deletions command.go
Expand Up @@ -20,9 +20,9 @@ type StringCommand struct {
}

func (comm *StringCommand) Process(client *Client) {
fmt.Printf("\n\nSTRINGTYPE: %s", strings.ToLower(string(client.Request.Argv[1])))
fmt.Printf("\n\nSTRINGTYPE: %s", strings.ToLower(string(client.Request.Argv[0])))
// Determine string command type.
switch strings.ToLower(string(client.Request.Argv[1])) {
switch strings.ToLower(string(client.Request.Argv[0])) {
case "set":
comm.Set(client)
case "get":
Expand All @@ -37,13 +37,14 @@ func (comm *StringCommand) Process(client *Client) {
}

func (comm *StringCommand) Set(client *Client) {
client.Db.Set(client.Request.Argv[2], client.Request.Argv[3])
fmt.Printf("\n\nSettings: %s %s", client.Request.Argv[1], client.Request.Argv[2])
client.Db.Set(client.Request.Argv[1], client.Request.Argv[2])
// Reply
client.Response.Ok()
}

func (comm *StringCommand) Get(client *Client) {
buf := client.Db.Get(client.Request.Argv[2])
buf := client.Db.Get(client.Request.Argv[1])
fmt.Printf("\n\nGET RESPONSE: %s", string(buf))
client.Response.SendBulk(buf)
//_, _ = client.Conn.Write([]byte("+OK\r\n"))
Expand Down

0 comments on commit 3b837dc

Please sign in to comment.