After the previous Redis basic learning, today officially entered the coding stage, into the coding stage we also face a multiple choice question, what client library to choose? If there is a choice of difficult to choose again to headache. But don't worry about me first headache, today we will introduce you to six .
01、
One of the oldest and best known Redis C#/.NET client libraries, but not the first choice for most people because of its commercial nature.
NET client library is a feature-rich , simple , high-performance C#/.NET client library , the native features and functionality to provide good support , but at the same time do a more advanced functionality of the abstraction , making it easier for simple objects or complex types of serialization operations . Of course, it also provides both synchronous and asynchronous APIs.
Let's write a small, simple example of how to use it:
public static void Run()
{
($" Usage Examples");
// Create a connection pool
var pool = new RedisManagerPool("127.0.0.1:6379");; //Create a connection pool.
// Get a redis instance
using var redis = ();
//Set the key-value pairs
var setResult = ("key1", "value1");
($"Result of the set key-value pair key1/value1 operation: {setResult}");; //Get the value corresponding to the key.
// Get the value corresponding to the key
var value = <string>("key1");
($"Get the value corresponding to the key key1: {value}");;
// Delete the key
var delResult = ("key1"); ($"Get the value corresponding to key1: {value}"); // Delete key.
($"Result of operation to delete key key1: {delResult}"); // Check if the key exists.
// Check if the key exists
var exists = ("key1");
($"Key key1 exists: {exists}"); //Check if key exists.
}
The results of the implementation are as follows:
02、
NET-based , high-performance , free , full-featured , general-purpose old Redis client . And support for Redis multi-node , Redis clusters , IO multiplexing , synchronous/asynchronous dual programming model and other technologies , which also makes its interaction with Redis both flexible and efficient , greatly improving the performance of Redis read and write concurrency.
It also provides a wealth of advanced features , including but not limited to pipelines , connection pooling , transactions , Lua scripting , subscribe/publish and so on. Serialization and compression also provides a variety of ways to choose from , it is very easy to integrate with .
Let's write a small, simple example of how to use it:
public static void Run()
{
($" Usage Example"); // Create an instance of ConnectionMultiplexer.
// Create a ConnectionMultiplexer instance
using var connection = ("127.0.0.1:6379"); // Create an instance of ConnectionMultiplexer.
// Get the Redis database instance
var redis = (); // Set up the key-value pairs.
//Set the key-value pairs
var setResult = ("key1", "value1");
($"Result of the set key-value pair key1/value1 operation: {setResult}");; //Get the value corresponding to the key.
// Get the value corresponding to the key
var value = ("key1");
($"Get the value corresponding to the key key1: {value}");
// Delete the key
var delResult = ("key1");
($"Result of operation to delete key key1: {delResult}"); // Check if the key exists.
// Check if the key exists
var exists = ("key1");
($"Key key1 exists: {exists}"); //Check if key exists.
}
The results of the implementation are as follows:
03、CSRedisCore
CSRedisCore is a national based on the open source project csredis on the implementation of the famous Redis C#/.NET client library . It does all the method names and redis-cli method name consistency. It supports Redis clusters , Redis sentinels and Redis master-slave separation , as well as geo-type , stream-type commands , while supporting synchronous/asynchronous interfaces .
Let's write a small, simple example of how to use it:
public static void Run()
{
($"CSRedisRedis Usage Example");
// Create a CSRedisClient instance
var redis = new CSRedisClient("127.0.0.1:6379"); // Create an instance of CSRedisClient.
// Set the key-value pairs
var setResult = ("key1", "value1");
($"Set key-value pair key1/value1 operation result: {setResult}");;
// Get the value corresponding to the key
var value = ("key1");
($"Get the value corresponding to the key key1: {value}");
// Delete the key
var delResult = ("key1");
($"Result of operation to delete key key1: {delResult}"); // Check if the key exists.
// Check if the key exists
var exists = ("key1");
($"Key key1 exists: {exists}"); //Check if key exists.
}
The results of the implementation are as follows:
04、FreeRedis
FreeRedis is another masterpiece by the author of CSRedisCore. It should also be better than CSRedisCore, at least logically, and it is. FreeRedis has been optimized for memory usage, storage efficiency, and improvements in persistence, fault tolerance, as well as more advanced features and customization options. Let's go straight to the official description.
From the introduction alone, it has the features that CSRedisCore has, and it has the features that CSRedisCore doesn't have. In general, it is more powerful. In addition, CSRedisCore is currently in the maintenance phase has not added new features. Therefore, we recommend FreeRedis.
Let's write a small, simple example of how to use it:
public static void Run()
{
($"FreeRedis Usage Example"); // Create a CSRedisClient instance.
// Create a CSRedisClient instance
var redis = new RedisClient("127.0.0.1:6379"); // Create an instance of CSRedisClient.
// Set the key-value pairs
("key1", "value1");
($"Setting key-value pair key1/value1 operation succeeded");; //Get the value corresponding to the key.
// Get the value corresponding to the key
var value = ("key1");
($"Get the value corresponding to key key1 as: {value}");; // Get the value corresponding to key key1.
// Delete the key
var delResult = ("key1");
($"Result of operation to delete key key1: {delResult}"); // Check if the key exists.
// Check if the key exists
var exists = ("key1");
($"Key key1 exists: {exists}"); //Check if key exists.
}
The results of the implementation are as follows:
05、
It has low latency, high performance, high throughput and good stability and reliability, so it has a good play in the application scenario of a large number of real-time data computing. It is optimized for big data and message queuing , so that it can be used to support an average of 10 billion calls per day , and its connection pool can be done concurrently 100000 connections . Including network communication under the premise of get/set operations can be achieved in an average time of 200 to 600 microseconds. Its binary serialization is also more helpful to improve data storage and reading efficiency.
Let's write a small, simple example of how to use it:
public static void Run()
{
($" Usage Example"); // Create a CSRedisClient instance.
// Create a CSRedisClient instance
var redis = new FullRedis("127.0.0.1:6379", "", 0); // Create an instance of CSRedisClient.
// Set the key-value pairs
var setResult = ("key1", "value1");
($"Set key-value pair key1/value1 operation result: {setResult}");;
// Get the value corresponding to the key
var value = <string>("key1");
($"Get the value corresponding to the key key1: {value}");;
// Delete the key
var delResult = ("key1"); ($"Get the value corresponding to key1: {value}"); // Delete key.
($"Result of operation to delete key key1: {delResult}"); // Check if the key exists.
// Check if the key exists
var exists = ("key1");
($"Key key1 exists: {exists}"); //Check if key exists.
}
The results of the implementation are as follows:
06、。
is a highly available , high-performance , asynchronous non-blocking design of the .net core client library . And basically comprehensive coverage of redis-cli directives , provides a variety of serialization methods , simple and easy to use .
Let's write a small, simple example of how to use it:
public static async Task RunAsync()
{
($" Usage Example"); // Create a CSRedisClient instance.
// Create a CSRedisClient instance
RedisDB redis = new RedisDB(0)
{
DataFormater = new JsonFormater()
}; // Create a CSRedisClient instance.
// Add the write host
("127.0.0.1", 6379); // Add the write host.
// Add the read host
("127.0.0.1", 6379); //Add the read host.
//Set the key-value pair
var setResult = await ("key1", "value1");
($"Setting the key-value pair key1/value1 operation result: {setResult}");
// Get the value corresponding to the key
var value = await <string>("key1");
($"Get the value corresponding to the key key1: {value}");
// Delete the key
var delResult = await ("key1"); ($"Get the value corresponding to key1: {value}"); // Delete key.
($"Delete key key1 result: {delResult}"); // Check if the key exists. var delResult = await ("key1"); var delResult = await ("key1"); // Delete key key1.
// Check if the key exists
var exists = await ("key1");
($"Key key1 exists: {exists}"); //Check if key exists.
}
The results of the implementation are as follows:
07Summary
-
: Comprehensive integrated functionality for users who need business support.
-
: Officially recommended, fully functional, good community support, and well documented.
-
CSRedisCore: Full-featured, easy to use and suitable for rapid development.
-
FreeRedis: High-performance, full-featured, easy to use and suitable for rapid development.
-
: High performance, high concurrency, low latency, distributed scenarios are suitable for use.
-
. : High-availability, high-performance, asynchronous operation for high-load scenarios.
classifier for sums of money: The test method code as well as the sample source code have been uploaded to the code repository for those who are interested./hugogoos/Planner