question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

My value is stored as a number. Why does it become a string after being taken out with .get()?

See original GitHub issue
key = 'id'
value = 111
await redisdb.set(key, value)
res = await redisdb.get(key)
print(res, type(res))

image

Is there a way to keep the number type? Thanks

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
SuperSajuukcommented, Feb 12, 2021

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).

1reaction
MojtabaArezoomandcommented, Nov 1, 2021

@Andrew-Chen-Wang Pickling is working great. Thanks for your early response and help.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found