There is a command, which works perfectly at my Redis Azure Cache "redis-cli" prompt (an Enterprise E10 instance with the TimeSeries module enabled):
EVAL "redis.call('TS.ADD', KEYS[1], '*', ARGV[1], 'RETENTION', ARGV[2], 'ON_DUPLICATE', 'SUM', 'ENCODING', 'UNCOMPRESSED'); return redis.call('TS.RANGE', KEYS[1], '-', '+')" 1 key1 1 1800000
1) 1) (integer) 1693323424958
2) 1
2) 1) (integer) 1693323485951
2) 1
3) 1) (integer) 1693323528702
2) 1
4) 1) (integer) 1693323531678
2) 1
As you can see, I have called it 4 times, which has added 4 timestamps, all with the value 1 to the "key1" time series.
However, when I try to call the same command in a simple C# .Net console app:
private static readonly TimeSpan RETENTION_TIME = TimeSpan.FromMinutes(30);
private const string LUA_SCRIPT = @"redis.call('TS.ADD', KEYS[1], '*', ARGV[1], 'RETENTION', ARGV[2], 'ON_DUPLICATE', 'SUM', 'ENCODING', 'UNCOMPRESSED'); return redis.call('TS.RANGE', KEYS[1], '-', '+')";
private static async Task<int> AddTimestampReturnSumAsync(IDatabase db, string key, int retentionTime)
{
RedisResult result = await db.ScriptEvaluateAsync(LUA_CMD, new RedisKey[] { key }, new RedisValue[] { retentionTime });
Console.WriteLine(JsonSerializer.Serialize(result));
return 0; // a placeholder, I actually want to return a sum of the values
}
Then the following line:
int sum = await AddTimestampReturnSumAsync(redis.GetDatabase(), "key1", (int)RETENTION_TIME.TotalMilliseconds);
fails with
StackExchange.Redis.RedisServerException: 'ERR Error running script (call to f_503fcb14af1e60051a54d3617d5265f753dfe423): @user_script:1: @user_script: 1: Lua redis() command arguments must be strings or integers'
Trying to debug the issue, I have tried the following 2 strings and they just work as expected:
private const string LUA_SCRIPT = @"return KEYS[1]"; // returns a RedisResult with "key1"
private const string LUA_SCRIPT = @"return ARGV[1]"; // returns a RedisResult with 1800000
Is the issue maybe in the Lua code?
I am just trying to call TS.ADD
and the TS.RANGE
as a single atomic unit from my C# app.
Currently, I am studing the ScriptingTests.cs trying to understand what is different with my code...