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 #)