Skip to content

Instantly share code, notes, and snippets.

@ivermac
Last active September 19, 2019 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivermac/8dfe31f9e31cc31b4f67804c553692fb to your computer and use it in GitHub Desktop.
Save ivermac/8dfe31f9e31cc31b4f67804c553692fb to your computer and use it in GitHub Desktop.
Calling Java vararg function in Clojure

A colleague and I were using Jedis and wanted to delete multiple keys at once without using a loop. The version of Jedis we were using has 2 del functions and the one we wanted use is a java vararg function and can be found here. We understood a Java vararg function as a variadic function in Clojure which simply means a function with infinite arity. Assuming b1 and a1 are keys in redis, the following is what we attempted initially:

(.del jedis "a1" "b1")

The above failed with the following error: IllegalArgumentException No matching method found: del for class redis.clients.jedis.Jedis clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:80)

A little bit of research lead us to stackoverflow and the first solution of using into-array fixed it for us. We went ahead and tried the following and it worked for us

(.del jedis (into-array ["a1" "b1"]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment