0

in my flask app, I typically will

from extensions import redis

and then in my functions will do something like

redis.set('redis:test:queue:increment', 1)

and all is fine.

Now that I am attempting to install/understand/use python RQ, I'm finding that is it doing something to my Redis() and I cannot use it like above inside a function that is enqueue(). The above test will output:

AttributeError: 'Redis' object has no attribute 'get'

Using a SO method to list all the methods attached to an object, I'm seeing that going through the queue, the redis object only has:

['__class__', '__delattr__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_include_public_methods', 'init_app']

Where-as calling the function outside of rq produces the expected:

['__class__', '__delattr__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_include_public_methods', 'append', 'bgrewriteaof', 'bgsave', 'bitcount', 'bitop', 'bitpos', 'blpop', 'brpop', 'brpoplpush', 'client_getname', 'client_kill', 'client_list', 'client_setname', 'config_get', 'config_resetstat', 'config_rewrite', 'config_set', 'dbsize', 'debug_object', 'decr', 'delete', 'dump', 'echo', 'eval', 'evalsha', 'execute_command', 'exists', 'expire', 'expireat', 'flushall', 'flushdb', 'from_url', 'get', 'getbit', 'getrange', 'getset', 'hdel', 'hexists', 'hget', 'hgetall', 'hincrby', 'hincrbyfloat', 'hkeys', 'hlen', 'hmget', 'hmset', 'hscan', 'hscan_iter', 'hset', 'hsetnx', 'hvals', 'incr', 'incrby', 'incrbyfloat', 'info', 'init_app', 'keys', 'lastsave', 'lindex', 'linsert', 'llen', 'lock', 'lpop', 'lpush', 'lpushx', 'lrange', 'lrem', 'lset', 'ltrim', 'mget', 'move', 'mset', 'msetnx', 'object', 'parse_response', 'persist', 'pexpire', 'pexpireat', 'pfadd', 'pfcount', 'pfmerge', 'ping', 'pipeline', 'psetex', 'pttl', 'publish', 'pubsub', 'randomkey', 'register_script', 'rename', 'renamenx', 'restore', 'rpop', 'rpoplpush', 'rpush', 'rpushx', 'sadd', 'save', 'scan', 'scan_iter', 'scard', 'script_exists', 'script_flush', 'script_kill', 'script_load', 'sdiff', 'sdiffstore', 'sentinel', 'sentinel_get_master_addr_by_name', 'sentinel_master', 'sentinel_masters', 'sentinel_monitor', 'sentinel_remove', 'sentinel_sentinels', 'sentinel_set', 'sentinel_slaves', 'set', 'set_response_callback', 'setbit', 'setex', 'setnx', 'setrange', 'shutdown', 'sinter', 'sinterstore', 'sismember', 'slaveof', 'slowlog_get', 'slowlog_len', 'slowlog_reset', 'smembers', 'smove', 'sort', 'spop', 'srandmember', 'srem', 'sscan', 'sscan_iter', 'strlen', 'substr', 'sunion', 'sunionstore', 'time', 'transaction', 'ttl', 'type', 'unwatch', 'watch', 'zadd', 'zcard', 'zcount', 'zincrby', 'zinterstore', 'zlexcount', 'zrange', 'zrangebylex', 'zrangebyscore', 'zrank', 'zrem', 'zremrangebylex', 'zremrangebyrank', 'zremrangebyscore', 'zrevrange', 'zrevrangebyscore', 'zrevrank', 'zscan', 'zscan_iter', 'zscore', 'zunionstore']

Please someone help me understand what is happening here. It is imperative that my queue'd tasks have access to my redis keys.

chrickso
  • 2,994
  • 5
  • 30
  • 53
  • Are you using Flask-Redis with Flask and something else outside of Flask? – dirn Feb 25 '15 at 20:25
  • flask-and-redis, yes. what do you mean 'outside of flask'? – chrickso Feb 25 '15 at 21:17
  • What `Redis` are you using with RQ? Is it `from redis import Redis`? That's not the same class as what you import from Flask-Redis. – dirn Feb 25 '15 at 21:20
  • i now have this half-working. The RQ worker and the job_functions.py are using from redis import Redis. When I push to heroku the job_function() is attempting to connect to localhost (the default) so am currently trying to figure out how to specify a connection to REDISCLOUD_URL when initiating redis = Redis() – chrickso Feb 25 '15 at 21:27
  • 1
    `import redis` and `r = redis.from_url(os.environ.get('REDISCLOUD_URL'))` should get you going in the right direction. – dirn Feb 25 '15 at 21:36

0 Answers0