R
R
Rostislav Ignatenko2017-05-31 17:42:59
JavaScript
Rostislav Ignatenko, 2017-05-31 17:42:59

How to store numbers in Redis?

There is an application on Node.js and a Redis server where values ​​are written in the form

client.hmset(id, {
      'name': 'John',
      'age': 25
    })

I am trying to get the age values ​​like this
client.hgetall(id, function(err, obj){
      console.log(obj.age);               // 25
      console.log(typeof(obj.age));   // String
})

Those. as I understand it, all data in Redis is stored as strings? Or is it still possible to store int values ​​somehow?
I just don’t want to apply every time I get such a value
Number(obj.age);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Fortop, 2017-06-07
@Fortop

Stored always and exclusively as strings (except bitmasks https://redis.io/topics/data-types
) you definitely need to do type casting, where you need it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question