hmset a string, hget a int type
wuaoo opened this issue · 3 comments
wuaoo commented
# coding=UTF-8
from twisted.internet import defer, reactor
import txredisapi
redis_conf = {
'host': 'localhost',
'port': 6379,
'dbid': 0
}
redis_db = txredisapi.lazyConnectionPool(**redis_conf)
@defer.inlineCallbacks
def test_txredis_hmset():
k = 'test'
v = {'a': '1'}
yield redis_db.hmset(k, v)
query_v = yield redis_db.hget(k, 'a')
print type(query_v) # <type 'int'>
if __name__ == '__main__':
reactor.callLater(0, test_txredis_hmset)
reactor.callLater(1, reactor.stop)
reactor.run()
python_version = 2.7.10
txredisapi_version = 2.4.3
IlyaSkriblovsky commented
This is an expected behavior. Redis itself doesn't make a distinction between string and number types. txredisapi tries to guess the type if convertNumbers
is set to True
(this is the default). So, if you set a number-like string, you will get back an integer.
You can disable this auto-converting by adding convertNumbers=False
to lazyConnectionPool(...)
. But in this case you will always get a string, even if you wrote an integer.
wuaoo commented
Thinks, very much!
fiorix commented
👍