• StackExchange.Redis的使用


    RedisHelper.cs

    using StackExchange.Redis;
    
    namespace ConsoleApplication2
    {
        //学习使用Nuget配置NewtonJson.dll
        //https://blog.csdn.net/leftfist/article/details/38687745
        //https://blog.csdn.net/ligaofeng/article/details/17371769
    
        // PM> install-package newtonsoft.json
        // PM> Install-Package StackExchange.Redis
        public class RedisHelper
        {
            private static readonly ConfigurationOptions ConfigurationOptions = ConfigurationOptions.Parse("127.0.0.1" + ":" + "6379");
            private static readonly object Locker = new object();
            private static ConnectionMultiplexer _redisConn;
    
            /// <summary>
            /// 单例获取
            /// </summary>
            public static ConnectionMultiplexer RedisConn
            {
                get
                {
                    if (_redisConn == null)
                    {
                        lock (Locker)
                        {
                            if (_redisConn == null || !_redisConn.IsConnected)
                            {
                                _redisConn = ConnectionMultiplexer.Connect(ConfigurationOptions);
                            }
                        }
                    }
                    return _redisConn;
                }
            }
        }
    }

    用法:

            static void Main(string[] args)
            {
                //http://www.cnblogs.com/weixiao520/p/5765358.html
    
                var db = RedisHelper.RedisConn.GetDatabase();
                var key = "keyTest1";
                //SET命令
                db.StringSet(key, "1093939393939393939");
                //GET命令
                var value = db.StringGet(key);
                Console.WriteLine(value);
    
    
                //HMSET
                key = "hashTest";
                db.HashSet(key, new[] { new HashEntry("b", "2"), new HashEntry("c", "3") });
                //HMGET
                var values = db.HashGetAll(key);
                Console.WriteLine(values[0].Name + "///" + values[0].Value);
    
                Console.ReadLine();
            }
       
  • 相关阅读:
    Centos7yum安装LNMP
    CentOS7安装和配置rsync+inotify
    SSH
    nginx https
    nginx rewrite
    nginx代理缓存
    nginx动静分离
    Centos7使用squid实现正向代理
    利用tengine的nginx_upstream_check_module来检测后端服务状态
    nginx基于tcp负载均衡
  • 原文地址:https://www.cnblogs.com/littlehb/p/9185193.html
Copyright © 2020-2023  润新知