ring

Thierry 2022-05-17T09:28:29.152529Z

Hi everyone! I have a quick question. Is it possible to access the contents of ring.middleware.session.memory/memory-store without passing a predefined atom? I know I can access the data if I define an atom and pass that as argument to memory-store. If I don't then the function creates an unnamed atom, how do I access the unnamed atom? It only returns the following without me being able to access it. #object [ring.middleware.session.memory.MemoryStore 0x1295a8d0 "ring.middleware.session.memory.MemoryStore@1295a8d0"]

jumar 2022-05-17T09:50:56.045329Z

do you want that for debugging or what do you want to do with that?

Thierry 2022-05-17T09:51:39.248669Z

What I want to do in the end is get the ips that are logged in and the session count per ip.

jumar 2022-05-17T09:56:02.144659Z

Is that information going to be available in your session? I feel like you should use a separate mechanism for getting these stats. But you could use something like this as a workaround:

(comment
  (def ms (memory-store))
  (.write-session ms "k" "val")
  (.read-session ms "k")
  (.write-session ms "k2" "val2")

  (.session_map ms)
  ;; => #atom[{"k" "val", "k2" "val2"} 0x7f51bf9]

  .)

✅ 1
Thierry 2022-05-17T09:57:03.603989Z

Thanks! the (.session_map X) was exactly what I was looking for

Thierry 2022-05-17T09:57:13.994279Z

no idea why i couldnt find that with google

jumar 2022-05-17T09:57:34.559859Z

Of course, this relies on an implementation detail 🙂 I just used cider-inspect in emacs to look at the contents of ms var.

Thierry 2022-05-17T09:59:55.808469Z

I use Calva in VSCode, no clue how to do cider-inspect there

jumar 2022-05-17T10:03:46.782429Z

Maybe it's not as easy. This one is less convenient but I used to use it a while ago:

(->> (clojure.reflect/reflect ms) :members (sort-by :name) (clojure.pprint/print-table [:name :flags :parameter-types :return-type]))

Thierry 2022-05-17T10:06:05.775959Z

That works, thanks! Looking at the output I was close, but not close enough haha

Thierry 2022-05-17T10:06:44.198139Z

(vec (.getMethods (.getClass session-store))) found some of them, but didnt include session_map