Redis Getting Started Tutorial (C #)

Source: Internet
Author: User

What is Redis?

Redis is an open source, Key-value database, written in C, that supports network interaction and can be memory-based and persistent.

Complementary concepts:

Persistence: A mechanism for converting program data between persistent and transient states. In layman's parlance, instantaneous data (such as in-memory data, which cannot be persisted permanently) persists into persistent data (for example, persistent to a database and can be persisted for a long time).

Installation and startup of Redis:

: Https://github.com/MSOpenTech/redis/releases, can choose to download 32-bit or 64-bit as needed

Here I choose the 64-bit installation package:

Then unzip the installation package to the specified directory.

Next is the boot of RDIs, open a CMD command window, enter the extracted Redis directory, run the command "redis-server.exe redis.windows.conf" to start Redis, the following interface:

The following describes the simple use of Redis:

1. Create a new project on vs 2017 where I created the console program;

2. Installing the Servicestack.redis library through the NuGet Manager

3. Create a new test class:

public class Todo    {public        long Id {get; set;}        public string Content {get; set;}        public int Order {get; set;}        public bool-Done {get; set;}    }

4. Test the code as follows, this process cannot close the previous CMD window, otherwise it will not be able to access the server:

static void Main (string[] args) {var redismanger = new Redismanagerpool ("127.0.0.1:6379");                           Redis connection string var Redis = Redismanger.getclient (); Get a redis Client var redistodos = Redis.            As<todo> (); var Newtodo = new Todo//instantiation of a Todo class {Id = REDISTODOS.G            Etnextsequence (), Content = "Learn Redis", Order = 1,};                                    Redistodos.store (Newtodo);               Save the Newtodo instance to the database add Todo Savetodo = Redistodos.getbyid (newtodo.id); Check "Saved Todo: {0}" based on ID query.            Print (Savetodo.dump ());                                         Savetodo.done = true;            Change Redistodos.store (Savetodo);            var Updatetodo = Redistodos.getbyid (newtodo.id); Check "Updated Todo: {0}". Print (Updatetodo.dump ());           Redistodos.deletebyid (newtodo.id);            Remove var Remainingtodos = Redistodos.getall (); "No more Todos:".            Print (Remainingtodos.dump ());        Console.ReadLine (); }

The results of the final operation are as follows:

Redis Getting Started Tutorial (C #)

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.