コード例 #1
0
    public async Task TestScriptEvaluateStoreSet()
    {
        var cacheKey = nameof(TestScriptEvaluateStoreSet).ToLower();

        var set = new Dictionary <long, double>();

        for (long index = 0; index < 64; index++)
        {
            set.Add(index, DateTime.Now.GetTotalMicroseconds());
        }

        _redisProvider.ZAdd(cacheKey, set);

        var scirpt     = @"local workerids = redis.call('ZRANGE', @key, @start,@stop)
                                    redis.call('ZADD',@key,@score,workerids[1])
                                    return workerids[1]";
        var parameters = new { key = cacheKey, start = 0, stop = 0, score = DateTime.Now.GetTotalMicroseconds() };

        var luaResult = (byte[])await _redisProvider.ScriptEvaluateAsync(scirpt, parameters);

        var workerId = _cache.Serializer.Deserialize <long>(luaResult);

        _output.WriteLine(workerId.ToString());
        Assert.True(workerId >= 0);
    }