How can I clear all Instances of type X in ServiceStack Redis Client

旧城冷巷雨未停 提交于 2019-12-11 09:09:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!