首先就是先要配置Memcached,这个回头再写。

https://zhidao.baidu.com/question/809745125827797732.html

https://www.cnblogs.com/XZhao/p/6821121.html

using Memcached.ClientLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OAMS.Common
{
public class MemcacheHelper//声明一个类,里面放所用的方法之类的
{
private static readonly MemcachedClient mc = null;//MemcachedClient是添加的Memcached的dll里封装的
static MemcacheHelper()
{
//最好放在配置文件中
string[] serverlist = { "127.0.0.1:11211", "10.0.0.132:11211" };
//初始化池
SockIOPool pool = SockIOPool.GetInstance();
pool.SetServers(serverlist);

pool.InitConnections = 3;
pool.MinConnections = 3;
pool.MaxConnections = 5;

pool.SocketConnectTimeout = 1000;
pool.SocketTimeout = 3000;

pool.MaintenanceSleep = 30;
pool.Failover = true;

pool.Nagle = false;
pool.Initialize();

// 获得客户端实例
mc = new MemcachedClient();
mc.EnableCompression = false;
}

/// <summary>
/// 存储数据
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public static bool Set(string key, object value)
{
return mc.Set(key, value);
}
public static bool Set(string key, object value, DateTime time)
{
return mc.Set(key, value, time);
}
/// <summary>
/// 获取数据
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public static object Get(string key)
{
return mc.Get(key);
}
/// <summary>
/// 删除
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public static bool Delete(string key)
{
if (mc.KeyExists(key))
{
return mc.Delete(key);

}
return false;

}
}
}

-------------------------------------------------------------------------

//将登录用户信息存储到Memcache中。
Common.MemcacheHelper.Set(sessionId, Common.SerializeHelper.SerializeToString(userInfo), DateTime.Now.AddMinutes(20));

//根据该值查Memcache.
object obj = Common.MemcacheHelper.Get(sessionId);

要在nuget里引用(安装) EnyimMemcached ,

https://blog.csdn.net/ma_jiang/article/details/61419460

  

记录一下Memcached的用法:的更多相关文章

  1. Mac linux 安装memcached服务 用法

    今天在Mac上安装memcached服务的时候 由于安装memcached之前需要安装libevent依赖包 所以使用brew install libevent 安装过程中报错 Warning: Yo ...

  2. 开发portlet中的一些问题记录,portlet:resourceURL用法,portlet中通过processAction方法传值

    在portlet页面中引入js或者css,通过c或者s标签 <!--jquery实际放的地方:/MyTask/WebContent/scripts/jquery-1.8.3.min.js--&g ...

  3. 记录一下set的用法

    set译为集合,是一个内部自动有序且不含重复元素的容器 有时出现需要去掉重复元素的情况 而且有可能因这些元素比较大或者类型不是int型而不能直接开散列表 在这种情况下就可以用set来保留元素本身而不考 ...

  4. 记录一个url_for的用法

    使用url_for生成url时,需要将url协议从http换成https时,就可以通过在函数中增加参数实现: url_for('secure_thingy', _external=True, _sch ...

  5. 记录一下Comparator的用法

    Collections.sort(res, new Comparator<ArrayList<Integer>>() {             @Override       ...

  6. memcached使用文档

    使用memcached进行内存缓存 通常的网页缓存方式有动态缓存和静态缓存等几种,在ASP.NET中已经可以实现对页面局部进行缓 存,而使用memcached的缓存比ASP.NET的局部缓存更加灵活, ...

  7. Memcached简介

    在Web服务开发中,服务端缓存是服务实现中所常常采用的一种提高服务性能的方法.其通过记录某部分计算结果来尝试避免再次执行得到该结果所需要的复杂计算,从而提高了服务的运行效率. 除了能够提高服务的运行效 ...

  8. Memcached+PHP+Mysql+Linux 实践

    首先确保你的服务器环境已经具备了memcached和lamp,关于在Linux上搭建memcahced+php环境可以参考我的另外一篇帖子( http://www.cnblogs.com/codeAB ...

  9. [转载]memcached完全剖析--1. memcached的基础

    转载自:http://charlee.li/memcached-001.html 翻译一篇技术评论社的文章,是讲memcached的连载.fcicq同学说这个东西很有用,希望大家喜欢. 发表日:200 ...

随机推荐

  1. 【BZOJ 1193】 [HNOI2006]马步距离

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 原问题可以等价为两个点. 然后其中一个点要移动到另外一个点. 那么我们可以把左下角那个点(对称总是可以得到一个点在左下角)放在原点的 ...

  2. mysql-联结

    一.联结 联结是利用SQL的select能执行的最重要的操作. 1.关系表:假如有一个包含产品目录的数据库表,其中每个类别的物品占一行.对于每种物品要求存储的信息包括产品描述和价格,以及生产该产品的供 ...

  3. UI组件之AdapterView及其子类(四)Gallery画廊控件使用

    听说 Gallery如今已经不使用了,API使用ViewPaper取代了,以后再学专研ViewPaper吧如今说说Gallery画廊,就是不停显示图片的意思 Gallery是用来水平滚动的显示一系列项 ...

  4. rest_framework-解析器-总结完结篇

    感谢alex和武老师 前戏: Djaogo对请求体只支持 application/x-www-form-urlencoded请求头以及name=alex&age=18的数据格式 django. ...

  5. Spring深入浅出(一)IOC的基本知识

    Spring前言 Spring是一个企业级开发框架,为解决企业级项目开发过于复杂而创建的,框架的主要优势之一就是分层架构,允许开发者自主选择组件. Spring的两大核心机制是IOC(控制反转)和AO ...

  6. iOS 集成Protobuf,转换proto文件

    原文地址:http://blog.csdn.net/hyq4412/article/details/54891038 附加Homebrew安装地址:https://brew.sh/index_zh-c ...

  7. Linux FTP客户端

    1.File Zilla File Zilla是一个开源的,跨平台的Linux FTP客户端.File Zilla有一个标签式的用户界面,允许用户查看正在传输的文件的所有细节.File Zilla是通 ...

  8. [国家集训队]拉拉队排练 Manancher_前缀和_快速幂

    Code: #include <cstdio> #include <algorithm> #include <cstring> using namespace st ...

  9. session 存入 memcahce

    <?php header('content-type:text/html;charset=utf-8'); class RedisSessionHandler{ public $ttl; //失 ...

  10. NodeJS学习笔记 进阶 (9)express+cookie-parser:签名机制深入剖析(ok)

    个人总结:这篇文章讲解了express框架种cookie的使用,需要引用cookie-parser这个包.读完这篇文章需要10分钟. 摘选自网络 文章导读 cookie-parser是Express的 ...