Пример #1
0
        public async Task <string> CatchUp()
        {
            var result = await Client.ReadFrom(Ref);

            Ref = result.Next;
            return(result.Value);
        }
Пример #2
0
        public async Task <ReadResult <string> > ReadFrom(LogRef @ref)
        {
            long offset = @ref.Offset.GetValueOrDefault(0);

            var value = (string)await Redis.StringGetRangeAsync(@ref.Key, offset, -1);

            return(AppendResult.Ok(value, next: @ref.WithOffset(offset + value.Length)));
        }
Пример #3
0
        public async Task <AppendResult> AppendTo(LogRef @ref, string val)
        {
            if (@ref.Offset == null)
            {
                throw new LogException("Can't append using a handle without an offset!");
            }

            await _luaAppend.EnsureLoaded(_redisMultiplexer);

            var newOffset = (long)await Redis.ScriptEvaluateAsync(
                script : _luaAppend.LoadedLuaScript,
                parameters : new { key = (RedisKey)@ref.Key, offset = @ref.Offset, val }
                );

            if (newOffset < 0)
            {
                return(AppendResult.Fail);
            }

            return(AppendResult.Ok(next: @ref.WithOffset(newOffset)));
        }
 public static LogCursor CreateCursor(this LogClient client, LogRef @ref)
 => new LogCursor(client, @ref);
Пример #5
0
        public async Task Write(string value)
        {
            var result = await Client.AppendTo(Ref, value);

            Ref = result.Next;
        }
Пример #6
0
 internal LogCursor(LogClient client, LogRef @ref)
 {
     Client = client;
     Ref    = @ref;
 }