记录一下Memcached的用法:
首先就是先要配置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的用法:的更多相关文章
- Mac linux 安装memcached服务 用法
今天在Mac上安装memcached服务的时候 由于安装memcached之前需要安装libevent依赖包 所以使用brew install libevent 安装过程中报错 Warning: Yo ...
- 开发portlet中的一些问题记录,portlet:resourceURL用法,portlet中通过processAction方法传值
在portlet页面中引入js或者css,通过c或者s标签 <!--jquery实际放的地方:/MyTask/WebContent/scripts/jquery-1.8.3.min.js--&g ...
- 记录一下set的用法
set译为集合,是一个内部自动有序且不含重复元素的容器 有时出现需要去掉重复元素的情况 而且有可能因这些元素比较大或者类型不是int型而不能直接开散列表 在这种情况下就可以用set来保留元素本身而不考 ...
- 记录一个url_for的用法
使用url_for生成url时,需要将url协议从http换成https时,就可以通过在函数中增加参数实现: url_for('secure_thingy', _external=True, _sch ...
- 记录一下Comparator的用法
Collections.sort(res, new Comparator<ArrayList<Integer>>() { @Override ...
- memcached使用文档
使用memcached进行内存缓存 通常的网页缓存方式有动态缓存和静态缓存等几种,在ASP.NET中已经可以实现对页面局部进行缓 存,而使用memcached的缓存比ASP.NET的局部缓存更加灵活, ...
- Memcached简介
在Web服务开发中,服务端缓存是服务实现中所常常采用的一种提高服务性能的方法.其通过记录某部分计算结果来尝试避免再次执行得到该结果所需要的复杂计算,从而提高了服务的运行效率. 除了能够提高服务的运行效 ...
- Memcached+PHP+Mysql+Linux 实践
首先确保你的服务器环境已经具备了memcached和lamp,关于在Linux上搭建memcahced+php环境可以参考我的另外一篇帖子( http://www.cnblogs.com/codeAB ...
- [转载]memcached完全剖析--1. memcached的基础
转载自:http://charlee.li/memcached-001.html 翻译一篇技术评论社的文章,是讲memcached的连载.fcicq同学说这个东西很有用,希望大家喜欢. 发表日:200 ...
随机推荐
- 大O时间复杂度
大O表示法指出了在最糟情况下的运行时间.比较操作数,指出了算法运行时间的增速 常见的大O运行时间 O(logn):也叫对数时间,包括二分查找 O(n):也叫线性时间,包括简单查找 O(nlogn):包 ...
- NYIST 1006 偷西瓜
偷西瓜 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 对于农村的孩子来说最大的乐趣,莫过于和小伙伴们一块下地偷西瓜了,虽然孩子们条件不是很好,但是往往他们很聪明,他 ...
- LaTeX argmin argmax 下标使用方法
本系列文章由 @YhL_Leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/50036001 LaTeX中,使用arg ...
- 精品JS代码收藏大全
1. oncontextmenu="window.event.returnvalue=false" 将彻底屏蔽鼠标右键 <table border oncontextmenu ...
- sass04 嵌套、继承、占位符
demo1.scss body{ //选择器嵌套 background-color:lightgray; header{ background-color:lightgreen; } footer{ ...
- hdu-2871
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #i ...
- spark 数据预处理 特征标准化 归一化模块
#We will also standardise our data as we have done so far when performing distance-based clustering. ...
- hdoj--1408--盐水的故事(技巧)
盐水的故事 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- <Sicily>Funny Game
一.题目描述 Two players, Singa and Suny, play, starting with two natural numbers. Singa, the first player ...
- vue子组件使用指令 同时绑定v-model 指令没有作用
//这里直接上代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...