2016-06-07 12:58:18 -04:00
|
|
|
# The default key schema looks like:
|
|
|
|
# doclines:foo
|
|
|
|
# DocVersion:foo
|
|
|
|
# but if we use redis cluster, we want all 'foo' keys to map to the same
|
|
|
|
# node, so we must use:
|
|
|
|
# doclines:{foo}
|
|
|
|
# DocVersion:{foo}
|
|
|
|
# since redis hashes on the contents of {...}.
|
|
|
|
#
|
|
|
|
# To transparently support different key schemas for different clients
|
|
|
|
# (potential writing/reading to both a cluster and single instance
|
|
|
|
# while we migrate), instead of keys, we now pass around functions which
|
|
|
|
# will build the key when passed a schema.
|
|
|
|
#
|
|
|
|
# E.g.
|
|
|
|
# key_schema = Settings.redis.keys
|
|
|
|
# key_schema == { docLines: ({doc_id}) -> "doclines:#{doc_id}", ... }
|
|
|
|
# key_builder = RedisKeyBuilder.docLines({doc_id: "foo"})
|
|
|
|
# key_builder == (key_schema) -> key_schema.docLines({doc_id: "foo"})
|
|
|
|
# key = key_builder(key_schema)
|
|
|
|
# key == "doclines:foo"
|
|
|
|
module.exports = RedisKeyBuilder =
|
|
|
|
blockingKey: ({doc_id}) ->
|
|
|
|
return (key_schema) -> key_schema.blockingKey({doc_id})
|
|
|
|
docLines: ({doc_id}) ->
|
|
|
|
return (key_schema) -> key_schema.docLines({doc_id})
|
|
|
|
docOps: ({doc_id}) ->
|
|
|
|
return (key_schema) -> key_schema.docOps({doc_id})
|
|
|
|
docVersion: ({doc_id}) ->
|
|
|
|
return (key_schema) -> key_schema.docVersion({doc_id})
|
2017-02-14 11:11:43 -05:00
|
|
|
docHash: ({doc_id}) ->
|
|
|
|
return (key_schema) -> key_schema.docHash({doc_id})
|
2016-06-07 12:58:18 -04:00
|
|
|
projectKey: ({doc_id}) ->
|
|
|
|
return (key_schema) -> key_schema.projectKey({doc_id})
|
|
|
|
uncompressedHistoryOp: ({doc_id}) ->
|
|
|
|
return (key_schema) -> key_schema.uncompressedHistoryOp({doc_id})
|
|
|
|
pendingUpdates: ({doc_id}) ->
|
|
|
|
return (key_schema) -> key_schema.pendingUpdates({doc_id})
|
2016-12-08 07:31:43 -05:00
|
|
|
ranges: ({doc_id}) ->
|
|
|
|
return (key_schema) -> key_schema.ranges({doc_id})
|
2016-06-07 12:58:18 -04:00
|
|
|
docsInProject: ({project_id}) ->
|
|
|
|
return (key_schema) -> key_schema.docsInProject({project_id})
|
|
|
|
docsWithHistoryOps: ({project_id}) ->
|
|
|
|
return (key_schema) -> key_schema.docsWithHistoryOps({project_id})
|