Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Equivalent of pipeline feature in 0.5.x #173

Closed
hasit opened this issue Jul 13, 2022 · 3 comments
Closed

Equivalent of pipeline feature in 0.5.x #173

hasit opened this issue Jul 13, 2022 · 3 comments
Assignees
Labels
dmap enhancement New feature or request

Comments

@hasit
Copy link
Contributor

hasit commented Jul 13, 2022

Hello,

I notice that the pipeline feature was removed in latest version of olric (#8 (comment)). Is there an equivalent of this in 0.5.x?

@buraksezer
Copy link
Owner

Hey,

Olric still supports pipelining at the protocol level. I'm going to bring back that feature soon, but I'm not sure how it should be implemented in the API.

  1. We have to calculate partition owners for the given keys.
  2. Group the keys by the partition owner.
  3. Send commands to the partition owner in one batch.
  4. Receive the result of execution and prepare a response.

BTW, only a subset of the API can support pipelining. For example, the Lock commands should not be supported.

It may look like this:

cmds, err := rdb.Pipelined(ctx, func(pipe redis.Pipeliner) error {
	for i := 0; i < 100; i++ {
		pipe.Get(ctx, fmt.Sprintf("key%d", i))
	}
	return nil
})
if err != nil {
	panic(err)
}

for _, cmd := range cmds {
    fmt.Println(cmd.(*redis.StringCmd).Val())
}

@buraksezer buraksezer self-assigned this Jul 13, 2022
@buraksezer buraksezer added enhancement New feature or request dmap labels Jul 13, 2022
@buraksezer
Copy link
Owner

Hey @hasit

I prepared the new version of pipelining. It only supports a subset of the DMap methods:

  • Put
  • Get
  • Delete
  • Expire
  • Incr
  • Decr
  • GetPut
  • IncrByFloat

You can find the initial implementation here: https://github.com/buraksezer/olric/blob/feature/resp-pipelining/pipeline.go

Here is an example:

func ExamplePipeline() {
	c, err := NewClusterClient([]string{"127.0.0.1:3320"})
	if err != nil {
		// Handle this error
	}
	dm, err := c.NewDMap("mydmap")
	if err != nil {
		// Handle this error
	}

	ctx := context.Background()

	pipe, err := dm.Pipeline()
	if err != nil {
		// Handle this error
	}

	futurePut, err := pipe.Put(ctx, "key-1", "value-1")
	if err != nil {
		// Handle this error
	}

	futureGet := pipe.Get(ctx, "key-1")

	err = pipe.Flush(context.Background())
	if err != nil {
		// Handle this error
	}

	err = futurePut.Result()
	if err != nil {
		// Handle this error
	}

	gr, err := futureGet.Result()
	if err != nil {
		// Handle this error
	}
	value, err := gr.String()
	if err != nil {
		// Handle this error
	}
	fmt.Println(value)
}

@buraksezer
Copy link
Owner

It's merged into master. I released v0.5.0-beta.7. See the documentation on pkg.go.dev.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dmap enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants