本文介绍了如何清除 ServiceStack Redis 客户端中所有类型为 X 的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从 Redis Db 中清除所有 X 实例以进行测试.但是我找不到 redisClient.As().CLEAR() 方法?如何清除所有 X 实例?
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?
我可以使用
var client=new PooledRedisClientManager(ConfigurationManager.AppSettings["RedisServer"]).GetClient();
X x=new X();
client.As<X>().Store(x);
所有 x 个实例都作为 urn:X:x.id 模式添加到 Db.
all x instances are added to Db as urn:X:x.id pattern.
推荐答案
IRedisTypedClient 实现了通用的 IBasicPersistenceProvider 接口,具有 DeleteAll()
方法.所以你所追求的很简单:
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);
这篇关于如何清除 ServiceStack Redis 客户端中所有类型为 X 的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!