How to set IGarnetApi's args and read output? #967
Answered
by
badrishc
Janne Solanpää (solanpaa)
asked this question in
Q&A
|
Hi, I'm developing custom transactions for our use case. There I need to call, e.g., IGarnetApi.SortedSetCount. How do I set the input and read the output? Minimum example of my issue using Garnet.common;
using Garnet.server;
using Tsavorite.core;
namespace Garnet {
public class MyTx : CustomTransactionProcedure
{
public override bool Prepare<TGarnetReadApi>(TGarnetReadApi api, ref CustomProcedureInput input) {
int offset = 0;
// Lock the key for exclusive access
AddKey(GetNextArg(ref input, ref offset), LockType.Exclusive, true);
return true;
}
public override void Main<TGarnetApi>(TGarnetApi api, ref CustomProcedureInput input, ref MemoryResult<byte> output)
{
int offset = 0;
var key = GetNextArg(ref input, ref offset);
var minScore = GetNextArg(ref input, ref offset);
var maxScore = GetNextArg(ref input, ref offset);
var keyBytes = key.ToArray();
//
// HELP: How to set zcountInput to correspond to 'minScore maxScore'?
//
ObjectInput zcountInput = new ObjectInput();
GarnetObjectStoreOutput zcountOutput = new GarnetObjectStoreOutput();
var status = api.SortedSetCount(keyBytes, ref zcountInput, ref zcountOutput);
//
// HELP: How to read count from zcountOutput?
//
int countOutput = 0; // <- ??
var myCalculation = countOutput + 1;
WriteSimpleString(ref output, myCalculation.ToString());
}
}
}I tried looking up different ways |
Answered by
badrishc
Jan 30, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We have not added all APIs to IGarnetApi. In this PR, I added SortedSetCount and showed how to use it in a sample custom transaction: #978