-
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 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
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 |
Beta Was this translation helpful? Give feedback.
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