Skip to content

Make optimistic version locking optional#856

Closed
sgtsquiggs wants to merge 2 commits intoredis:mainfrom
sgtsquiggs:verless-om
Closed

Make optimistic version locking optional#856
sgtsquiggs wants to merge 2 commits intoredis:mainfrom
sgtsquiggs:verless-om

Conversation

@sgtsquiggs
Copy link
Copy Markdown
Contributor

@sgtsquiggs sgtsquiggs commented Jun 11, 2025

This PR will make the reids:",ver" tag optional. This PR will resolve #854.

Usecase:

You are using rueidis/om to keep a cache up-to-date, reading directly off a kafka queue. You do not want to deal with versioning your data in redis. You are always upserting.

TODO:

  • Update README and documentation

Comment on lines +74 to +75
s.ver = &field{reflect.TypeOf(int64(0)), "", -1, false, true, false}
s.verless = true
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I wonder if it is possible to just keep s.ver == nil?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Definitely can do that, just would result in more LOC changed.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@sgtsquiggs, maybe we should keep the current approach. Is this PR ready for merge?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hi @sgtsquiggs, could you help resolve the conflicts?

@SoulPancake
Copy link
Copy Markdown
Contributor

@sgtsquiggs Are you continuing on this?

@sgtsquiggs sgtsquiggs marked this pull request as ready for review October 19, 2025 22:47
Comment on lines +112 to +114
if r.schema.verless {
return nil
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

When will this happen? If it never happens, can we just delete it?

Suggested change
if r.schema.verless {
return nil
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

On the other hand, if the case does happen, we should not return nil either.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I modified the script (here) to return nil if the ver arg is not present. Alternatively I could have used another script that does not perform optimistic locking, and forked based on r.schema.verless.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Oh, can we align with the original behavior to return ARGV[2] as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Absolutely. Wrote this PR quickly so I could fork and use om - looking at this code today I don't remember a lot of it and it looks a little dodgy to me. I'll try to reimplement a bit cleaner this week.

Comment on lines +134 to +135
if r.schema.verless {
continue
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same here. Can we delete this?

// ver is no longer required
if s.ver == nil {
panic(fmt.Sprintf("schema %q should have one field with `redis:\",ver\"` tag", t))
s.ver = &field{reflect.TypeOf(int64(0)), "", -1, false, true, false}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Field names should be explicitly specified.

@sgtsquiggs
Copy link
Copy Markdown
Contributor Author

Withdrawing this PR to rework it 👍

@sgtsquiggs sgtsquiggs marked this pull request as draft October 20, 2025 13:33
@SoulPancake
Copy link
Copy Markdown
Contributor

Hi @sgtsquiggs Are you still working on this?

@rueian
Copy link
Copy Markdown
Collaborator

rueian commented Feb 16, 2026

Hi @SoulPancake, I think it is fine if you can take it over.

rueian pushed a commit that referenced this pull request Feb 21, 2026
Continuation from #856

solves #854

---------

Co-authored-by: Matthew Crenshaw <mcrenshaw@clearstreet.io>
@rueian rueian closed this Feb 21, 2026
rueian pushed a commit to valkey-io/valkey-go that referenced this pull request Feb 21, 2026
Continuation from redis/rueidis#856

solves #854

---------

Co-authored-by: Matthew Crenshaw <mcrenshaw@clearstreet.io>
Signed-off-by: Rueian <rueiancsie@gmail.com>
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.

Let us disable optimistic locking in github.com/redis/rueidis/om

3 participants