Liking cljdoc? Tell your friends :D

konserve.core


add-write-hook!clj/s

(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:

  • 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.

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.
sourceraw docstring

appendclj/s

(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.
sourceraw docstring

assocclj/s

(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.
sourceraw docstring

assoc-inclj/s

(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.
sourceraw docstring

assoc-serializersclj/s

(assoc-serializers store serializers)

Assoc the given serializers onto the store, taking effect immediately.

Assoc the given serializers onto the store, taking effect immediately.
sourceraw docstring

bassocclj/s

(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.
sourceraw docstring

bgetclj/s

(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.
sourceraw docstring

connect-storeclj/s

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.

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.
sourceraw docstring

create-storeclj/s

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.
sourceraw docstring

delete-storeclj/s

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.
sourceraw docstring

dissocclj/s

(dissoc store key)
(dissoc store key opts)

Removes an entry from the store.

Removes an entry from the store. 
sourceraw docstring

exists?clj/s

(exists? store key)
(exists? store key opts)

Checks whether value is in the store.

Checks whether value is in the store.
sourceraw docstring

getclj/s

(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.
sourceraw docstring

get-inclj/s

(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.
sourceraw docstring

get-lockclj/s

(get-lock {:keys [locks] :as store} key)
source

get-metaclj/s

(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.
sourceraw docstring

go-lockedclj/smacro

(go-locked store key & code)
source

keysclj/s

(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.
sourceraw docstring

lock-free?clj/s

(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.
sourceraw docstring

lockedclj/smacro

(locked store key & code)
source

logclj/s

(log store key)
(log store key opts)

Loads the whole append log stored at key.

Loads the whole append log stored at key.
sourceraw docstring

maybe-go-lockedclj/smacro

(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.
sourceraw docstring

maybe-lockedclj/smacro

(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.
sourceraw docstring

multi-assocclj/s

(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.
sourceraw docstring

multi-dissocclj/s

(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.
sourceraw docstring

multi-getclj/s

(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.
sourceraw docstring

reduce-logclj/s

(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.
sourceraw docstring

release-storeclj/s

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.
sourceraw docstring

remove-write-hook!clj/s

(remove-write-hook! store hook-id)

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.

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.
sourceraw docstring

store-exists?clj/s

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.
sourceraw docstring

updateclj/s

(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).
sourceraw docstring

update-inclj/s

(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).
sourceraw docstring

waitclj/s

(wait lock)
source

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close