bwlewis / rredis

R client for Redis
http://illposed.net/
93 stars 25 forks source link

strange characters set by R #12

Closed caccio closed 11 years ago

caccio commented 11 years ago

Using redis to exchange data between multiple clients I found problems setting a value in R (using rredis) and reading it back from the redis client or from node: the value I get back is not the one I put in, but a string of "strange characters". It works perfectly only if I get the value back in R or if I read a value stored by the redis client.

1) In R

> library(rredis)
> redisConnect(timeout=300)
> redisSet('x',10)
[1] "OK"
> redisGet('x')
[1] 10

2) In redis-cli

redis 127.0.0.1:6379> get x
"X\n\x00\x00\x00\x02\x00\x03\x00\x00\x00\x02\x03\x00\x00\x00\x00\x0e\x00\x00\x00\x01@$\x00\x00\x00\x00\x00\x00"
redis 127.0.0.1:6379> set x 5
OK

3) In R

> redisGet('x')
[1] "5"

I get the same results using rredis 1.6.7 either with R 3.0.0-64bit (on OSX 10.8) and R 2.15.2-64bit (on Windows 7). Redis version is 2.6.12 (on OSX 10.8), but I tried also with a free redis on-line service.

bwlewis commented 11 years ago

rredis stores serialized R objects by default. You have two options:

  1. Parse the serialized R object on the other client.
  2. Store R values in a form that can be understood by the other cilent, for example as ASCII strings.

These options are discussed in the vignette, and in the help examples, for example see the 2nd example in the help page for redisSet.