Skip to content

Instantly share code, notes, and snippets.

@apb2006
Last active May 10, 2022 17:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apb2006/9563707df4d8f7dd536d9cd3ea70046f to your computer and use it in GitHub Desktop.
Save apb2006/9563707df4d8f7dd536d9cd3ea70046f to your computer and use it in GitHub Desktop.
BaseX Redis (with Jedis)

Requires network access to a server running Redis. In this example the server is called "odroid.local"

Setup

This uses Jedis, a Redis Java client Add the Jedis jars to lib/custom. (Download from https://jar-download.com/artifacts/redis.clients/jedis or similar)

  • jedis-4.2.3.jar
  • gson-2.8.9.jar
  • commons-pool2-2.11.1.jar
  • json-20211205.jar

Note: slf4j-api-1.7.32.jar (not required, later version already in lib)

(: Redis interface test: expiring keys :)
declare namespace JedisPooled = "java:redis.clients.jedis.JedisPooled";
declare variable $REDIS:=JedisPooled:new("odroid.local", 6379);
let $_:=JedisPooled:set($REDIS,"name", "andy") (: create key :)
let $_:=JedisPooled:expire($REDIS,"name",10) (: expire in 10 secs :)
let $_:=JedisPooled:set($REDIS,"calls", "0")
(: query Redis as fast as possible until key disappears, returns number of queries made before expiry :)
return
hof:until(
function($_) {JedisPooled:get($REDIS,"name")=>empty() },
function($_) {JedisPooled:incr($REDIS,"calls")=>trace("still there: ") },
()
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment