RedisKeyBuilder.coffee 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # The default key schema looks like:
  2. # doclines:foo
  3. # DocVersion:foo
  4. # but if we use redis cluster, we want all 'foo' keys to map to the same
  5. # node, so we must use:
  6. # doclines:{foo}
  7. # DocVersion:{foo}
  8. # since redis hashes on the contents of {...}.
  9. #
  10. # To transparently support different key schemas for different clients
  11. # (potential writing/reading to both a cluster and single instance
  12. # while we migrate), instead of keys, we now pass around functions which
  13. # will build the key when passed a schema.
  14. #
  15. # E.g.
  16. # key_schema = Settings.redis.keys
  17. # key_schema == { docLines: ({doc_id}) -> "doclines:#{doc_id}", ... }
  18. # key_builder = RedisKeyBuilder.docLines({doc_id: "foo"})
  19. # key_builder == (key_schema) -> key_schema.docLines({doc_id: "foo"})
  20. # key = key_builder(key_schema)
  21. # key == "doclines:foo"
  22. module.exports = RedisKeyBuilder =
  23. blockingKey: ({doc_id}) ->
  24. return (key_schema) -> key_schema.blockingKey({doc_id})
  25. docLines: ({doc_id}) ->
  26. return (key_schema) -> key_schema.docLines({doc_id})
  27. docOps: ({doc_id}) ->
  28. return (key_schema) -> key_schema.docOps({doc_id})
  29. docVersion: ({doc_id}) ->
  30. return (key_schema) -> key_schema.docVersion({doc_id})
  31. projectKey: ({doc_id}) ->
  32. return (key_schema) -> key_schema.projectKey({doc_id})
  33. uncompressedHistoryOp: ({doc_id}) ->
  34. return (key_schema) -> key_schema.uncompressedHistoryOp({doc_id})
  35. pendingUpdates: ({doc_id}) ->
  36. return (key_schema) -> key_schema.pendingUpdates({doc_id})
  37. trackChangesEnabled: ({doc_id}) ->
  38. return (key_schema) -> key_schema.trackChangesEnabled({doc_id})
  39. trackChangesEntries: ({doc_id}) ->
  40. return (key_schema) -> key_schema.trackChangesEntries({doc_id})
  41. docsInProject: ({project_id}) ->
  42. return (key_schema) -> key_schema.docsInProject({project_id})
  43. docsWithHistoryOps: ({project_id}) ->
  44. return (key_schema) -> key_schema.docsWithHistoryOps({project_id})