Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Conversation

@Pryz
Copy link
Contributor

@Pryz Pryz commented May 22, 2017

No description provided.

@Pryz Pryz requested a review from achille-roussel May 22, 2017 02:00
return ParseArgs(c.Query(ctx, cmd, args...), nil)
}

func (c *Client) MultiExec(ctx context.Context, cmds ...Command) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need documentation for this method.

}

r, err := c.Do(&Request{
Addr: addr,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be rewritten

Cms: []Command{{ ... }}

(no need to repeat Command{)


return r.Args
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, we need documentation for this method.

conn_test.go Outdated
tx1 := makeConnTx(ctx, &Request{Cmd: "SET", Args: List("redis-go.test.conn", "0123456789")})
tx2 := makeConnTx(ctx, &Request{Cmd: "GET", Args: List("redis-go.test.conn")})
req1 := &Request{
Cmds: []Command{Command{Cmd: "SET", Args: List("redis-go.test.conn", "0123456789")}},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we can get rid of the Command as well.

conn_test.go Outdated
tx1 := makeConnTx(ctx, req1)

req2 := &Request{
Cmds: []Command{Command{Cmd: "GET", Args: List("redis-go.test.conn")}},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we can get rid of the Command as well.

request.go Outdated
// For server request, Args is never nil, even if there are no values in
// the argument list.
Args Args
// Cmds is the list of transaction's commands.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cmds is the list of transaction's commands. => Cmds is the list of commands that are part of the transaction.

request.go Outdated
return ParseArgs(req.Args, dsts...)
for _, cmd := range req.Cmds {
err := ParseArgs(cmd.Args, dsts...)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's inline the error check here if err := ParseArgs(cmd.Args, dsts...); err != nil {

server.go Outdated
Addr: conn.RemoteAddr().String(),
Args: args,
Context: ctx,
cmd = Command{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about doing cmd := Command{ here and get rid of the variable declaration above?

server.go Outdated
}

cmds := []Command{}
cmds = append(cmds, cmd)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we could shorten the code by rewriting it as cmds := []Command{cmd}.

server_test.go Outdated
defer cancel()

err := cli.MultiExec(ctx,
Command{Cmd: "MULTI"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So how about making MULTI and EXEC automatic?

@Pryz Pryz force-pushed the support-transactions branch 3 times, most recently from c644eb2 to 336e701 Compare May 24, 2017 21:38
if len(addr) == 0 {
addr = "localhost:6379"
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can optimize the memory allocations here by rewriting the code as

multi := make([]Command, 0, len(cmds)+2) multi = append(multi, Command{Cmd: "MULTI"}) multi = append(multi, cmds...) multi = append(multi, Command{Cmd: "EXEC"})
addr := c.Addr
if len(addr) == 0 {
addr = "localhost:6379"
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's check that the list of command doesn't contain any MULTI, EXEC or DISCARD.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should we do in that case ? drop the query or remove duplicate keys ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to drop the query and return an error, it's a misuse of the package.

request.go Outdated
// For server request, Args is never nil, even if there are no values in
// the argument list.
Args Args
// Cmds is a lir of commands that are part of the transaction.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a lir ?

server.go Outdated

func (s *Server) serveRequest(res *responseWriter, req *Request) (err error) {
args := req.Args
cmds := req.Cmds
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this intermediary variable isn't useful, we could just write for _, cmd := range req.Cmds {

server.go Outdated
args.Close()
}
default:
err = s.serveRedis(res, req)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is weird isn't it? It's gonna call serveRedis multiple times for the same request if there are many arguments.

@Pryz Pryz force-pushed the support-transactions branch 2 times, most recently from 31e503a to 1eb106a Compare July 10, 2017 02:34
@Pryz
Copy link
Contributor Author

Pryz commented Jul 10, 2017

So this is mostly working except when we parse the response.

Sending :

MULTI GET foo GET bob EXEC 

Will return

+OK +QUEUED +QUEUED *2 $3 bar $5 alice 

But we only have +OK in the Args. I'll check how we are dealing with that in the resp parser I guess.

conn_test.go Outdated
}
}

func isInArray(list []string, val string) bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function doesn't seem used.

response.go Outdated
if err := enc.Encode(val); err != nil {
return err
for _, arg := range res.Args {
if arg != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this ever happen? It seems like it's a bad idea to allow nil arguments.

response.go Outdated
return enc.Close()
}

func (res *Response) CloseAllArgs() error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we just call this Close?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I was just lazy of writing a for loop multiple times :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the method is fine, I was just arguing on the method name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad :) Can changed that for sure !

@Pryz Pryz force-pushed the support-transactions branch 2 times, most recently from dce0e01 to 0915048 Compare July 10, 2017 22:04
args.go Outdated
err := args.dec.Err()

if args.done != nil {
if args.done != nil && err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@achille-roussel not sure this one is correct

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, we have to notify the done channel even if there were no errors, otherwise each connection will only be able to handle one request, then will timeout.

@Pryz Pryz force-pushed the support-transactions branch 5 times, most recently from 4264009 to 47bff1f Compare July 10, 2017 23:31
@Pryz Pryz force-pushed the support-transactions branch from 47bff1f to b7df68a Compare July 11, 2017 01:38
@Pryz Pryz force-pushed the support-transactions branch from 073d590 to d3248b5 Compare July 11, 2017 03:05
@Pryz Pryz force-pushed the support-transactions branch from d3248b5 to 9afcdf4 Compare July 11, 2017 07:24
@achille-roussel
Copy link
Contributor

Closing in favor of #26 Thanks for your hard work on that one man!

@achille-roussel achille-roussel deleted the support-transactions branch July 14, 2017 06:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

3 participants