C # Redis Combat (V)

Source: Internet
Author: User

V. Delete data in 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 Plaincopy
  1. using (var redisclient = redismanager.getclient ())
  2. {
  3. var user = redisclient.gettypedclient<user> ();
  4. var newuser = New User
  5. {
  6. Id = user. GetAll (). Count,
  7. Name = txtName.Text,
  8. Job = New Job {Position = Txtposition.text}
  9. };
  10. User. Delete (NewUser);
  11. }

The above code directly deletes the last piece of data, as follows:
2 , void Deletebyid (object id), delete data function [CSharp]View Plaincopy
  1. using (var redisclient = redismanager.getclient ())
  2. {
  3. var user = redisclient.gettypedclient<user> ();
  4. //var newuser = new User
  5. //{  
  6. //Id = user. GetAll (). Count,
  7. //Name = txtName.Text,
  8. //job = new Job {Position = Txtposition.text}
  9. //};
  10. //user.  Delete (NewUser);
  11. User. Deletebyid (Txtredisid.text); ID value in//txtredisid.text
  12. }
For example, a piece of data with ID equal to 3 is deleted.
3, void Deletebyids (IEnumerable IDs); bulk Delete function [CSharp]View Plaincopy
    1. using (var redisclient = redismanager.getclient ())
    2. {
    3. var user = redisclient.gettypedclient<user> ();
    4. User. Deletebyids ((Txtredisid.text). ToList ()); ID value in//txtredisid.text
    5. }
For example, the code removes three data with IDs: 1, 2, 6, respectively.
4 , void DeleteAll (); Delete all data [CSharp]View Plaincopy
    1. var user = redisclient.gettypedclient<user> ();
    2. User. DeleteAll (); //Delete all data
If you want to reprint, please specify the source, this series of blog sample program

C # Redis Combat (V)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.