I’m trying to set multiple fields of a hash independently and retrieve them all at once later on. Is the code below supposed to work or am doing something wrong here? When I run it locally against redis-2.0.0-x64 on Windows downloaded from the Service Stack site, the result of task3 will always just contains field2.
var con = RedisConnectionManager.Instance.GetConnection();
var key = "somekey1";
// set the field value and expiration
var task = con.Hashes.Set(1, key, "field1", token.ToByteArray())
.ContinueWith((x)=> con.Keys.Expire(1, key, 7200));
task.Wait();
var task2 = con.Hashes.Set(1, key, "field2", "fooobar");
task2.Wait();
var task3 = con.Hashes.GetAll(1, key);
task3.Wait();
Cannot reproduce this on a reasonably current version of redis – looks fine here:
or, more efficiently (uses pipelining, by not waiting):
So yes: should work, and seems to work. Note I’m using 2.4.5 locally; 2.0 is very old now, and has a number of important bugs. It is entirely possible that there was a bug relating to HSET plus EXPIRE at the server – in which case there isn’t much the client library can do to compensate.
I strongly suggest using a more “current” build of redis-server than 2.0. If one isn’t available, you might want to try the dmajkic binaries (goes to 2.4.5), or the [MSOpenTech]*https://github.com/MSOpenTech/redis) source. However!!! This is just for local debugging. For production work at the current time (i.e. until the MSOpenTech code is happy-happy), I would recommend using a linux server to host redis. Ubuntu Server works well.