Skip to content

Commit

Permalink
Merge pull request #449 from momentohq/feat/add-listLength-to-list-mo…
Browse files Browse the repository at this point in the history
…difications
  • Loading branch information
rishtigupta authored Jun 8, 2023
2 parents 076faff + d86cee6 commit b5bbb03
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 16 deletions.
7 changes: 4 additions & 3 deletions src/Momento.Sdk/Internal/ScsDataClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,7 @@ private async Task<CacheListRetainResponse> SendListRetainAsync(string cacheName
return this._logger.LogTraceCollectionRequestError(REQUEST_TYPE_LIST_RETAIN, cacheName, listName, new CacheListRetainResponse.Error(_exceptionMapper.Convert(e, metadata)));
}

return this._logger.LogTraceCollectionRequestSuccess(REQUEST_TYPE_LIST_RETAIN, cacheName, listName, new CacheListRetainResponse.Success());
return this._logger.LogTraceCollectionRequestSuccess(REQUEST_TYPE_LIST_RETAIN, cacheName, listName, new CacheListRetainResponse.Success(response));
}

const string REQUEST_TYPE_LIST_REMOVE_VALUE = "LIST_REMOVE_VALUE";
Expand All @@ -1180,19 +1180,20 @@ private async Task<CacheListRemoveValueResponse> SendListRemoveValueAsync(string
ListName = listName.ToByteString(),
AllElementsWithValue = value
};
_ListRemoveResponse response;
var metadata = MetadataWithCache(cacheName);

try
{
this._logger.LogTraceExecutingCollectionRequest(REQUEST_TYPE_LIST_REMOVE_VALUE, cacheName, listName, value, null);
await this.grpcManager.Client.ListRemoveAsync(request, new CallOptions(headers: MetadataWithCache(cacheName), deadline: CalculateDeadline()));
response = await this.grpcManager.Client.ListRemoveAsync(request, new CallOptions(headers: MetadataWithCache(cacheName), deadline: CalculateDeadline()));
}
catch (Exception e)
{
return this._logger.LogTraceCollectionRequestError(REQUEST_TYPE_LIST_REMOVE_VALUE, cacheName, listName, value, null, new CacheListRemoveValueResponse.Error(_exceptionMapper.Convert(e, metadata)));
}

return this._logger.LogTraceCollectionRequestSuccess(REQUEST_TYPE_LIST_REMOVE_VALUE, cacheName, listName, value, null, new CacheListRemoveValueResponse.Success());
return this._logger.LogTraceCollectionRequestSuccess(REQUEST_TYPE_LIST_REMOVE_VALUE, cacheName, listName, value, null, new CacheListRemoveValueResponse.Success(response));
}

const string REQUEST_TYPE_LIST_LENGTH = "LIST_LENGTH";
Expand Down
9 changes: 8 additions & 1 deletion src/Momento.Sdk/Responses/CacheListFetchResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public class Hit : CacheListFetchResponse
protected readonly Lazy<IList<string>> _stringList;
#pragma warning restore 1591

/// <summary>
/// The length of the list.
/// </summary>
public int ListLength { get; private set; }

/// <summary>
///
/// </summary>
Expand All @@ -66,6 +71,8 @@ public Hit(_ListFetchResponse response)
{
return new List<string>(values.Select(v => v.ToStringUtf8()));
});

ListLength = values.Count;
}

/// <summary>
Expand All @@ -83,7 +90,7 @@ public override string ToString()
{
var stringRepresentation = String.Join(", ", ValueListString.Select(value => $"\"{value}\""));
var byteArrayRepresentation = String.Join(", ", ValueListByteArray.Select(value => $"\"{value.ToPrettyHexString()}\""));
return $"{base.ToString()}: ValueListString: [{stringRepresentation.Truncate()}] ValueListByteArray: [{byteArrayRepresentation.Truncate()}]";
return $"{base.ToString()}: ValueListString: [{stringRepresentation.Truncate()}] ValueListByteArray: [{byteArrayRepresentation.Truncate()}] ListLength: {ListLength}";
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/Momento.Sdk/Responses/CacheListPopBackResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,19 @@ public class Hit : CacheListPopBackResponse
protected readonly ByteString value;
#pragma warning restore 1591

/// <summary>
/// The length of the list post-pop (and post-truncate, if that applies).
/// </summary>
public int ListLength { get; private set; }

/// <summary>
///
/// </summary>
/// <param name="response">The cache response.</param>
public Hit(_ListPopBackResponse response)
{
this.value = response.Found.Back;
ListLength = checked((int)response.Found.ListLength);
}

/// <summary>
Expand All @@ -69,7 +75,7 @@ public byte[] ValueByteArray
/// <inheritdoc />
public override string ToString()
{
return $"{base.ToString()}: ValueString: \"{ValueString.Truncate()}\" ValueByteArray: \"{ValueByteArray.ToPrettyHexString().Truncate()}\"";
return $"{base.ToString()}: ValueString: \"{ValueString.Truncate()}\" ValueByteArray: \"{ValueByteArray.ToPrettyHexString().Truncate()}\" ListLength: {ListLength}";
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/Momento.Sdk/Responses/CacheListPopFrontResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,19 @@ public class Hit : CacheListPopFrontResponse
protected readonly ByteString value;
#pragma warning restore 1591

/// <summary>
/// The length of the list post-pop (and post-truncate, if that applies).
/// </summary>
public int ListLength { get; private set; }

/// <summary>
///
/// </summary>
/// <param name="response">The cache response</param>
public Hit(_ListPopFrontResponse response)
{
this.value = response.Found.Front;
ListLength = checked((int)response.Found.ListLength);
}

/// <summary>
Expand All @@ -69,7 +75,7 @@ public byte[] ValueByteArray
/// <inheritdoc />
public override string ToString()
{
return $"{base.ToString()}: ValueString: \"{ValueString.Truncate()}\" ValueByteArray: \"{ValueByteArray.ToPrettyHexString().Truncate()}\"";
return $"{base.ToString()}: ValueString: \"{ValueString.Truncate()}\" ValueByteArray: \"{ValueByteArray.ToPrettyHexString().Truncate()}\" ListLength: {ListLength}";
}
}

Expand Down
24 changes: 23 additions & 1 deletion src/Momento.Sdk/Responses/CacheListRemoveValueResponse.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Momento.Sdk.Exceptions;
using Momento.Protos.CacheClient;
using Momento.Sdk.Exceptions;

namespace Momento.Sdk.Responses;

Expand Down Expand Up @@ -32,6 +33,27 @@ public abstract class CacheListRemoveValueResponse
/// <include file="../docs.xml" path='docs/class[@name="Success"]/description/*' />
public class Success : CacheListRemoveValueResponse
{
/// <summary>
/// The length of the list post-remove operation.
/// </summary>
public int ListLength { get; private set; }

/// <summary>
///
/// </summary>
/// <param name="response">The cache response</param>
public Success(_ListRemoveResponse response)
{
if (response.ListCase == _ListRemoveResponse.ListOneofCase.Found) {
ListLength = checked((int)response.Found.ListLength);
}
}

/// <inheritdoc />
public override string ToString()
{
return $"{base.ToString()}: ListLength: {ListLength}";
}
}

/// <include file="../docs.xml" path='docs/class[@name="Error"]/description/*' />
Expand Down
22 changes: 21 additions & 1 deletion src/Momento.Sdk/Responses/CacheListRetainResponse.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Momento.Sdk.Exceptions;
using Momento.Protos.CacheClient;
using Momento.Sdk.Exceptions;

namespace Momento.Sdk.Responses;

Expand Down Expand Up @@ -32,6 +33,25 @@ public abstract class CacheListRetainResponse
/// <include file="../docs.xml" path='docs/class[@name="Success"]/description/*' />
public class Success : CacheListRetainResponse
{
/// <summary>
/// The length of the list post-retain operation.
/// </summary>
public int ListLength { get; private set; }

/// <summary>
///
/// </summary>
/// <param name="response">The cache response</param>
public Success(_ListRetainResponse response)
{
ListLength = checked((int)response.Found.ListLength);
}

/// <inheritdoc />
public override string ToString()
{
return $"{base.ToString()}: ListLength: {ListLength}";
}
}

/// <include file="../docs.xml" path='docs/class[@name="Error"]/description/*' />
Expand Down
Loading

0 comments on commit b5bbb03

Please sign in to comment.