使用cassandra作为芹菜结果后端

时间:2014-02-25 16:25:24

标签: python cassandra celery

我正在尝试使用cassandra作为结果后端。这是芹菜应用程序:

from __future__ import absolute_import
from celery import Celery

app = Celery('proj',
        broker='amqp://',
        backend='cassandra',
        include=['proj.tasks'])

# Optional configuration, see the application user guide.
app.conf.update(
    CASSANDRA_SERVERS = ["localhost:9160"],
    CASSANDRA_KEYSPACE = "celery",
    CASSANDRA_COLUMN_FAMILY = "tasks_result",
    CASSANDRA_READ_CONSISTENCY = "ONE",
    CASSANDRA_WRITE_CONSISTENCY = "ONE",
    CASSANDRA_OPTIONS = { 
        'timeout': 10, 
        'max_retries': 1
    }   
    )   

if __name__ == '__main__':
    app.start()

因为,芹菜的cassandra后端使用pycassa,我使用pycassaShell创建了keypace - 'celery'和table - 'tasks_result'。问题是存储在'tasks_result'表中的结果有十六进制十进制值,如下所示:

 key                                                                        | column1   | value
----------------------------------------------------------------------------+-----------+--------------------------------------------
 0x65333336633966622d323937612d346535612d613164352d353333613765663962613663 |  0x6368696c6472656e |                             0x80025d71012e
 0x65333336633966622d323937612d346535612d613164352d353333613765663962613663 | 0x646174655f646f6e65 | 0x323031342d30322d32355431363a30343a34355a
 0x65333336633966622d323937612d346535612d613164352d353333613765663962613663 |    0x726573756c74 |                               0x80024b092e
 0x65333336633966622d323937612d346535612d613164352d353333613765663962613663 |    0x737461747573 |                           0x53554343455353
 0x65333336633966622d323937612d346535612d613164352d353333613765663962613663 | 0x74726163656261636b |                                 0x80024e2e

如何检索存储的实际数据?提前谢谢..

1 个答案:

答案 0 :(得分:1)

创建ColumnFamily(aka表)时,将KeyValidation和ColumnValidation定义为UTF8Type。然后使用pycassa从中读取它应该没问题。默认情况下,Cassandra以二进制形式存储内容。根据表定义,转换由查询接口发生。