How do I push integers with lpush
in a redis list type?
I want to test my finagle-redis client if it works correctly and insert manual sample data into redis like this
127.0.0.1:6379> rpush key:214 1 1 1
(integer) 3
127.0.0.1:6379> LRANGE key:214 0 -1
1) "1"
2) "1"
3) "1"
Redis already displays the numbers as char. When I extract them, I also get chars:
val data: List[ChannelBuffer] = Await.result(redisClient.lRange(key, 0, -1))
val buffer: ChannelBuffer = data(0)
buffer.readChar() // 1
buffer.readInt() // 49
Is writing integers to a list possible with the cli client? And if not, will the following even work?
val key = ChannelBuffers.copiedBuffer("listkey", utf8)
val list: List[ChannelBuffer] = List(1,1,1).map { number =>
val buffer = ChannelBuffers.buffer(4) // int sized buffer
buffer.writeInt(number)
buffer
}
// will this store the int's correctly??
redisClient.lpush(key, list)
In redis most everything is a string. This is because of the protocol used. It's text-based, so it's impossible to tell number 1234
from string "1234"
.
It might be storing integers internally, but you'll get strings anyway. You should cast your numbers in the app.