I'm evaluating redis, and an trying to use a lua script to get multiple hash keys from redis in one call.
I can't seem to get it to work. The code below returns an array of items to my c# code, but I can't seem to get at the hash results. the redisResult returned is an array and each element of the array is an empty array. I expected each element to be an array of the hash values.
int key1 = 1;
var sb = new StringBuilder();
var compositeKeys = new List<RedisKey>();
for (int key2 = 1; key2 < 1000; key2++)
{
compositeKeys.Add((RedisKey)GetRedisKey2(key1, key2));
}
sb.AppendLine("local collate = function(key)");
sb.AppendLine("local raw_data = redis.call('HGETALL', key)");
sb.AppendLine("local data = {}");
sb.AppendLine("for idx = 1, #raw_data, 2 do");
sb.AppendLine(" data[raw_data[idx]] = raw_data[idx + 1]");
sb.AppendLine("end");
sb.AppendLine("return data;");
sb.AppendLine("end");
sb.AppendLine("local data = {}");
sb.AppendLine("for _, key in pairs(KEYS) do");
sb.AppendLine(" data[_] = collate(key)");
sb.AppendLine("end");
sb.AppendLine("return data");
var results = _redDb.ScriptEvaluate(sb.ToString(), compositeKeys.ToArray());
EDIT: to better explain what I'm trying to do: This will be used for looking up stock market data, and there are three use cases for getting the data out of the cache.
- Get a single item by symbol and time
- Get a range of historical data for a single symbol
- Get a range of symbols from specific time
Each data point has about 30 fields of data about the stock at that time. I am storing it using a key that combine the symbol and time, and hash fields for each field in my object. The performance I am receiving for a single stock lookup is great, but I am having trouble with looking up a range of values.
I implemented the pipelined approach described in this question: StackExchange.Redis: Batch access for multiple hashes. The performance is OK, but not better than what I get today out of SQL Server. I'd like to benchmark the performance using the LUA scripting approach, but I must be doing something wrong.