Abhijay Ghildyal Abhijay Ghildyal - 1 month ago 5x
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?


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"