kvs.htm 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <html>
  2. <head>
  3. <meta charset="utf-8" />
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <meta name="description" content="" />
  7. <meta name="author" content="Maxim Sokhatsky" />
  8. <title>KVS</title>
  9. <link rel="stylesheet" href="https://n2o.space/n2o.css" />
  10. </head>
  11. <body>
  12. <header>
  13. <a href="../index.html"><img src="https://n2o.space/img/Synrc Neo.svg"></a>
  14. <h1>KVS</h1>
  15. </header>
  16. <main>
  17. <section>
  18. <h3>INTRO</h3>
  19. <p>This module is used to manage different KV backends to your cloud of Erlang apps.
  20. This is an unified abstraction layer to several databases: <b>redis</b>,
  21. <b>mongo</b>, <b>mnesia</b>, <b>riak</b>, <b>aerospike</b>.</p>
  22. <p><blockquote><p><ul>
  23. <li><b><a href="#dir">dir/0</a></b> &mdash; table list.</li>
  24. <li><b><a href="#ver">ver/0</a></b> &mdash; KVS version.</li>
  25. <li><b><a href="#seq">seq/2</a></b> &mdash; generate new sequence id for table.</li>
  26. <li><b><a href="#count">count/1</a></b> &mdash; records in table.</li>
  27. <li><b><a href="#put">put/1</a></b> &mdash; put record using element 2 as key.</li>
  28. <li><b><a href="#get">get/2</a></b> &mdash; get record by key from table.</li>
  29. <li><b><a href="#delete">delete/1</a></b> &mdash; delete record from table.</li>
  30. <li><b><a href="#index">index/3</a></b> &mdash; index by field and its value.</li>
  31. </ul></p></blockquote></p>
  32. <p>You can change backend by setting application env. This behaves well on </p>
  33. <figure><code>
  34. application:set_env(kvs,dba,store_mnesia).
  35. </code></figure>
  36. </section>
  37. <section>
  38. <h3>RECORDS</h3>
  39. <figure><figcaption>KVS CORE</figcaption><code>
  40. #ok { data= [] :: term() }.
  41. #error { data= [] :: term() }.
  42. #cur { id= [] :: term(),
  43. top= [] :: [] | integer(),
  44. bot= [] :: [] | integer(),
  45. dir= 0 :: 0 | 1,
  46. reader= [] :: [] | tuple(),
  47. writer= [] :: [] | tuple(),
  48. left= 0 :: integer(),
  49. right= 0 :: inetegr() }.
  50. #iter { id= [] :: [] | integer(),
  51. prev= [] :: [] | integer(),
  52. next= [] :: [] | integer()).
  53. </code></figure>
  54. <p><ul>
  55. <li>id &mdash; Unique key of the cursor.</li>
  56. </ul></p>
  57. </section>
  58. <section>
  59. <h3>CONFIG</h3>
  60. <p>In sys.config you should specify kvs backend and list of modules
  61. containing <b>metainfo/0</b> exported function.</p>
  62. <figure><code>
  63. [{kvs, [{dba, store_mnesia},
  64. {schema, [kvs]} ]}].
  65. </code></figure>
  66. </section>
  67. <section>
  68. <p>This module may refer to:
  69. <a href="http://erlang.org/doc/man/mnesia.html">mnesia</a></b>,
  70. <a href="kvs_stream.htm"><b>kvs_stream</b></a>.
  71. </p>
  72. </section>
  73. </main>
  74. <footer>
  75. 2005&mdash;2017 &copy; Synrc Research Center
  76. </footer>
  77. </body>
  78. </html>