前置:服务器安装redis
1.引用redis
2.使用redis(c#)
一 引用redis (nuget 搜索:CSRedisCore)
二 使用redis(c#)
using System; namespace ConsoleAppRedis { class Program { static void Main(string[] args) { //第一种 var rds = new CSRedis.CSRedisClient("127.0.0.1:6379"); rds.Set("test1", "123123", 60); var str = rds.Get("test1"); Console.WriteLine(str); //第二种 RedisHelper.Initialization(rds); RedisHelper.Set("aaaa", 11111); var str1 = RedisHelper.Get("aaaa"); Console.WriteLine(str1); Console.WriteLine("Hello World!"); Console.ReadKey(); } } }
using System; namespace ConsoleAppRedis { class Program { static void Main(string[] args) { //第一种,无登录密码 //var rds = new CSRedis.CSRedisClient("127.0.0.1:6379"); //rds.Set("test1", "123123", 60); //var str = rds.Get("test1"); //Console.WriteLine(str); //第二种 //RedisHelper.Initialization(rds); //RedisHelper.Set("aaaa", 11111); //var str1 = RedisHelper.Get("aaaa"); //Console.WriteLine(str1); //第三种,有登录密码 var rds2 = new CSRedis.CSRedisClient("127.0.0.1:6379,password=123456,defaultDatabase=13,poolsize=50,ssl=false,writeBuffer=10240,prefix=key前辍"); rds2.Set("test1", "123123", 60); var str3 = rds2.Get("test1"); Console.WriteLine(str3); Console.WriteLine("Hello World!"); Console.ReadKey(); } } }