0

Good Afternoon,

  1. I am using pythomnic3k python framework and sharded solr, redis database servers.

    Following is my api request:

    http://1.2.3.4:8090/api20/account2/addnewemail?Email=foo@yahoo.com&Token=[redacted]&AccountID=[redacted]

    error: AttributeError: 'function' object has no attribute 'get'

  2. Function where this error arises:

    def count_maps(r):
        dt = r.get(Namespace.MAPPINGS + ':count')
    

    r is redis instance and Namespance.Mappings + ':count' = ytk:map:count

  3. solr schema xml file has these sharded instance:

    <?xml version="1.0" encoding="UTF-8"?>
        <mapping>
            <meta>
                <date>201-12-13 00:00:00</date>
                <active>true</active>
                <static url="0.0.0.0:8983/solr" />
            </meta>
            <map>
                <shard url="0.0.0.0:8983/solr" start="00000000" end="00009999" readonly="false">
                    <slave url="0.0.0.0:8983/solr" />
                </shard>
            </map>
        </mapping>
    
  1. Redis instance r is in redis_utils.py

    def test_redis_obj(r):
    try:
        r.ping()
        return True
    except ConnectionError: 
        return False
    
    def redis_obj(redis_def, timeout = None):
    if not redis_def:
        return None
            return redis.StrictRedis(
                host = redis_def["ip"],
                port = redis_def["port"],
                db = redis_def["db"],
                socket_timeout = timeout
            )
    
    def random_redis_obj(timeout = None):
        return redis_obj(random_redis_def(), timeout)
    
    def random_tested_redis_obj(attempts = 3, timeout = 1):
        for _ in range(attempts):
            r = random_redis_obj(timeout)
            if r and test_redis_obj(r):
                return r
    raise YtkRedisError("active redis server not found (%d attempts done)" % attempts)
    
  2. Here is function where count_maps(r) is called in solr_manager.py:

    def get_unique_shards(r, the_map: int = -1):
        '''
        Returns array: [map][shard](0: url; 1: [slaves urls])
        with unique shards with their slaves in mappings
        '''
    num = count_maps(r)
    if the_map >= num:
        raise IndexError("There aren't map at index " + str(the_map))
    if the_map < 0:
        return _get_all_unique_shards(r, num)
    else:
        return _get_unique_shards(r, the_map)
    
    def count_maps(r):
        dt = r.get(Namespace.MAPPING + ':count')
        if dt is not None:
            return int(dt)
        return None
    
    • I understand this redis object try to count solr instances, is it right ?

    • Kindly help me in what can be possible reason why my redis object is None ? I checked my logs same 'get attribute..' error and unable to debug it.

afuzzyllama
  • 6,538
  • 5
  • 47
  • 64
JKV
  • 281
  • 1
  • 4
  • 8
  • 4
    `r` is not `None`; according to your error, it is a function. Please post the code where you create `r`. – jonrsharpe Dec 16 '13 at 11:27
  • @jonrsharpe I have updated my question with code where r is declared, – JKV Dec 16 '13 at 11:46
  • No you haven't: you've posted some code which returns an object called `r`. Which doesn't call `count_maps`. BTW - Is this really your whitespace? – doctorlove Dec 16 '13 at 11:48
  • @doctorlove sorry if it is still not clear, but I am trying to put all information I understand. – JKV Dec 16 '13 at 12:04
  • Well, now you're calling `get_unique_shards()` with an argument `r`. Which you still don't show the creation of. And where's the traceback? – Wooble Dec 16 '13 at 12:27

1 Answers1

1

As I got your question, an r is a connection to redis, if it's so you can define at the beggining of your py file like:

import redis

r = redis.ConnectionPool(host='localhost', port=6379, db=0)

Than you can use r as:

def count_maps():
    dt = r.get(Namespace.MAPPING + ':count')
    if dt is not None:
        return int(dt)
    return None
greg
  • 1,417
  • 9
  • 28
  • thanks, but I am using `from shared.redis_utils import decode_obj, random_tested_redis_obj` at the very top of the file. You are right but `r` is `StrictRedis` not using connection pool, thanks I think I am close after your answer – JKV Dec 16 '13 at 13:31