-
Notifications
You must be signed in to change notification settings - Fork 520
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into users/padgupta/add_flag_to_control_tlscheck
- Loading branch information
Showing
33 changed files
with
593 additions
and
1,629 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
libs/client/GarnetClientAPI/GarnetClientListCommands.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace Garnet.client | ||
{ | ||
public sealed partial class GarnetClient | ||
{ | ||
private static readonly Memory<byte> LPUSH = "$5\r\nLPUSH\r\n"u8.ToArray(); | ||
private static readonly Memory<byte> RPUSH = "$5\r\nRPUSH\r\n"u8.ToArray(); | ||
|
||
/// <summary> | ||
/// Add the specified element to the head of the list stored at key | ||
/// </summary> | ||
/// <param name="key">The key of the list</param> | ||
/// <param name="element">The element to be added</param> | ||
/// <param name="callback">The callback function when operation completes</param> | ||
/// <param name="context">An optional context to correlate request to callback</param> | ||
public void ListLeftPush(string key, string element, Action<long, long, string> callback, long context = 0) | ||
{ | ||
ListLeftPush(key, new[] { element }, callback, context); | ||
} | ||
|
||
/// <summary> | ||
/// Add the specified elements to the head of the list stored at key | ||
/// </summary> | ||
/// <param name="key">The key of the list</param> | ||
/// <param name="elements">The elements to be added</param> | ||
/// <param name="callback">The callback function when operation completes</param> | ||
/// <param name="context">An optional context to correlate request to callback</param> | ||
public void ListLeftPush(string key, IEnumerable<string> elements, Action<long, long, string> callback, long context = 0) | ||
{ | ||
ArgumentNullException.ThrowIfNull(key); | ||
ArgumentNullException.ThrowIfNull(elements); | ||
ArgumentNullException.ThrowIfNull(callback); | ||
|
||
var arrElem = new[] { key }.Union(elements).ToArray(); | ||
|
||
if (arrElem.Length == 1) | ||
{ | ||
throw new ArgumentException("Elements collection cannot be empty.", nameof(elements)); | ||
} | ||
|
||
ExecuteForLongResult(callback, context, nameof(LPUSH), arrElem); | ||
} | ||
|
||
/// <summary> | ||
/// Asynchronously add the specified elements to the head of the list stored at key | ||
/// </summary> | ||
/// <param name="key">The key of the list</param> | ||
/// <param name="elements">The elements to be added</param> | ||
/// <returns>The number of list elements after the addition</returns> | ||
public async Task<long> ListLeftPushAsync(string key, params string[] elements) | ||
{ | ||
ArgumentNullException.ThrowIfNull(key); | ||
ArgumentNullException.ThrowIfNull(elements); | ||
|
||
if (elements.Length == 0) | ||
{ | ||
throw new ArgumentException("Elements collection cannot be empty.", nameof(elements)); | ||
} | ||
|
||
return await ExecuteForLongResultAsync(nameof(LPUSH), [key, .. elements]); | ||
} | ||
|
||
/// <summary> | ||
/// Add the specified element to the tail of the list stored at key | ||
/// </summary> | ||
/// <param name="key">The key of the list</param> | ||
/// <param name="element">The element to be added</param> | ||
/// <param name="callback">The callback function when operation completes</param> | ||
/// <param name="context">An optional context to correlate request to callback</param> | ||
public void ListRightPush(string key, string element, Action<long, long, string> callback, long context = 0) | ||
{ | ||
ListRightPush(key, new[] { element }, callback, context); | ||
} | ||
|
||
/// <summary> | ||
/// Add the specified elements to the tail of the list stored at key | ||
/// </summary> | ||
/// <param name="key">The key of the list</param> | ||
/// <param name="elements">The elements to be added</param> | ||
/// <param name="callback">The callback function when operation completes</param> | ||
/// <param name="context">An optional context to correlate request to callback</param> | ||
public void ListRightPush(string key, IEnumerable<string> elements, Action<long, long, string> callback, long context = 0) | ||
{ | ||
ArgumentNullException.ThrowIfNull(key); | ||
ArgumentNullException.ThrowIfNull(elements); | ||
ArgumentNullException.ThrowIfNull(callback); | ||
|
||
var arrElem = new[] { key }.Union(elements).ToArray(); | ||
|
||
if (arrElem.Length == 1) | ||
{ | ||
throw new ArgumentException("Elements collection cannot be empty.", nameof(elements)); | ||
} | ||
|
||
ExecuteForLongResult(callback, context, nameof(RPUSH), arrElem); | ||
} | ||
|
||
/// <summary> | ||
/// Asynchronously add the specified elements to the tail of the list stored at key | ||
/// </summary> | ||
/// <param name="key">The key of the list</param> | ||
/// <param name="elements">The elements to be added</param> | ||
/// <returns>The number of list elements after the addition</returns> | ||
public async Task<long> ListRightPushAsync(string key, params string[] elements) | ||
{ | ||
ArgumentNullException.ThrowIfNull(key); | ||
ArgumentNullException.ThrowIfNull(elements); | ||
|
||
if (elements.Length == 0) | ||
{ | ||
throw new ArgumentException("Elements collection cannot be empty.", nameof(elements)); | ||
} | ||
|
||
return await ExecuteForLongResultAsync(nameof(RPUSH), [key, .. elements]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.