def count_range(self, txn, from_key, to_key):
key_from = struct.pack('<STR_LIT>', self._slot) + self._serialize_key(from_key)<EOL>to_key = struct.pack('<STR_LIT>', self._slot) + self._serialize_key(to_key)<EOL>cnt = <NUM_LIT:0><EOL>cursor = txn._txn.cursor()<EOL>has_more = cursor.set_range(key_from)<EOL>while has_more:<EOL><INDENT>if cursor.key() >= to_key:<EOL><INDENT>break<EOL><DEDENT>cnt += <NUM_LIT:1><EOL>has_more = cursor.next()<EOL><DEDENT>return cnt<EOL>
Counter number of records in the perstistent map with keys
within the given range.

:param txn: The transaction in which to run.
:type txn: :class:`zlmdb.Transaction`

:param from_key: Count records starting and including from this key.
:type from_key: object

:param to_key: End counting records before this key.
:type to_key: object

:returns: The number of records.
:rtype: int