def keysize(db, k):
    """Returns the estimate size, in bytes, of a key and its value.
    The size of the key is simply its length.
    For values, it depends on the datatype:
        For strings, it's the length of the string
        For hashes, it's the sum of the lengths of the fields and their values
        For lists and sets, it's the sum of the lengths of each item
        For sorted sets, it's the 8*num (for the scores) + length of each member
    Returns 0 if the key is not found
    """
    if not k: return 0
    t = db.type(k)
    if not t: return 0
    ret = len(k)
    if t == 'string':
        ret += db.strlen(k)
    elif t == 'hash':
        d = db.hgetall(k)
        for f, v in d.iteritems():
            ret += len(f) + len(v)
    elif t == 'list':
        for el in db.lrange(k, 0, -1):
            ret += len(el)
    elif t == 'set':
        for el in db.smembers(k):
            ret += len(el)
    elif t == 'zset':
        for val in db.zrange(k, 0, -1):
            ret += 8 + len(val)
    return ret