V. Deletion of dataIn C # Redis Combat (iv), which describes how to write Key-value data in Redis, this article explains how to delete data from Redis.
1. Void Delete (T entity) and the use of delete function
[CSharp]View Plain copy
- 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);
- }
the above code directly deletes the last piece of data, as follows:
2
. void Deletebyid (object id); Delete data function
[CSharp]View Plain copy
- 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);
- User. Deletebyid (Txtredisid.text); ID value in//txtredisid.text
- }
For example, a piece of data with ID equal to 3 is deleted.
3, void Deletebyids (IEnumerable IDs); bulk Delete function
[CSharp]View Plain copy
- using (var redisclient = redismanager.getclient ())
- {
- var user = redisclient.gettypedclient<user> ();
- User. Deletebyids ((Txtredisid.text). ToList ()); ID value in//txtredisid.text
- }
For example, the code removes three data with IDs: 1, 2, 6, respectively.
4
, void DeleteAll (); Delete all data
[CSharp]View Plain copy
- var user = redisclient.gettypedclient<user> ();
- User. DeleteAll (); //Delete all data
C # Redis Combat (V)