richfitz / redux

@@ -5,9 +5,17 @@
Loading
5 5
char * string_duplicate(const char * x);
6 6
7 7
// API functions first:
8 -
SEXP redux_redis_connect(SEXP host, SEXP port) {
9 -
  redisContext *context = redisConnect(CHAR(STRING_ELT(host, 0)),
10 -
                                       INTEGER(port)[0]);
8 +
SEXP redux_redis_connect(SEXP r_host, SEXP r_port, SEXP r_timeout) {
9 +
  redisContext *context;
10 +
  const char * host = CHAR(STRING_ELT(r_host, 0));
11 +
  const int port = INTEGER(r_port)[0];
12 +
  if (LENGTH(r_timeout) == 0) {
13 +
    context = redisConnect(host, port);
14 +
  } else {
15 +
    int timeout = INTEGER(r_timeout)[0];
16 +
    struct timeval tvout = {timeout / 1000, (timeout % 1000) * 1000};
17 +
    context = redisConnectWithTimeout(host, port, tvout);
18 +
  }
11 19
  if (context == NULL) {
12 20
    error("Creating context failed catastrophically [tcp]"); // # nocov
13 21
  }
@@ -16,14 +24,22 @@
Loading
16 24
    redisFree(context);
17 25
    error("Failed to create context: %s", errstr);
18 26
  }
19 -
  SEXP extPtr = PROTECT(R_MakeExternalPtr(context, host, R_NilValue));
27 +
  SEXP extPtr = PROTECT(R_MakeExternalPtr(context, r_host, R_NilValue));
20 28
  R_RegisterCFinalizer(extPtr, redis_finalize);
21 29
  UNPROTECT(1);
22 30
  return extPtr;
23 31
}
24 32
25 -
SEXP redux_redis_connect_unix(SEXP path) {
26 -
  redisContext *context = redisConnectUnix(CHAR(STRING_ELT(path, 0)));
33 +
SEXP redux_redis_connect_unix(SEXP r_path, SEXP r_timeout) {
34 +
  redisContext *context;
35 +
  const char * path = CHAR(STRING_ELT(r_path, 0));
36 +
  if (LENGTH(r_timeout) == 0) {
37 +
    context = redisConnectUnix(path);
38 +
  } else {
39 +
    int timeout = INTEGER(r_timeout)[0];
40 +
    struct timeval tvout = {timeout / 1000, (timeout % 1000) * 1000};
41 +
    context = redisConnectUnixWithTimeout(path, tvout);
42 +
  }
27 43
  if (context == NULL) {
28 44
    error("Creating context failed catastrophically [unix]"); // # nocov
29 45
  }
@@ -32,7 +48,7 @@
Loading
32 48
    redisFree(context);
33 49
    error("Failed to create context: %s", errstr);
34 50
  }
35 -
  SEXP extPtr = PROTECT(R_MakeExternalPtr(context, path, R_NilValue));
51 +
  SEXP extPtr = PROTECT(R_MakeExternalPtr(context, r_path, R_NilValue));
36 52
  R_RegisterCFinalizer(extPtr, redis_finalize);
37 53
  UNPROTECT(1);
38 54
  return extPtr;

@@ -8,8 +8,8 @@
Loading
8 8
#include <Rversion.h>
9 9
10 10
static const R_CallMethodDef callMethods[] = {
11 -
  {"Credux_redis_connect",       (DL_FUNC) &redux_redis_connect,        2},
12 -
  {"Credux_redis_connect_unix",  (DL_FUNC) &redux_redis_connect_unix,   1},
11 +
  {"Credux_redis_connect",       (DL_FUNC) &redux_redis_connect,        3},
12 +
  {"Credux_redis_connect_unix",  (DL_FUNC) &redux_redis_connect_unix,   2},
13 13
14 14
  {"Credux_redis_command",       (DL_FUNC) &redux_redis_command,        2},
15 15

@@ -4,9 +4,9 @@
Loading
4 4
## from user code; see the functions in connection.R for what to use.
5 5
redis_connect <- function(config) {
6 6
  if (config$scheme == "redis") {
7 -
    ptr <- redis_connect_tcp(config$host, config$port)
7 +
    ptr <- redis_connect_tcp(config$host, config$port, config$timeout)
8 8
  } else {
9 -
    ptr <- redis_connect_unix(config$path)
9 +
    ptr <- redis_connect_unix(config$path, config$timeout)
10 10
  }
11 11
  if (!is.null(config$password)) {
12 12
    redis_command(ptr, c("AUTH", config$password))
@@ -17,12 +17,12 @@
Loading
17 17
  ptr
18 18
}
19 19
20 -
redis_connect_tcp <- function(host, port) {
21 -
  .Call(Credux_redis_connect, host, as.integer(port))
20 +
redis_connect_tcp <- function(host, port, timeout = NULL) {
21 +
  .Call(Credux_redis_connect, host, as.integer(port), as.integer(timeout))
22 22
}
23 23
24 -
redis_connect_unix <- function(path) {
25 -
  .Call(Credux_redis_connect_unix, path)
24 +
redis_connect_unix <- function(path, timeout = NULL) {
25 +
  .Call(Credux_redis_connect_unix, path, as.integer(timeout))
26 26
}
27 27
28 28
redis_command <- function(ptr, command) {

@@ -23,6 +23,9 @@
Loading
23 23
##' \code{SELECT}.  Do not use in a redis clustering context.
24 24
##' (default: \code{NULL}; i.e., don't switch).}
25 25
##'
26 +
##' \item{\code{timeout}}{The maximum number of milliseconds to wait for the
27 +
##' connection to be established.  (default: \code{NULL}; i.e. wait forever).}
28 +
##'
26 29
##' }
27 30
##'
28 31
##' The way that configuration options are resolved follows the design
@@ -70,7 +73,8 @@
Loading
70 73
                port = as.integer(Sys_getenv("REDIS_PORT", 6379L)),
71 74
                path = NULL,
72 75
                password = NULL,
73 -
                db = NULL)
76 +
                db = NULL,
77 +
                timeout = NULL)
74 78
  dots <- list(...)
75 79
  if (length(dots) > 0L && !identical(dots, config)) {
76 80
    warning("Ignoring dots in favour of config")
Files Coverage
R 100.00%
src 100.00%
Project Totals (18 files) 100.00%

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading