liubiao4123 / servicestack

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

typed client, store operation and how to make object expired? #20

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
 var item = new b
{
    Email = "one@test.com",
    Password = "text",
    FirstName = "Jim Smith",
    Id = 4
};

Console.WriteLine(item.ToValueObject().Dump());
this.GetTypedClient().Store(item.ToValueObject());
this.GetTypedClient().ExpireEntryIn("4", TimeSpan.FromSeconds(20));
var fromCache = this.GetTypedClient().GetById("4");
Console.WriteLine(fromCache.Dump());

where this.GetTypedClient is this

public  IRedisTypedClient<DTOb> GetTypedClient()
{
     return rc.GetTypedClient<DTOb>();
}

so my question - why 

this.GetTypedClient().ExpireEntryIn("4", TimeSpan.FromSeconds(20));

doesn't make entry with id=4 expired in 20 seconds. It seems "Store" method 
doesn't change the behavior regardless of ExpireEntryIn.

please let me know how can I use typed client + store values in redis which 
will be expiring in X seconds?

Original issue reported on code.google.com by dmitrys...@gmail.com on 14 Jul 2010 at 11:07

GoogleCodeExporter commented 8 years ago
Hi 'GetTypedClient<TPocoType>' is only for complex types i.e. POCO's.

When you call 'Store' from a 'GetTypedClient<TPocoType>()' client, then the key 
its stored against is actually 'urn:DTOb:4'. Basically it uses 
'IdUtils.CreateUrn<T>()' to determine the key. 

So the problem is you're not expiring the same key, i.e. '4' != 'urn:DTOb:4'

Now there is a 'IRedisTypedClient<T>.SetEntry(string key, T value, TimeSpan 
expireIn);' where you can specify the key the value is stored against as well 
as expire it in a single call.

I can see why its confusing though, although if the method includes the word 
'Id' in the name (e.g. GetById) then its just expecting the 'Id' field (i.e. 
'4') for all other methods with a 'key' field, its expecting the full key (i.e. 
urn:DTOb:4). 

Hope this helps.
- Demis

Original comment by demis.be...@gmail.com on 14 Jul 2010 at 11:22

GoogleCodeExporter commented 8 years ago
so when I do SetEntry(), key property should be 4 or urn:DTOb:4 ?

Original comment by dmitrys...@gmail.com on 15 Jul 2010 at 2:01

GoogleCodeExporter commented 8 years ago
Actually in that case, the key can be anything you want it to be. By convention 
I would use 'IdUtils.CreateUrn<T>()' to create the key since it is less likely 
to collide with other types that share the same Id value and you should then be 
able to use other methods (i.e. GetById, etc). 

The problem with the current design (that you've highlighted here) is that I've 
left some operations on IRedisTypedClient that are not specifically catered for 
accessing POCO types. 

'IRedisTypedClient<T>.SetEntry(string key, T value, TimeSpan expireIn);'

should really have been:

'IRedisTypedClient<T>.SetEntry(T value, TimeSpan expireIn);'

In which I would've extracted the key automatically for you.

It looks like I'm going to need to go through the 'IRedisTypedClient' interface 
and re-factor the methods to make them all a perfect fit.

- Demis

Original comment by demis.be...@gmail.com on 15 Jul 2010 at 7:35

GoogleCodeExporter commented 8 years ago

Original comment by demis.be...@gmail.com on 28 Aug 2010 at 5:25