Description Usage Arguments Value Data Format Auto-Load References Examples
The function loads config data, stored as JSON-strings in config files to the Redis cache.
1 2 3 4 5 | redis_loadConfig(file, append = FALSE)
redis_readConfigFile(file)
.auto_load(expr, parent)
|
file |
character vector of file names (a single file name for
|
append |
logical, if |
expr |
character string, expression to evaluate, see Auto-Load section for details |
parent |
environment, parent environment for the environment in which
|
a list of configuration settings
All config files must contain data in JSON format. Basic elements of the data structure at top level are
key
mandatory, unique key to store and access data in the Redis cache
value
mandatory, data object containing a list of
key-value pairs. This can be any list of named data. There is one
mandatory element: id
. This is a unique identifier of
the data. It will be matched to key
and no key must be
assigned to one or more id
s (e.g. from multiple
config-files)
auto_load
optional, an auto load obejct, i.e. a list of key-value pairs, see Auto Load section for details.
For loading a minimal config file, see Examples.
The auto_load
section of the config settings contains a named list
of R expressions, e.g.
1 2 3 | "auto_load": {
"date": "Sys.Date()"
}
|
will set the config value date
to the current date (using
Sys.Date()
). Use "::"
to preface the function
with the package name (just like in plain R). A single colon :
can
be used to preface the expression with a file name (i.e. anything
that ends with ".R"
or ".r"
), that will be sourced
before the expression will be evaluated.
If file name is provided without any expression, variable value
as
defined by the script will be returned.
All expressions (and the sourcing of the R-script, in case a file name is
provided) will be evaluated in an separate environment with parent
environment parent
.
Function redis_readConfigFile
, that calls .auto_load
will set
parent
to a new environment containing all non-auto-load config
settings. The parent environment of this is set to
.GlobalEnv
. Thus all config settings and any object
within the global search path will be available for execution of
expr
.
Function redis_readConfigFile
further sets the working directory
temporarily to the config file's base directory, i.e. all relative paths
in a file name will be with respect to this directory.
see https://en.wikipedia.org/wiki/JSON for details on JSON file format
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | ## Not run:
## show template for minimal configuration file
file <- system.file('templates/minimal.cfg', package = 'easyRedis')
cat(stringr::str_c(readLines(file), collapse = '\n'))
## *** SET UP AN OPEN REDIS-CONNECTION FIRST! ***
config <- redis_loadConfig(file)
key <- attr(config, 'key')
redis_getConfig(key)
## *** CLEAR REDIS KEY! ***
rredis::redisDelete(key)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.