问题
I want to clear all X instance from Redis Db for testing. But I could not find redisClient.As().CLEAR() method? How can I clear all X instance?
I can add X Instances using
var client=new PooledRedisClientManager(ConfigurationManager.AppSettings["RedisServer"]).GetClient();
X x=new X();
client.As<X>().Store(x);
all x instances are added to Db as urn:X:x.id pattern.
回答1:
The IRedisTypedClient implements the generic IBasicPersistenceProvider<T> interface which has a DeleteAll()
method. So what you're after is simply:
client.As<T>().DeleteAll();
For more fine-grained deletion options you also have:
client.As<T>().DeleteById(id);
client.As<T>().DeleteByIds(ids);
回答2:
If you are using the RedisNativeClient class you have this method to delete a specific key:
public int Del(string key)
if you want to delete all keys you can call Del with * as key
and you have those methods as well:
public void FlushDb()
public void FlushAll()
if you are using the RedisClient class you have this method:
public bool Remove(string key) // Again i guess you can use the * for delete all keys
回答3:
client.As().DeleteAll();
I think naming "Remove" is for relations.
User.Cars.Remove("Red Car")
If you want to delete object "Delete" :)
Delete("Red Car")
It does not work. I'm getting weird {"wrong number of arguments for 'del' command, sPort: 19570, LastCommand: "} error.
来源:https://stackoverflow.com/questions/10790385/how-can-i-clear-all-instances-of-type-x-in-servicestack-redis-client