#!/usr/bin/env python
from redis import StrictRedis
rr = StrictRedis()
# rr.flushdb()
rr.execute_command('ft.create', 'idx', 'schema', 'f1', 'text', 'f2', 'text', 'n1', 'numeric', 'sortable')
rr.execute_command('ft.add', 'idx', 'doc1', 1.0, 'fields', 'f1', 'first 1', 'f2', 'first 2', 'n1', 100)
rr.execute_command('ft.add', 'idx', 'doc2', 1.0, 'fields', 'f1', 'second 1', 'f2', 'second 2', 'n1', 200)
rr.execute_command('ft.add', 'idx', 'doc3', 1.0, 'fields', 'f1', 'third 1', 'f2', 'third 2', 'n1', 300)
print rr.execute_command('ft.search', 'idx', '*', 'sortby', 'n1', 'asc')
print rr.execute_command('ft.search', 'idx', '*', 'sortby', 'n1', 'asc', 'LIMIT', 0, 1)
print rr.execute_command('ft.search', 'idx', '*', 'sortby', 'n1', 'asc', 'LIMIT', 1, 1)
# output:
[3L, 'doc1', ['f1', 'first 1', 'f2', 'first 2', 'n1', '100'], 'doc2', ['f1', 'second 1', 'f2', 'second 2', 'n1', '200'], 'doc3', ['f1', 'third 1', 'f2', 'third 2', 'n1', '300']]
[3L, 'doc1', ['f1', 'first 1', 'f2', 'first 2', 'n1', '100']]
[3L, 'doc2', ['f1', 'second 1', 'f2', 'second 2', 'n1', '200']]