bustle / radredis

Basic redis backed object modeling for Node.
19 stars 3 forks source link

Value normalization does not consider the null/empty case. #54

Closed jqyu closed 7 years ago

jqyu commented 7 years ago

Redis values are serialized as strings, and as such nulls are typically stored as the empty string. Thus, when retrieving specific properties, nulls will be deserialized incorrectly:

https://github.com/bustlelabs/radredis/blob/master/src/index.js#L268-L270

import radredis from 'radredis'
const Model = radredis({
  foo: { type: 'integer' },
  bar: { type: 'integer' }
})

Model.create({ foo: 123 })
     .then(() => Model.find(1, [ 'foo', 'bar' ]))
     // => { foo: 123, bar: NaN }

Problem lies in the fact that calling an hmget returns empty strings, not undefined