I play today with F # and redis. I am using ServiceStack.redis to connect to MSOpenTech redis running on localhost. For testing purposes, I tried to save the price of bitcoin on redis with code like this:
let redis = new RedisClient("localhost") redis.FlushAll() let redisBitstamp = redis.As<BitstampLast>() let last = {Id = redisBitstamp.GetNextSequence(); Timestamp = 1386459953; Value=714.33M} redisBitstamp.Store(last) let allValues = redisBitstamp.GetAll() allValues.PrintDump()
Unfortunately, the result of PrintDump was:
[ { __type: "Program+BitstampLast, RedisSave", Id: 0, Timestamp: 0, Value: 0 } ]
Just for testing, I used almost identical code in C # in the same redis instance:
class BitstampLast { public Int64 Id { get; set; } public int Timestamp { get; set; } public decimal Value { get; set; } } class Program { static void Main(string[] args) { var redis = new RedisClient("localhost"); redis.FlushAll(); var redisBitstamp = redis.As<BitstampLast>(); var last = new BitstampLast() {Id = redisBitstamp.GetNextSequence(), Timestamp = 1386459953, Value=714.33M}; redisBitstamp.Store(last); var allValues = redisBitstamp.GetAll(); allValues.PrintDump(); } }
And the result ...
[ { __type: "CSharpRedis.BitstampLast, CSharpRedis", Id: 1, Timestamp: 1386459953, Value: 714.33 } ]
So what am I missing? Why does it work in C # and not in F #?
EDIT: BitstampLast is defined as follows:
type BitstampLast = {Id:int64; Timestamp:int; Value:decimal}
which is wrong because it should be:
type BitstampLast = {mutable Id:int64; mutable Timestamp:int; mutable Value:decimal}
And now it works. Then the following questions - why should it be volatile? Can redis work with this object?
c # f # servicestack c # -to-f # redis
mlusiak
source share