Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SortedSetCount to IGarnetApi #979

Closed
badrishc opened this issue Jan 30, 2025 · 0 comments · Fixed by #978
Closed

Add SortedSetCount to IGarnetApi #979

badrishc opened this issue Jan 30, 2025 · 0 comments · Fixed by #978
Assignees

Comments

@badrishc
Copy link
Collaborator

Discussed in #967

Originally posted by solanpaa January 28, 2025
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 ObjectInput and GarnetObjectStoreOutput are used within the codebase, but most uses seem to rely on internal-only functionalities. Would appreciate some pointers on how to use these in my own extensions

@badrishc badrishc self-assigned this Jan 30, 2025
@badrishc badrishc changed the title Add SortedSetCount to IGarnetAPI Add SortedSetCount to IGarnetApi Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant