1

I have list of POCO objects (~80k). I have tried different ways to store these objects in Redis.

Refer to redisClient.StoreAll() at http://docs.servicestack.net/redis-client/redis-client. In order to retrieve all of the stored objects you do redisClient.GetAll(). I would like to know how can i query subset of objects based on a criteria.

Afzi
  • 43
  • 1
  • 4

1 Answers1

0

It's not clear what you mean by querying since data in Redis is typically accessed by key and Redis doesn't have any explicit support for querying values which are effectively opaque to redis.

I recommend reading this previous answer on how you can store related objects in Redis using the ServiceStack.Redis client. Which shows how you can use Indexes to create relationships between types.

If you just want to search through keys you can use Redis Scan APIs, e.g:

var userKeyPattern = IdUtils.CreateUrn<User>("*"); //= urn:User:*
var scanUsers = Redis.ScanAllKeys(userKeyPattern);
//Stop after retrieving 10000 user keys 
var sampleUsers = scanUsers.Take(10000).ToList(); 

But you can't do custom adhoc server-side querying of Redis Values unless you create a custom LUA script to parse the JSON value payload. You would need to create custom indexes for all the relationships you want to maintain otherwise you will need to fetch the results on the client and query them in memory.

Community
  • 1
  • 1
mythz
  • 141,670
  • 29
  • 246
  • 390
  • Thanks for your explanation. May be you can also help me explain Service Stack Redis List implementation. I added my 80K poco objects using the following code: – Afzi Jun 26 '16 at 04:21
  • `var typedClient = client.As();` `typedClient.Lists["securityprojections"].AddRange(items);` Now looks like I was able to query this list using following code: `var results = typedClient.Lists["securityprojections"].Where(w => w.Ticker == "FTS CN").ToList();` First of all it was very fast. Upon verification of the expected results, it turned out that there were too little rows returned i.e. the results were wrong. Could you explain what is happening behind the scenes? – Afzi Jun 26 '16 at 04:32
  • @Afzi please don't put code in comments, if you have a new question ask a new question. You can use `typedClient.Lists["securityprojections"].GetAll()` to fetch all items from a list. – mythz Jun 26 '16 at 12:09