IlyaSkriblovsky / txredisapi

non-blocking redis client for python twisted
Apache License 2.0
235 stars 91 forks source link

hmset a string, hget a int type #109

Closed wuaoo closed 8 years ago

wuaoo commented 8 years ago
# 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 8 years ago

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 8 years ago

Thinks, very much!

fiorix commented 8 years ago

👍