Ejemplo n.º 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);
    }
Ejemplo n.º 2
0
        internal async Task <long> GetWorkerIdAsync(string serviceName)
        {
            var workerIdSortedSetCacheKey = string.Format(SharedCachingConsts.WorkerIdSortedSetCacheKey, serviceName);

            var scirpt = @"local workerids = redis.call('ZRANGE', @key, @start,@stop)
                                    redis.call('ZADD',@key,@score,workerids[1])
                                    return workerids[1]";

            var parameters = new { key = workerIdSortedSetCacheKey, start = 0, stop = 0, score = DateTime.Now.GetTotalMilliseconds() };
            var luaResult  = (byte[])await _redisProvider.ScriptEvaluateAsync(scirpt, parameters);

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

            _logger.LogInformation("Get WorkerNodes:{0}", workerId);

            return(workerId);
        }