1

I have a sorted set in Redis where I store the userid and last login timestamp.

Adding to sorted set (using below code) works like a charm using StackExchange.Redis for C# and I can see the values added in redis-cli.

IDatabase rdb = redis.GetDatabase();
rdb.SortedSetAdd("LOGINS", "userid:timestamp", 0.0, CommandFlags.None);

I now need to query Redis DB to get last login timestamp for a userid.

In redis-cli, I can run below query to get the last login timestamp for a userid:

zrevrangebylex LOGINS "[userid\xff" [userid LIMIT 0 1

However, I did not find a way to run this command in either StackExchange.Redis or ServiceStack.Redis to do lexicographic search in reverse order.

How to run above redis-cli query in C#?

kayess
  • 3,384
  • 9
  • 28
  • 45
user2107373
  • 427
  • 3
  • 16

1 Answers1

2

Simply: that command appears to have been omitted. I'll add a github issue for the next deploy. For now, you could use Lua (ScriptEvaluate) to invoke it (ungainly, but it should work).

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • Thanks Marc for adding github issue for this and suggesting a workaround. For others having this issue, this is the how we can call Lua using StackExchange.Redis `const string script = "return redis.call('zrevrangebylex', 'LOGINS', '[0301861887\xff', '[0301861887', 'LIMIT', '0', '1')"; var prepared = LuaScript.Prepare(script); var result = (string[])db.ScriptEvaluate(prepared); foreach (var res in result) Console.WriteLine(res);` – user2107373 Dec 09 '15 at 05:38