Skip to content

add ReadOnlyMemory<RedisKeyOrValue> and Lease<byte> for Lua and Execute - #3201

Open
pairbit wants to merge 11 commits into
StackExchange:mainfrom
pairbit:lua-memory-pr
Open

add ReadOnlyMemory<RedisKeyOrValue> and Lease<byte> for Lua and Execute#3201
pairbit wants to merge 11 commits into
StackExchange:mainfrom
pairbit:lua-memory-pr

Conversation

@pairbit

@pairbit pairbit commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Tasks:

  • add ReadOnlyMemory<RedisKeyOrValue> API for Lua
  • add Lease<byte>? API for Lua
  • add ScriptEvaluateReadOnlyAsync again if the script does not exist.
  • add rent args for key-prefix path
  • add ReadOnlyMemory<RedisKeyOrValue> API for Execute
  • add Lease<byte>? API for Execute
  • add IScriptRequestDisposer to Execute (to return memory to pools, including for fire-and-forget mode)

Links
#2346
#2843
#2844

Please consider this PR, this issue has been raised for a long time

* add RedisKeyOrValue

* add operators and override to RedisKeyOrValue

* add ThrowInvalidCast

* add IScriptRequestDisposer

* ScriptEvaluateMemory

* ScriptEvaluateMemoryReadOnlyAsync

* ScriptEvalMemoryMessage

* fix bug ScriptUnavailable ScriptEvaluateReadOnlyAsync

* add Lease ScriptEvaluateMemory

* add Prefixed

* FromKey FromValue

* undo Disposer
@pairbit pairbit changed the title add ReadOnlyMemory<RedisKeyOrValue> and Lease<byte> for Lua add ReadOnlyMemory<RedisKeyOrValue> and Lease<byte> for Lua and Execute Aug 31, 2026
@mgravell

Copy link
Copy Markdown
Collaborator

There's a couple of reasons I've been deferring on this for a little bit...

If we're thinking "efficiency", there's the problem of the return value, and managing it in a way that is flexible and efficient.

I'm not quite ready to release it on the world yet, but a large part of the IO rewrite is "yet to come", and explicitly targets flexible read / write custom command scenarios, including Lua (but also any ad-hoc commands). I'm torn between compromising on an eval[sha] now, bs giving you the real thing "soon" - trust me, it'll be much easier than this.

Thoughts?

@pairbit

pairbit commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

I understand that you want to give the maximum. But the perfect is the enemy of the good. The solution I propose will completely satisfy many and will be a compromise. For most tasks, the current solution will be sufficient. But I understand it's not perfect.

I'd really appreciate your consideration of my merge request. It's a good temporary compromise.

@pairbit

pairbit commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

I'm currently in dire need of the ScriptEvaluateLease and ExecuteLease methods.
In my projects I use only lua scripts and direct call commands, and I really miss the rent on return.

If you don't like the idea of ​​introducing a new RedisKeyOrValue or ScriptRequestDisposer type, I'm willing to live with their absence.

I am willing to listen to your terms on which you would agree to add methods with a Lease return.

I apologize for being stubborn, I have been waiting for these changes for a very long time.

@mgravell

mgravell commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

I'll try to look today. Balancing competing needs is always tricky. I'm not against reasonable APIs. The return value is the trickiest bit, since this can technically be an arbitrary tree of different data types.

Thinking outside of the box: how might a lease + RespReader work for you? I.e. the lease isn't a value, but an API over the tree? If you're accessing a scalar or BLOB: this is then one line to get the blob, and I could provide helper APIs for those.

@pairbit

pairbit commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

I understand that the Lease<byte> object only works with a scalar result, which is fine for me since I'm working with blob. I try to avoid trees and arrays as a result.

Thinking outside of the box: how might a lease + RespReader work for you?

Returning lease + RespReader would be a great solution!

After the review, please give me your opinion on my idea with IScriptRequestDisposer, which returns all data associated with a request to pools after writing. IScriptRequestDisposer could not be used for ScriptEvaluate because the message can be used twice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants