Ubuntu腾讯云主机安装分布式memcache服务器,C#中连接云主机进行存储的示例

news/2024/7/7 14:38:46

Ubuntu腾讯云主机安装分布式memcache服务器,C#中连接云主机进行存储的示例(github代码:https://github.com/qq719862911/MemcacheTestDemo)

1、腾讯云安装memcache服务器,并且启动服务器。

1)安装Memcache服务端 

sudo apt-get install memcached 

安装完Memcache服务端以后,我们需要启动该服务: 

memcached -d -m 128 -p 11111 -u root 


这里需要说明一下memcached服务的启动参数: 

-p 监听的端口 
-l 连接的IP地址, 默认是本机 
-d start 启动memcached服务 
-d restart 重起memcached服务 
-d stop|shutdown 关闭正在运行的memcached服务 
-d install 安装memcached服务 
-d uninstall 卸载memcached服务 
-u 以的身份运行 (仅在以root运行的时候有效) 
-m 最大内存使用,单位MB。默认64MB 
-M 内存耗尽时返回错误,而不是删除项 
-c 最大同时连接数,默认是1024 
-f 块大小增长因子,默认是1.25-n 最小分配空间,key+value+flags默认是48 
-h 显示帮助 

 

2、C#中连接云memcache的存储数据。

1)Nuget安装 : EnyimMemcached  (C#中的memcache客户端)

2)在console程序的main中书写此代码。

 

    static void Main(string[] args)
        {
            MemcachedClientConfiguration mcConfig = new MemcachedClientConfiguration();
            mcConfig.AddServer("119.29.176.32:11111");//云服务器的公网地址加 memcache的端口
            using (MemcachedClient client =new MemcachedClient(mcConfig))
            {
                client.Store(Enyim.Caching.Memcached.StoreMode.Set, "name", "haiyi",TimeSpan.FromSeconds(30));
                   var name =  client.Get<string>("name");
                 Console.WriteLine(name);
                /*调试  模式 存储数据*/
                //IStoreOperationResult result = client.ExecuteStore(Enyim.Caching.Memcached.StoreMode.Set, "name", "haiyi", TimeSpan.FromSeconds(30));
                //Console.WriteLine( result.StatusCode+"  is success: "+result.Success+ "  InnerResult" + result.InnerResult);
                //  var getResult =  client.ExecuteGet<string>("name");
                //Console.WriteLine(getResult.InnerResult+"  statuCode:"+getResult.StatusCode+"  success:"+getResult.Success+ "  value=" +getResult.Value); //+getResult.Exception.Message
            }
            Console.Read();
        }

 

 

 

 

转载于:https://www.cnblogs.com/Tom-yi/p/8862484.html


http://www.niftyadmin.cn/n/3959849.html

相关文章

Practical Netty (3) 在Netty中使用Protobuf

Practical Netty (3) 在Netty中使用Protobuf 作者&#xff1a;柳大Poechant&#xff08;钟超&#xff09;邮箱&#xff1a;zhongchao.ustc#gmail.com&#xff08;# -> &#xff09;博客&#xff1a;Blog.CSDN.net/Poechant 微博&#xff1a;weibo.com/lauginhom 日期&#x…

Atom改国内源

linux #进入目录 cd /home/你的用户名/.atom#创建文件并编辑 vim .apmrc#添加国内源 registryhttps://registry.npm.taobao.org#保存退出#测试是否成功 apm install --check windows #进入目录 找到C:\Users\用户名\.atom目录#创建名为 .apmrc 的文件并编辑#添加国内源 registr…

几种JAVA加密算法

1. MD5加密&#xff0c;常用于加密用户名密码&#xff0c;当用户验证时。   protected byte[] encrypt(byte[] obj) ...{   try ...{   MessageDigest md5 MessageDigest.getInstance("MD5");   md5.update(obj);   return md5.digest();   } catch (No…

Asky极简教程:零基础1小时学编程(已更新前8节)

Asky极简架构 开源Asky极简架构、超轻量级、高并发、水平扩展、微服务架构 《Asky极简教程&#xff1a;零基础1小时学编程》开源教程 零基础入门&#xff0c;从零开始全程演示&#xff0c;如何开发一个大型互联网系统&#xff0c;开源教程 开源代码 开源解决方案零基础1小时学…

[算法]两数之和,三数之和

1. 两数之和 给定一个整数数组和一个目标值&#xff0c;找出数组中和为目标值的两个数。 你可以假设每个输入只对应一种答案&#xff0c;且同样的元素不能被重复利用。 示例: 给定 nums [2, 7, 11, 15], target 9因为 nums[0] nums[1] 2 7 9 所以返回 [0, 1] LeetCode&am…

Qt(Mac) 进程的启动

试了半天&#xff0c;终于成功了&#xff01;&#xff01;&#xff01;&#xff01;&#xff08;教程都是Windows的&#xff09; 1.与Windows不一样&#xff0c;Mac的要在了路径前加上open&#xff1b; 2.例 图为把一个按钮与TextEdit程序进程联系&#xff0c;点击后就可以启动…

Hibernate的三种连接池设置C3P0、Proxool和DBCP

Xml代码 <!-- JDBC驱动程序 --> <property name"connection.driver_class">com.mysql.jdbc.Driver</property> <property name"connection.url">jdbc:mysql://localhost:3306/struts?useUnicodetrue&characterEncodingGBK&l…

ALGO-151_蓝桥杯_算法训练_6-2递归求二进制表示位数

记: 进制转换 AC代码: 1 #include <stdio.h>2 #define K 23 4 int main(void)5 {6 int n,ans 0;7 scanf("%d",&n);8 while (1)9 { 10 if (n/K 0 && n%K 0) 11 { 12 break; 13 } 14 …