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

RedisValue: type mismatch #2418

Closed
naighes opened this issue Mar 29, 2023 · 8 comments
Closed

RedisValue: type mismatch #2418

naighes opened this issue Mar 29, 2023 · 8 comments

Comments

@naighes
Copy link

naighes commented Mar 29, 2023

Hello!
I'm experiencing an issue with RedisValue underlying type.
So, I'm flushing some data like the following:

RedisValue someInt = 12;
db.HashSetAsync(key, new[] {
    new HashEntry("some_int", someInt)
    // ...
});

The property IsInteger() prints true for someInt.
The problem occurs when attempting to read back the set:

var entry = await db.HashGetAllAsync(key);
var someInt = entry.FirstOrDefault(x => x.Name == "some_int").Value;

Here IsInteger() returns false, and I cannot sort out why.
Furthermore any cast to Int32 just fails (e.g. var x = (Int32)someInt;).
Any hint?

@mgravell
Copy link
Collaborator

What does someInt.ToString() show? I'm interested in whether the value is simply now what we expect

@naighes
Copy link
Author

naighes commented Mar 29, 2023

What does someInt.ToString() show? I'm interested in whether the value is simply now what we expect

It prints "12", which is correct.
But look at this:

foreach (var e in entry) {
    System.Diagnostics.Debug.WriteLine($"{e.Name} : {e.Value.ToString()}");
}

It prints:

some_int : 12
...

Instead, this:

var entry = await db.HashGetAllAsync(key);
var v = entry.FirstOrDefault(x => x.Name == "some_int").Value.ToString();

...well, it prints an empty string for v.

@mgravell
Copy link
Collaborator

That suggests the match wasn't found by name. I'll see what I can find.

@mgravell
Copy link
Collaborator

I have a repro, but I don't get the empty value - I get a 12, but where IsInteger reports false; I think this is a documentation error, as this isn't intended to mean "can be interpreted as", but instead means "the underlying value being used here is..."

It should work correctly via someInt.TryParse(out int), remembering to check the bool return value.

mgravell added a commit that referenced this issue Mar 29, 2023
@mgravell
Copy link
Collaborator

See also: ^^^

@mgravell
Copy link
Collaborator

(note: if this fixes things, please don't close this - I will add a documentation fix in that branch and add a PR)

@mgravell
Copy link
Collaborator

Also note for me: check that we have == operators (left and right) for: string and int - we can avoid some things here.

mgravell added a commit that referenced this issue Mar 30, 2023
* add passing (modified) test for #2418

* - clarify the meaning of RedisValue.IsInteger, and reduce the visibility
- fix a typo

* fix PR number
@NickCraver
Copy link
Collaborator

Fixed in #2420 - closing out to cleanup :)

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

No branches or pull requests

3 participants