5、刪除數據
一、void Delete(T entity);刪除函數的運用
- using (var redisClient = RedisManager.GetClient())
- {
- var user = redisClient.GetTypedClient<User>();
- var newUser = new User
- {
- Id = user.GetAll().Count,
- Name = txtName.Text,
- Job = new Job { Position = txtPosition.Text }
- };
- user.Delete(newUser);
-
- }
以上代碼直接刪除了最後一條數據,效果圖以下:
2、void DeleteById(object id);刪除數據函數
- using (var redisClient = RedisManager.GetClient())
- {
- var user = redisClient.GetTypedClient<User>();
-
-
-
-
-
-
-
- user.DeleteById(txtRedisId.Text);
- }
以下圖,刪除了ID等於3的一條數據。
三、void DeleteByIds(IEnumerable ids);批量刪除函數
- using (var redisClient = RedisManager.GetClient())
- {
- var user = redisClient.GetTypedClient<User>();
- user.DeleteByIds((txtRedisId.Text).ToList());
-
- }
以下圖,代碼刪除了ID分別爲:一、二、6的三條數據。
4、void DeleteAll();刪除所有數據
- var user = redisClient.GetTypedClient<User>();
- user.DeleteAll();