Abhijay Ghildyal Abhijay Ghildyal - 1 year ago 72
R Question

R library rredis during 'hset' appends spurious string

I am storing a hash to key value using rredis as follows :



redisConnect(host=redishost[1], port=as.numeric(redishost[2]))

toStore <- "asdf"
redisHSet(key='simulatorinput', field = "asdf", value = toStore, NX=F)
redisHGet(key = 'simulatorinput', field = "asdf")

When I check my input in redis I get the following output:> HGET simulatorinput asdf

but, when I check my input to redis from R using

> redisHGet(key = 'simulatorinput', field = "asdf")
[1] "asdf"

Can somebody tell me the reason why this is happening? How can I avoid this from happening?

Answer Source

rredis pdf manual (p. 28) says the following:

In order to store strings that can easily be read by other clients, first convert the character object using the charToRaw function as shown in the examples.

toStore <- "asdf"
redisHSet(key='simulatorinput', field = "asdf", value = charToRaw(toStore), NX=F)
redisHGet(key = 'simulatorinput', field = "asdf")
[1] "asdf"
attr(,"redis string value")
[1] TRUE

From redis client:

redis> HGETALL simulatorinput
1) "asdf"
2) "asdf"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download