qq848420065 / servicestack

Automatically exported from code.google.com/p/servicestack
0 stars 0 forks source link

Why is Set method slower than list.Add() #11

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Please refer the code here: http://pastie.org/986760.

The first loop is calling Redis.Set()...passing string object for value.
In my env its taking 100 msec for each Redis.Set() in the loop.

The second loop is calling list.Add()...and it takes 50 msec for each Add(). 

Why does a Set() call take twice as much time as Add()? The "monitor" command 
shows that each "Set()" call results in "SADD" and "SET" commands...is this 
expected?

I'm using latest version of C# client and Redis Server 1.2.6 running on 
Linux.

Original issue reported on code.google.com by mahesh.p...@gmail.com on 1 Jun 2010 at 3:24

GoogleCodeExporter commented 8 years ago
Hi mahesh,

When using the high-level typed API (i.e. redisClient.GetTypedClient<string>()) 
I do an extra call to 'keep track of the entities'. By maintaining a set 
of ids for each entity I'm able to implement 'GetAll' and 'DeleteAll' that I 
otherwise would not be able to do.

Now there is no reason to use the high-level API if you are just using 'string' 
since the common API IRedisClient provides first class support for 
strings. The high-level 'GetTypedClient' is for providing a convenient 
strong-typed API against complex entities e.g. GetTypedClient<User>().  

So instead of doing:
var redis = redisClient.GetTypedClient<string>();
redis.Set("aaa_" + i, i.ToString());

you should just use the redisClient directly and do:
redisClient.SetEntry("aaa_" + i, i.ToString());

You will still be able to maintain a list of string's:
var redisList = redisClient.Lists["string1"];
redisList.Add(i.ToString());

Original comment by demis.be...@gmail.com on 1 Jun 2010 at 9:07

GoogleCodeExporter commented 8 years ago

Original comment by demis.be...@gmail.com on 11 Aug 2010 at 3:19