Comments (5)
Hi Eric,
Thanks for getting in touch!
The problem you're running into here isn't to do with make-conn-spec
, but with the fact that you're trying to define a function of [& body]. Function arguments are evaluated right away - in this case before the bindings established by with-conn
are actually in effect.
I might be able to make a suggestion if I understood better what you're trying to accomplish. I'm not familiar with Hyperion - took a look at the page just now, but couldn't find a simple description of what expectations it has for adapter APIs.
Could you point me toward a simple spec somewhere?
from carmine.
Hey Peter,
I'll give a quick run-down on how Hyperion works. Hyperion has a bunch of DataStores. Each one for a different database. The datastore is created with an database argument, which is then passed to each of its functions.
I would like to treat this database argument like the carmine macro. Example.
If I can get the first two specs of this file to pass I think I'll have smooth sailing from there.
from carmine.
Okay, I looked over the links briefly.
So can I clarify:
- You're trying to implement
hyperion.abstr/Datastore
for Carmine. - https://github.com/ekosz/hyperion/blob/redis/redis/src/hyperion/redis.clj is working already?
- You'd like to now make the connection stuff configurable through
open-db
?
Is that right?
I would like to treat this database argument like the carmine macro. Example.
Are you saying you're trying to get db
to behave like the with-conn
macro? That won't be possible (the one's a function, the other a macro), but it also doesn't seem like it should be necessary if all you want to do is satisfy #3 above.
What stops you from just giving the desired connection pool & spec to each with-conn
call?
So, for example, something like:
(defn- save-record [db record]
(let [kind (:kind record)
key (name (:key record))
my-pool (some-fn db)
my-spec (some-fn db)]
(carmine/with-conn my-pool my-spec
(r/set (str kind ":" key) record))
record))
I'm not sure what form db
takes exactly, but I'm assuming the options are somehow accesible through it, right?
So maybe something like:
(defn open-db [options]
(let [defaults {:host "127.0.0.1" :port 6379 :password nil :timeout 0 :db 0}
pool (r/make-conn-pool :max-active 8)
connection-spec (merge defaults options)]
{:pool pool :spec connection-spec})))
Then assuming open-db
returns the db
that's gonna get passed to save-record
...
(defn- save-record [db record]
(let [kind (:kind record)
key (name (:key record)]
(carmine/with-conn (:pool db) (:spec db)
(r/set (str kind ":" key) record))
record))
Disclaimer: I may have completely misunderstood how the API is working :)
from carmine.
Alrighty, I was able to come up with a nice compromise where I didn't have to repeat myself too much. Thank you for your help!
You can check out the redis module of Hyperion here.
from carmine.
Cool- that seems perfect.
A few other comments in case they're helpful:
open-db
would also be a good place to allow overriding the connection pool options if you wanted. There's no overlap between pool and connection-spec options, so you could just lump the two together in the singleoptions
map.- I'm not sure how concerned you are about performance, but be aware that
r/keys
is O(n) so if this is being called often, you may prefer to maintain your own list of keys in a ist or some other kind of index.
Cheers!
from carmine.
Related Issues (20)
- Problems using carmine store HOT 5
- `parse-map` stop working when upgrade from 3.2.0 to 3.3.0 HOT 10
- broken link to nippy in README HOT 1
- Support commands in RediSearch, RedisJSON, RedisTimeSeries, RedisBloom HOT 2
- Handling locked messages after JVM crash HOT 3
- Carmine v4 first core pre-release
- Carmine v4 Tundra
- Carmine v4 Sentinel support
- Carmine v4 Cluster support
- message-queue/queue-names is broken (and untested) HOT 1
- Feedback on v3.3 migration instructions HOT 3
- Silently catches OutOfMemoryErrors without rethrowing HOT 8
- Mutiple atomic transactions as a pipeline HOT 3
- Unexpected behavior with `(parse-map ... :keywordize)` HOT 3
- Does Carmine support DragonflyDB? HOT 10
- Connection loss/failure detection on MQ HOT 12
- Pub/Sub posts to wrong handler fn HOT 5
- Carmine message-queue: allow throughput control HOT 4
- Block on handler being ready when creating new listeners? HOT 4
- Closing the listener produces at least one error message to handler, sometimes several. HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from carmine.