Redis和Memcache还是Redis?(Redis and Memcache or just Redis?)
我通过简单的
Rails.cache
接口在我的Rails 3应用程序中使用memcached进行一些缓存,现在我想使用redis和resque进行一些后台处理。我觉得他们不一样,足以保证使用这两者。 关于英雄,尽管使用memcached和redis都有单独的费用。 使用两者还是应该迁移到只使用redis?
我喜欢使用memcached进行缓存,因为最近最近使用的密钥自动被推出缓存,我不需要缓存数据。 Redis对我来说大多是新手,但是我明白,默认情况下它是持久的,该键不会自动从缓存中过期。
编辑:只是想更清楚我的问题。 我知道只使用Redis而不是两者都是可行的。 我想我只想知道这样做有什么特别的缺点吗? 考虑到实施和基础设施,有没有什么原因,我不应该只是使用Redis? (即,对于简单的缓存,memcached是更快吗?)我没有找到任何方式。
I'm using memcached for some caching in my Rails 3 app through the simple
Rails.cache
interface and now I'd like to do some background job processing with redis and resque.I think they're different enough to warrant using both. On heroku though, there are separate fees to use both memcached and redis. Does it make sense to use both or should I migrate to just using redis?
I like using memcached for caching because least recently used keys automatically get pushed out of the cache and I don't need the cache data to persist. Redis is mostly new to me, but I understand that it's persistent by default and that keys do not expire out of the cache automatically.
EDIT: Just wanted to be more clear with my question. I know it's feasible to use only Redis instead of both. I guess I just want to know if there are any specific disadvantages in doing so? Considering both implementation and infrastructure, are there any reasons why I shouldn't just use Redis? (I.e., is memcached faster for simple caching?) I haven't found anything definitive either way.
原文:https://stackoverflow.com/questions/4188620
满意答案
这将打印出一个
pthread_t
的十六进制表示,无论实际是什么:void fprintPt(FILE *f, pthread_t pt) { unsigned char *ptc = (unsigned char*)(void*)(&pt); fprintf(f, "0x"); for (size_t i=0; i<sizeof(pt); i++) { fprintf(f, "%02x", (unsigned)(ptc[i])); } }
为了打印每个
pthread_t
一个小id,可以使用这样的东西(这个时候使用iostreams):void printPt(std::ostream &strm, pthread_t pt) { static int nextindex = 0; static std::map<pthread_t, int> ids; if (ids.find(pt) == ids.end()) { ids[pt] = nextindex++; } strm << ids[pt]; }
根据平台和
pthread_t
的实际表示,可能需要为pthread_t
定义一个operator<
,因为std::map
需要对元素进行排序:bool operator<(const pthread_t &left, const pthread_t &right) { ... }
This will print out a hexadecimal representation of a
pthread_t
, no matter what that actually is:void fprintPt(FILE *f, pthread_t pt) { unsigned char *ptc = (unsigned char*)(void*)(&pt); fprintf(f, "0x"); for (size_t i=0; i<sizeof(pt); i++) { fprintf(f, "%02x", (unsigned)(ptc[i])); } }
To just print a small id for a each
pthread_t
something like this could be used (this time using iostreams):void printPt(std::ostream &strm, pthread_t pt) { static int nextindex = 0; static std::map<pthread_t, int> ids; if (ids.find(pt) == ids.end()) { ids[pt] = nextindex++; } strm << ids[pt]; }
Depending on the platform and the actual representation of
pthread_t
it might here be necessary to define anoperator<
forpthread_t
, becausestd::map
needs an ordering on the elements:bool operator<(const pthread_t &left, const pthread_t &right) { ... }
相关问答
更多我如何从任意pthread_t获取线程ID?(How do I get a thread ID from an arbitrary pthread_t?)
对当前正在运行的线程重用pthread_t变量(reusing pthread_t variable for currently running threads)
如何打印pthread_t(How to print pthread_t)
删除pthread_t *(deleting pthread_t*)
管道无法通过pthread_t工作(pipe not working through pthread_t)
从线程ID获取pthread_t(get pthread_t from thread id)
如果我在未使用的pthread_t上调用pthread_join()会发生什么?(What will happen if I call pthread_join() on an unused pthread_t?)
为什么和pthread_t是不透明类型?(Why and in what sense is pthread_t an opaque type?)
`pthread_create`的`pthread_t *`参数需要多长时间才能存活?(How long does the `pthread_t*` argument to `pthread_create` need to survive?)
我可以让pthread_t实例超出范围吗?(Can I let pthread_t instance go out of scope?)
相关文章
更多Redis Cookbook
Redis概述
redis安装-redis集群管理
基于linux下redis安装与配置
基于window安装redis
redis整合spring示例一
redis主从从架构搭建-redis集群管理
redis 使用笔记01
Redis 哈希(Hash)详解
redis新增集群节点-redis集群管理
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!