Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 35 additions & 21 deletions Enyim.Caching.Tests/MemcachedClientMutateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,48 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace Enyim.Caching.Tests
{
public class MemcachedClientMutateTests : MemcachedClientTestsBase
{
[Fact]
public void When_Incrementing_Value_Result_Is_Successful()
{
var key = GetUniqueKey("mutate");
var mutateResult = _client.ExecuteIncrement(key, 100, 10);
MutateAssertPass(mutateResult, 100);
public class MemcachedClientMutateTests : MemcachedClientTestsBase
{
[Fact]
public void When_Incrementing_Value_Result_Is_Successful()
{
var key = GetUniqueKey("mutate");
var mutateResult = _client.ExecuteIncrement(key, 100, 10);
MutateAssertPass(mutateResult, 100);

mutateResult = _client.ExecuteIncrement(key, 100, 10);
MutateAssertPass(mutateResult, 110);
}
mutateResult = _client.ExecuteIncrement(key, 100, 10);
MutateAssertPass(mutateResult, 110);
}

[Fact]
public void When_Decrementing_Value_Result_Is_Successful()
{
var key = GetUniqueKey("mutate");
var mutateResult = _client.ExecuteDecrement(key, 100, 10);
MutateAssertPass(mutateResult, 100);
[Fact]
public void When_Decrementing_Value_Result_Is_Successful()
{
var key = GetUniqueKey("mutate");
var mutateResult = _client.ExecuteDecrement(key, 100, 10);
MutateAssertPass(mutateResult, 100);

mutateResult = _client.ExecuteDecrement(key, 100, 10);
MutateAssertPass(mutateResult, 90);
}
}
mutateResult = _client.ExecuteDecrement(key, 100, 10);
MutateAssertPass(mutateResult, 90);
}

[Fact]
public async Task When_Touch_Item_Result_Is_Successful()
{
var key = GetUniqueKey("touch");
await _client.AddAsync(key, "value", 1);
Assert.True((await _client.GetAsync<string>(key)).Success);
var result = await _client.TouchAsync(key, TimeSpan.FromSeconds(60));
await Task.Delay(1010);
Assert.True(result.Success, "Success was false");
Assert.True((result.StatusCode ?? 0) == 0, "StatusCode was not null or 0");
Assert.True((await _client.GetAsync<string>(key)).Success);
}
}
}

#region [ License information ]
Expand Down
5 changes: 4 additions & 1 deletion Enyim.Caching/IMemcachedClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface IMemcachedClient : IDisposable

bool Set(string key, object value, int cacheSeconds);
Task<bool> SetAsync(string key, object value, int cacheSeconds);

bool Replace(string key, object value, int cacheSeconds);
Task<bool> ReplaceAsync(string key, object value, int cacheSeconds);

Expand Down Expand Up @@ -66,6 +66,9 @@ public interface IMemcachedClient : IDisposable
CasResult<ulong> Increment(string key, ulong defaultValue, ulong delta, DateTime expiresAt, ulong cas);
CasResult<ulong> Increment(string key, ulong defaultValue, ulong delta, TimeSpan validFor, ulong cas);

Task<IOperationResult> TouchAsync(string key, DateTime expiresAt);
Task<IOperationResult> TouchAsync(string key, TimeSpan validFor);

bool Remove(string key);
Task<bool> RemoveAsync(string key);

Expand Down
9 changes: 5 additions & 4 deletions Enyim.Caching/Memcached/Enums.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
using Enyim.Caching.Memcached.Protocol.Binary;
using System;

namespace Enyim.Caching.Memcached
{
public enum MutationMode : byte { Increment = 0x05, Decrement = 0x06 };
public enum ConcatenationMode : byte { Append = 0x0E, Prepend = 0x0F };
public enum MemcachedProtocol { Binary, Text }
public enum MutationMode : byte { Increment = 0x05, Decrement = 0x06, Touch = OpCode.Touch };
public enum ConcatenationMode : byte { Append = 0x0E, Prepend = 0x0F };
public enum MemcachedProtocol { Binary, Text }
}

#region [ License information ]
/* ************************************************************
*
* Copyright (c) 2010 Attila Kisk�, enyim.com
* Copyright (c) 2010 Attila Kisk? enyim.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
22 changes: 11 additions & 11 deletions Enyim.Caching/Memcached/IOperationFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@

namespace Enyim.Caching.Memcached
{
public interface IOperationFactory
{
IGetOperation Get(string key);
IMultiGetOperation MultiGet(IList<string> keys);
public interface IOperationFactory
{
IGetOperation Get(string key);
IMultiGetOperation MultiGet(IList<string> keys);

IStoreOperation Store(StoreMode mode, string key, CacheItem value, uint expires, ulong cas);
IDeleteOperation Delete(string key, ulong cas);
IMutatorOperation Mutate(MutationMode mode, string key, ulong defaultValue, ulong delta, uint expires, ulong cas);
IConcatOperation Concat(ConcatenationMode mode, string key, ulong cas, ArraySegment<byte> data);
IStoreOperation Store(StoreMode mode, string key, CacheItem value, uint expires, ulong cas);
IDeleteOperation Delete(string key, ulong cas);
IMutatorOperation Mutate(MutationMode mode, string key, ulong defaultValue, ulong delta, uint expires, ulong cas);
IConcatOperation Concat(ConcatenationMode mode, string key, ulong cas, ArraySegment<byte> data);

IStatsOperation Stats(string type);
IFlushOperation Flush();
}
IStatsOperation Stats(string type);
IFlushOperation Flush();
}
}

#region [ License information ]
Expand Down
1 change: 1 addition & 0 deletions Enyim.Caching/Memcached/MemcachedNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,7 @@ protected virtual async Task<IPooledSocketResult> ExecuteOperationAsync(IOperati
}
else
{
_logger.LogInformation($"{op}.{nameof(op.ReadResponseAsync)} result: {readResult.Message}");
readResult.Combine(result);
}
return result;
Expand Down
66 changes: 33 additions & 33 deletions Enyim.Caching/Memcached/Protocol/Binary/ConcatOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,49 @@

namespace Enyim.Caching.Memcached.Protocol.Binary
{
/// <summary>
/// Implements append/prepend.
/// </summary>
public class ConcatOperation : BinarySingleItemOperation, IConcatOperation
{
private ArraySegment<byte> data;
private ConcatenationMode mode;
/// <summary>
/// Implements append/prepend.
/// </summary>
public class ConcatOperation : BinarySingleItemOperation, IConcatOperation
{
private readonly ArraySegment<byte> data;
private readonly ConcatenationMode mode;

public ConcatOperation(ConcatenationMode mode, string key, ArraySegment<byte> data)
: base(key)
{
this.data = data;
this.mode = mode;
}
public ConcatOperation(ConcatenationMode mode, string key, ArraySegment<byte> data)
: base(key)
{
this.data = data;
this.mode = mode;
}

protected override BinaryRequest Build()
{
var request = new BinaryRequest((OpCode)this.mode)
{
Key = this.Key,
Cas = this.Cas,
Data = this.data
};
protected override BinaryRequest Build()
{
var request = new BinaryRequest((OpCode)this.mode)
{
Key = this.Key,
Cas = this.Cas,
Data = this.data
};

return request;
}
return request;
}

protected override IOperationResult ProcessResponse(BinaryResponse response)
{
return new BinaryOperationResult() { Success = true };
}
protected override IOperationResult ProcessResponse(BinaryResponse response)
{
return new BinaryOperationResult() { Success = true };
}

ConcatenationMode IConcatOperation.Mode
{
get { return this.mode; }
}
}
ConcatenationMode IConcatOperation.Mode
{
get { return this.mode; }
}
}
}

#region [ License information ]
/* ************************************************************
*
* Copyright (c) 2010 Attila Kisk�, enyim.com
* Copyright (c) 2010 Attila Kisk? enyim.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Loading