My value is stored as a number. Why does it become a string after being taken out with .get()?
See original GitHub issuekey = 'id'
value = 111
await redisdb.set(key, value)
res = await redisdb.get(key)
print(res, type(res))
Is there a way to keep the number type? Thanks
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Results From Across the Web
Convert numbers stored as text to numbers - Microsoft Support
When numbers are actually stored in cells as text, problems with calculations or sorting can occur. Read this article to learn how to...
Read more >Excel VALUE function to convert text to numbers - Ablebits
The VALUE function in Excel is designed to convert text values to numbers. It can recognize numeric strings, dates and times. ... Where...
Read more >SQL order string as number - Stack Overflow
It is taking them as character not as number while sorting. In database I have 1 2 3 4 5 6 7 8 ......
Read more >Number - JavaScript - MDN Web Docs - Mozilla
Chrome Edge
Number Full support. Chrome1. Toggle history Full support. Edge12. Toggl...
EPSILON Full support. Chrome34. Toggle history Full support. Edge12. Toggl...
MAX_SAFE_INTEGER Full support. Chrome34....
Read more >Strings and Character Data in Python
You will also be introduced to two other Python objects used to represent raw byte data, the bytes and bytearray types. Take the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Bit late but worth pointing out that Redis doesn’t really have a concept of integers as far as I’ve determined. Anything involving integers will be converted to string automatically. Using set only stores “strings”, so if something is an integer, it gets converted before being stored, hence why your returned value from get() is now a string. You will just have to know which keys will be a pure integer and then cast them to a Python integer.
Side note: I wouldn’t recommend using Pickle for this kind of thing, seems a bit unnecessary. Just test your key for whether it returns None (meaning it doesn’t exist) or convert to int in your code when it does with a try/except block if the value isn’t an integer (but if you know that a specific key will always be an int, you shouldn’t need a try/except).
@Andrew-Chen-Wang Pickling is working great. Thanks for your early response and help.