EnyimMemcachedCore 中主要修改的代码如下:
1)OpCode 中添加了
Touch = 0x1C
2)StoreOperation 中添加了
case StoreMode.Touch: op = OpCode.Touch; break;
3)StoreOperationBase 在添加了
case StoreCommand.Touch: sb.Append("touch "); break;
4)MemcachedClient 的 PerformStoreAsync 方法中添加了
if (mode == StoreMode.Touch)
{
value = "";
}
运行 memcached 服务器返回错误 "Invalid arguments (4)"
tcp 抓包情况
请求:
Memcache Protocol, Unknown opcode (28) Request
Magic: Request (128)
Opcode: Unknown (28)
[Expert Info (Warning/Undecoded): Unknown opcode: 28]
[Unknown opcode: 28]
[Severity level: Warning]
[Group: Undecoded]
Key Length: 71
Extras length: 8
Data type: Raw bytes (0)
Reserved: 0
[Value length: 0]
Total body length: 79
Opaque: 2
CAS: 0
Extras
Unknown: 0000011200000014
Key: store_unit_test_636943328034572374_133f5e42-54ce-41e2-bc65-c6a55f2d4d90
响应:
Memcache Protocol, Unknown opcode (28) Response
Magic: Response (129)
Opcode: Unknown (28)
[Expert Info (Warning/Undecoded): Unknown opcode: 28]
[Unknown opcode: 28]
[Severity level: Warning]
[Group: Undecoded]
Key Length: 0
Extras length: 0
Data type: Raw bytes (0)
Status: Invalid arguments (4)
[Expert Info (Note/Response): Unknown opcode (28): Invalid arguments]
[Unknown opcode (28): Invalid arguments]
[Severity level: Note]
[Group: Response]
[Value length: 17]
Total body length: 17
Opaque: 2
CAS: 0
Value: Invalid arguments
请问如何解决?
解决了,不应该基于 StoreOperation 实现,而是要基于 MutatorOperation
在 MutatorOperation.UpdateExtra() 方法中添加了下面的实现代码
if (mode == MutationMode.Touch)
{
Span<byte> extra = stackalloc byte[4];
BinaryPrimitives.WriteUInt32BigEndian(extra, this.expires);
request.Extra = new ArraySegment<byte>(extra.ToArray());
}