4

Working on a console application, I have a singleton class which contains some generic collections. This collections were previously kept in memory and we are trying to move them to redis using stack exchange redis library.

Base class is:

public class QueueParamDTO
{
    public string Queue { get; set; }
    public int Max { get; set; }
    public int Calls { get; set; }
    public int Holdtime { get; set; }
    public int TalkTime { get; set; }
    public int Completed { get; set; }
    public int Abandoned { get; set; }
    ...
} 

The value of Property Queue of the class is unique so I'm using it to build the key and as for the value is a serialized string of the above object.

RedisSingleton.Connection.GetDatabase().StringSet($"queue:{queueParam.Queue}",JsonConvert.SerializeObject(queueParam));

I'm able to read individual values and deserializing the object. Also retrieve the complete list of keys using a pattern:

var keys = server.Keys(pattern: "queue:*", pageSize: 100);

How can I do the same thing for values, meaning getting the list of values using a specific key pattern as above ?

1 Answer 1

6

By getting first the list of keys I want to retrieve from redis and convert it to an array of RedisKey[]:

RedisKey[] queueKeys = RedisSingleton.Server.Keys(pattern: "queue:*").ToArray();

I'm able to retrieve the list of RedisValue[]:

RedisValue[] queueValues=RedisSingleton.Connection.GetDatabase().StringGet(queueKeys);

In the end I select and deserialize to a list of QueueParamDTO objects:

List<QueueParamDTO> queues = queueValues.Select(qv => JsonConvert.DeserializeObject<QueueParamDTO>(qv)).ToList();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.