Skip to content

Commit

Permalink
Review comment fix, added switch
Browse files Browse the repository at this point in the history
  • Loading branch information
Vijay-Nirmal committed Oct 4, 2024
1 parent dcfcb72 commit 3ef6294
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions libs/server/Storage/Functions/ObjectStore/ReadMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,40 @@ public bool SingleReader(ref byte[] key, ref ObjectInput input, ref IGarnetObjec

if (input.header.type != 0)
{
if (input.header.type == GarnetObjectType.Ttl || input.header.type == GarnetObjectType.PTtl) // TTL command
switch (input.header.type)
{
var ttlValue = input.header.type == GarnetObjectType.Ttl ?
ConvertUtils.SecondsFromDiffUtcNowTicks(value.Expiration > 0 ? value.Expiration : -1) :
ConvertUtils.MillisecondsFromDiffUtcNowTicks(value.Expiration > 0 ? value.Expiration : -1);
CopyRespNumber(ttlValue, ref dst.spanByteAndMemory);
return true;
}
case GarnetObjectType.Ttl:
var ttlValue = ConvertUtils.SecondsFromDiffUtcNowTicks(value.Expiration > 0 ? value.Expiration : -1);
CopyRespNumber(ttlValue, ref dst.spanByteAndMemory);
return true;
case GarnetObjectType.PTtl:
ttlValue = ConvertUtils.MillisecondsFromDiffUtcNowTicks(value.Expiration > 0 ? value.Expiration : -1);
CopyRespNumber(ttlValue, ref dst.spanByteAndMemory);
return true;

if ((byte)input.header.type < CustomCommandManager.StartOffset)
return value.Operate(ref input, ref dst.spanByteAndMemory, out _, out _);
case GarnetObjectType.Expiretime:
var expireTime = ConvertUtils.UnixTimeInSecondsFromTicks(value.Expiration > 0 ? value.Expiration : -1);
CopyRespNumber(expireTime, ref dst.spanByteAndMemory);
return true;
case GarnetObjectType.PExpiretime:
expireTime = ConvertUtils.UnixTimeInMillisecondsFromTicks(value.Expiration > 0 ? value.Expiration : -1);
CopyRespNumber(expireTime, ref dst.spanByteAndMemory);
return true;

if (input.header.type == GarnetObjectType.Expiretime || input.header.type == GarnetObjectType.PExpiretime)
{
var expireTime = input.header.type == GarnetObjectType.Expiretime ?
ConvertUtils.UnixTimeInSecondsFromTicks(value.Expiration > 0 ? value.Expiration : -1) :
ConvertUtils.UnixTimeInMillisecondsFromTicks(value.Expiration > 0 ? value.Expiration : -1);
CopyRespNumber(expireTime, ref dst.spanByteAndMemory);
return true;
}
default:
if ((byte)input.header.type < CustomCommandManager.StartOffset)
return value.Operate(ref input, ref dst.spanByteAndMemory, out _, out _);

if (IncorrectObjectType(ref input, value, ref dst.spanByteAndMemory))
return true;
if (IncorrectObjectType(ref input, value, ref dst.spanByteAndMemory))
return true;

(IMemoryOwner<byte> Memory, int Length) outp = (dst.spanByteAndMemory.Memory, 0);
var customObjectCommand = GetCustomObjectCommand(ref input, input.header.type);
var result = customObjectCommand.Reader(key, ref input, value, ref outp, ref readInfo);
dst.spanByteAndMemory.Memory = outp.Memory;
dst.spanByteAndMemory.Length = outp.Length;
return result;
(IMemoryOwner<byte> Memory, int Length) outp = (dst.spanByteAndMemory.Memory, 0);
var customObjectCommand = GetCustomObjectCommand(ref input, input.header.type);
var result = customObjectCommand.Reader(key, ref input, value, ref outp, ref readInfo);
dst.spanByteAndMemory.Memory = outp.Memory;
dst.spanByteAndMemory.Length = outp.Length;
return result;
}
}

dst.garnetObject = value;
Expand Down

0 comments on commit 3ef6294

Please sign in to comment.