(add-write-hook! store hook-id hook-fn)Register a write hook on the store. The hook-fn will be called after every successful write operation at the API layer (assoc-in, update-in, dissoc, etc.).
Hook message format: {:api-op :assoc-in|:assoc|:update-in|:update|:dissoc|:bassoc|:multi-assoc :key <top-level key> :key-vec <full key path> (for assoc-in/update-in) :value <written value> :old-value <previous value> (for update operations) :kvs <map of key->value> (for multi-assoc)}
Parameters:
Returns the store for chaining.
Register a write hook on the store. The hook-fn will be called after every
successful write operation at the API layer (assoc-in, update-in, dissoc, etc.).
Hook message format:
{:api-op :assoc-in|:assoc|:update-in|:update|:dissoc|:bassoc|:multi-assoc
:key <top-level key>
:key-vec <full key path> (for assoc-in/update-in)
:value <written value>
:old-value <previous value> (for update operations)
:kvs <map of key->value> (for multi-assoc)}
Parameters:
- store: A store implementing PWriteHookStore
- hook-id: Unique identifier for the hook (keyword recommended)
- hook-fn: Function of one argument (the write event map)
Returns the store for chaining.(append store key elem)(append store key elem opts)Append the Element to the log at the given key or create a new append log there. This operation only needs to write the element and pointer to disk and hence is useful in write-heavy situations.
Append the Element to the log at the given key or create a new append log there. This operation only needs to write the element and pointer to disk and hence is useful in write-heavy situations.
(assoc store key val)(assoc store key val opts)Associates the key to the value. This is a simple top-level overwrite and does not require locking for MVCC stores. For nested paths, use assoc-in.
Associates the key to the value. This is a simple top-level overwrite and does not require locking for MVCC stores. For nested paths, use assoc-in.
(assoc-in store key-vec val)(assoc-in store key-vec val opts)Associates the key-vec to the value, any missing collections for the key-vec (nested maps and vectors) are newly created.
Associates the key-vec to the value, any missing collections for the key-vec (nested maps and vectors) are newly created.
(assoc-serializers store serializers)Assoc the given serializers onto the store, taking effect immediately.
Assoc the given serializers onto the store, taking effect immediately.
(bassoc store key val)(bassoc store key val opts)Copies given value (InputStream, Reader, File, byte[] or String on JVM, Blob in JavaScript) under key in the store.
Copies given value (InputStream, Reader, File, byte[] or String on JVM, Blob in JavaScript) under key in the store.
(bget store key locked-cb)(bget store key locked-cb opts)Calls locked-cb with a platform specific binary representation inside the lock, e.g. wrapped InputStream on the JVM and Blob in JavaScript. You need to properly close/dispose the object when you are done!
You have to do all work in locked-cb, e.g.
(fn [{is :input-stream}] (let [tmp-file (io/file "/tmp/my-private-copy")] (io/copy is tmp-file)))
When called asynchronously (by default or w/ {:sync? false}), the locked-cb must synchronously return a channel.
Calls locked-cb with a platform specific binary representation inside
the lock, e.g. wrapped InputStream on the JVM and Blob in
JavaScript. You need to properly close/dispose the object when you
are done!
You have to do all work in locked-cb, e.g.
(fn [{is :input-stream}]
(let [tmp-file (io/file "/tmp/my-private-copy")]
(io/copy is tmp-file)))
When called asynchronously (by default or w/ {:sync? false}), the locked-cb
must synchronously return a channel.Connect to a konserve store based on :backend key in config.
Dispatches to the appropriate backend implementation based on the :backend key. The second argument (opts) controls synchronous or asynchronous execution.
Args: config - A map with :backend key and backend-specific configuration opts - Optional map with :sync? true/false (defaults to async {:sync? false})
Built-in backends:
External backends (require the module first):
Example: (connect-store {:backend :memory} {:sync? true}) (connect-store {:backend :file :path "/tmp/store"} {:sync? true}) (connect-store {:backend :s3 :bucket "my-bucket" :region "us-east-1"} {:sync? false})
See konserve.store namespace for multimethod definitions and backend registration.
Connect to a konserve store based on :backend key in config.
Dispatches to the appropriate backend implementation based on the :backend key.
The second argument (opts) controls synchronous or asynchronous execution.
Args:
config - A map with :backend key and backend-specific configuration
opts - Optional map with :sync? true/false (defaults to async {:sync? false})
Built-in backends:
- :memory - In-memory store (all platforms)
- :file - File-based store (JVM only)
External backends (require the module first):
- :file - File-based store for Node.js (konserve.node-filestore)
- :indexeddb - Browser IndexedDB (konserve.indexeddb - browser only)
- :s3 - AWS S3 (konserve-s3)
- :dynamodb - AWS DynamoDB (konserve-dynamodb)
- :redis - Redis (konserve-redis)
- :lmdb - LMDB (konserve-lmdb)
- :rocksdb - RocksDB (konserve-rocksdb)
Example:
(connect-store {:backend :memory} {:sync? true})
(connect-store {:backend :file :path "/tmp/store"} {:sync? true})
(connect-store {:backend :s3 :bucket "my-bucket" :region "us-east-1"} {:sync? false})
See konserve.store namespace for multimethod definitions and backend registration.Create a new store.
Note: Most backends auto-create on connect-store, so this is often equivalent. Use this when you explicitly want to create a new store. Will error if store already exists.
Args: config - A map with :backend key and backend-specific configuration opts - Optional map with :sync? true/false (defaults to async {:sync? false})
Example: (create-store {:backend :memory} {:sync? true}) (create-store {:backend :file :path "/tmp/store"} {:sync? true})
See connect-store for available backends.
Create a new store.
Note: Most backends auto-create on connect-store, so this is often equivalent.
Use this when you explicitly want to create a new store. Will error if store
already exists.
Args:
config - A map with :backend key and backend-specific configuration
opts - Optional map with :sync? true/false (defaults to async {:sync? false})
Example:
(create-store {:backend :memory} {:sync? true})
(create-store {:backend :file :path "/tmp/store"} {:sync? true})
See connect-store for available backends.Delete/clean up an existing store (removes underlying storage).
Args: config - The same config map used with connect-store opts - Optional map with :sync? true/false (defaults to async {:sync? false})
Example: (delete-store {:backend :file :path "/tmp/store"} {:sync? true}) (delete-store {:backend :s3 :bucket "my-bucket" :region "us-east-1"} {:sync? false})
See connect-store for available backends.
Delete/clean up an existing store (removes underlying storage).
Args:
config - The same config map used with connect-store
opts - Optional map with :sync? true/false (defaults to async {:sync? false})
Example:
(delete-store {:backend :file :path "/tmp/store"} {:sync? true})
(delete-store {:backend :s3 :bucket "my-bucket" :region "us-east-1"} {:sync? false})
See connect-store for available backends.(dissoc store key)(dissoc store key opts)Removes an entry from the store.
Removes an entry from the store.
(exists? store key)(exists? store key opts)Checks whether value is in the store.
Checks whether value is in the store.
(get store key)(get store key not-found)(get store key not-found opts)Returns the value stored described by key. Returns nil if the key is not present, or the not-found value if supplied.
Returns the value stored described by key. Returns nil if the key is not present, or the not-found value if supplied.
(get-in store key-vec)(get-in store key-vec not-found)(get-in store key-vec not-found opts)Returns the value stored described by key. Returns nil if the key is not present, or the not-found value if supplied.
Returns the value stored described by key. Returns nil if the key is not present, or the not-found value if supplied.
(get-meta store key)(get-meta store key not-found)(get-meta store key not-found opts)Returns the value stored described by key. Returns nil if the key is not present, or the not-found value if supplied.
Returns the value stored described by key. Returns nil if the key is not present, or the not-found value if supplied.
(keys store)(keys store opts)Return a channel that will yield all top-level keys currently in the store.
Return a channel that will yield all top-level keys currently in the store.
(lock-free? store)Returns true if the store does not require application-level locking. MVCC stores like LMDB implement the PLockFreeStore protocol to indicate they handle concurrency internally.
Returns true if the store does not require application-level locking. MVCC stores like LMDB implement the PLockFreeStore protocol to indicate they handle concurrency internally.
(log store key)(log store key opts)Loads the whole append log stored at key.
Loads the whole append log stored at key.
(maybe-go-locked store key & code)Like go-locked, but skips locking if store is lock-free.
Like go-locked, but skips locking if store is lock-free.
(maybe-locked store key & code)Like locked, but skips locking if store is lock-free.
Like locked, but skips locking if store is lock-free.
(multi-assoc store kvs)(multi-assoc store kvs opts)Atomically associates multiple key-value pairs with flat keys. Takes a map of keys to values and stores them in a single atomic transaction. All operations must succeed or all must fail (all-or-nothing semantics).
Example:
(multi-assoc store {:user1 {:name "Alice"}
:user2 {:name "Bob"}})
Returns a map of keys to results (typically true for each key).
Throws an exception if the store doesn't support multi-key operations.
Atomically associates multiple key-value pairs with flat keys.
Takes a map of keys to values and stores them in a single atomic transaction.
All operations must succeed or all must fail (all-or-nothing semantics).
Example:
```
(multi-assoc store {:user1 {:name "Alice"}
:user2 {:name "Bob"}})
```
Returns a map of keys to results (typically true for each key).
Throws an exception if the store doesn't support multi-key operations.(multi-dissoc store keys)(multi-dissoc store keys opts)Atomically dissociates multiple keys with flat keys. Takes a collection of keys to remove and deletes them in a single atomic transaction. All operations must succeed or all must fail (all-or-nothing semantics).
Example:
(multi-dissoc store [:user1 :user2 :user3])
Returns a map of keys to results (typically true for each key).
Throws an exception if the store doesn't support multi-key operations.
Atomically dissociates multiple keys with flat keys. Takes a collection of keys to remove and deletes them in a single atomic transaction. All operations must succeed or all must fail (all-or-nothing semantics). Example: ``` (multi-dissoc store [:user1 :user2 :user3]) ``` Returns a map of keys to results (typically true for each key). Throws an exception if the store doesn't support multi-key operations.
(multi-get store keys)(multi-get store keys opts)Atomically retrieves multiple values by keys. Takes a collection of keys and returns a sparse map containing only found keys. Uses flat keys only (not key-vecs).
Example:
(multi-get store [:user1 :user2 :user3])
;; => {:user1 {:name "Alice"} :user3 {:name "Charlie"}}
;; (user2 was not found, so excluded from result)
Returns a map {key -> value} for all found keys. Missing keys are excluded from result. Callers can use standard map lookup to handle missing keys: (get result :user2 :not-found) ;; => :not-found
Throws an exception if the store doesn't support multi-key operations.
Atomically retrieves multiple values by keys.
Takes a collection of keys and returns a sparse map containing only found keys.
Uses flat keys only (not key-vecs).
Example:
```
(multi-get store [:user1 :user2 :user3])
;; => {:user1 {:name "Alice"} :user3 {:name "Charlie"}}
;; (user2 was not found, so excluded from result)
```
Returns a map {key -> value} for all found keys. Missing keys are excluded from result.
Callers can use standard map lookup to handle missing keys:
(get result :user2 :not-found) ;; => :not-found
Throws an exception if the store doesn't support multi-key operations.(reduce-log store key reduce-fn acc)(reduce-log store key reduce-fn acc opts)Loads the append log and applies reduce-fn over it.
Loads the append log and applies reduce-fn over it.
Release connections and resources held by a store.
Args: config - The config map used to create the store store - The store instance to release opts - Optional map with :sync? true/false (defaults to async {:sync? false})
Example: (release-store {:backend :file :path "/tmp/store"} store {:sync? true}) (release-store {:backend :s3 :bucket "my-bucket" :region "us-east-1"} store)
See connect-store for available backends.
Release connections and resources held by a store.
Args:
config - The config map used to create the store
store - The store instance to release
opts - Optional map with :sync? true/false (defaults to async {:sync? false})
Example:
(release-store {:backend :file :path "/tmp/store"} store {:sync? true})
(release-store {:backend :s3 :bucket "my-bucket" :region "us-east-1"} store)
See connect-store for available backends.(remove-write-hook! store hook-id)Remove a previously registered write hook by its id.
Parameters:
Returns the store for chaining.
Remove a previously registered write hook by its id. Parameters: - store: A store implementing PWriteHookStore - hook-id: The id used when registering the hook Returns the store for chaining.
Check if a store exists at the given configuration.
Args: config - A map with :backend key and backend-specific configuration opts - Optional map with :sync? true/false (defaults to async {:sync? false})
Returns: true if store exists, false otherwise (or channel in async mode)
Example: (store-exists? {:backend :memory :id "my-store"} {:sync? true}) (store-exists? {:backend :file :path "/tmp/store"} {:sync? true})
See connect-store for available backends.
Check if a store exists at the given configuration.
Args:
config - A map with :backend key and backend-specific configuration
opts - Optional map with :sync? true/false (defaults to async {:sync? false})
Returns:
true if store exists, false otherwise (or channel in async mode)
Example:
(store-exists? {:backend :memory :id "my-store"} {:sync? true})
(store-exists? {:backend :file :path "/tmp/store"} {:sync? true})
See connect-store for available backends.(update store key fn)(update store key fn opts)Updates a position described by key by applying up-fn and storing the result atomically. Returns a vector [old new] of the previous value and the result of applying up-fn (the newly stored value).
Updates a position described by key by applying up-fn and storing the result atomically. Returns a vector [old new] of the previous value and the result of applying up-fn (the newly stored value).
(update-in store key-vec up-fn)(update-in store key-vec up-fn opts)Updates a position described by key-vec by applying up-fn and storing the result atomically. Returns a vector [old new] of the previous value and the result of applying up-fn (the newly stored value).
Updates a position described by key-vec by applying up-fn and storing the result atomically. Returns a vector [old new] of the previous value and the result of applying up-fn (the newly stored value).
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |