hiredis | R Documentation |
Create an interface to Redis, with a generated interface to all Redis commands.
hiredis(..., version = NULL)
redis_available(...)
... |
Named configuration options passed to
|
version |
Version of the interface to generate. If given as
a string to numeric version, then only commands that exist up to
that version will be included. If given as |
There is no need to explicitly close the redis connection. It will be closed automatically when the connection goes out of scope and is garbage collected.
Some commands will block. This includes BRPOP
(and other
list commands beginning with B
). Once these commands have
been started, they cannot be interrupted by Ctrl-C from an R
session. This is because the redux
package hands over
control to a blocking function in the hiredis
(C) library,
and this cannot use R's normal interrupt machinery. If you want
to block but retain the ability to interrupt then you will need to
wrap this in another call that blocks for a shorter period of
time:
found <- NULL con <- redux::hiredis() found <- NULL while (is.null(found)) { found <- con$BLPOP("key", 1) Sys.sleep(0.01) # needed for R to notice that interrupt has happened }
# Only run if a Redis server is running
if (redux::redis_available()) {
r <- redux::hiredis()
r$PING()
r$SET("foo", "bar")
r$GET("foo")
# There are lots of methods here:
r
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.