首页 \ 问答 \ Redis和Memcache还是Redis?(Redis and Memcache or just Redis?)

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
更新时间:2024-02-15 19:02

最满意答案

这将打印出一个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 an operator< for pthread_t, because std::map needs an ordering on the elements:

bool operator<(const pthread_t &left, const pthread_t &right) {
  ...
}

相关问答

更多
  • 由于pthread不需要用Linux线程(或者根本就不用内核线程)来实现,并且某些实现完全是用户级别的或混合的,所以pthread s接口不提供访问这些实现细节的函数,如那些将不可移植(甚至跨Linux上的pthread的实现)。 使用这些库的线程库可以将此作为扩展,但似乎并没有这样做。 除了访问线程库的内部数据结构(你可以理解,不需要,尽管你的假设是关于处理器亲和性和Linux线程ID,但是你的代码无论如何都不能移植),你可以在创建时玩弄技巧,如果您控制创建线程的代码: 给pthread_create() ...
  • pthread_t只是一个标识符。 你可以复制它或随意摧毁它。 当然,如你所说,如果你销毁它(因为它是本地的),那么你不能用它来调用pthread_join 。 如果您为多个线程重复使用相同的pthread_t变量,那么除非一次只有一个线程处于活动状态,否则您将用新值覆盖旧值,并且只能在最近启动的线程上调用pthread_join 。 另外,如果你从多个线程内部启动你的线程,那么你将需要用一个互斥体来保护pthread_t变量。 如果您需要等待线程完成,请给它自己的pthread_t变量,并在需要等待的地方 ...
  • 这将打印出一个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
  • 你需要方括号来创建数组: 不是这个: pthread_t* threadNumber = new pthread_t (4); // ^ ^ 但这是正确的: pthread_t* threadNumber = new pthread_t [4]; // ^ ^ 你的版本是一个初始化为4 pthread_t变量 - 无论这个4在这个上下文中意味着什么 - 因为 ...
  • 我认为在涉及线程时文件描述符是重复的,但似乎并非如此。 不,那不是真的。 进程中的所有线程共享这些文件描述符(以及其他资源)。 因为,关闭管道的写入端, write() (在线程中完成)失败。 相同进程的线程可以在共享地址空间时直接与每个进程通信。 例如,您可以使用全局变量进行线程之间的通信(具有适当的同步),或者您可以malloc()一些内存并将其传递给线程以发送数据。 您似乎期望的那种“共享”在由共同祖先通过fork()创建的进程之间使用。 分叉时 ,文件描述符(以及其他文件描述符)是重复的,您可以在每 ...
  • 我不认为这样的功能存在,但我很乐意纠正。 作为一种解决方法,我可以创建一个表映射&pthread_t到pid_t并确保我总是通过向该表添加条目的包装器调用pthread_create() 。 这非常有效,并允许我将OS线程id转换为pthread_t ,然后我可以使用pthread_cancel()终止它。 以下是该机制的片段: typedef void* (*threadFunc)(void*); static void* start_thread(void* arg) { threadFunc t ...
  • 根据ISO C, newThread变量是一个“不确定值的对象”,其使用会触发未定义的行为。 它可能有一个“陷阱表示”,它会触发CPU异常。 或者它可能只被解释为该类型的随机值,API可以通过以下两种方式之一处理:要么没有这样的线程,要么返回ESRCH ,要么侥幸有这样的线程。 然后会出现各种情况:是否可以加入,等等。 According to ISO C, the newThread variable is an "indeterminately valued object", the use of wh ...
  • 是否真的有意支持线程没有数字标识的系统? 有不同的类型可以作为数字线程标识符。 例如,在资源有限的系统上,可以使用8位线程标识符来代替unsigned long 。 属性类型的结构不是故意暴露的。 该注释不是针对pthread_t定义的,而是针对pthread_attr_t定义下面的一行: typedef union { char __size[__SIZEOF_PTHREAD_ATTR_T]; long int __align; } pthread_attr_t; 该注释指出char __siz ...
  • 返回线程ID供您自己使用。 如果您要分离线程或线程将自行分离,则无需存储它。 void make_thread(void) { pthread_t tid; return pthread_create(&tid, NULL, some_fn, NULL); } 这有点奇怪。 您无法加入该主题,因为您没有保留其ID。 你没有脱掉它。 我认为如果线程自行分离可能会很好,但这是一种奇怪的做事方式。 The thread ID is returned for your own use. You don't ...
  • 是的 - 让变量超出范围是安全的。 但请记住,您必须在某些时候执行以下两项操作之一: 1)pthread_detach()它会让内核释放某些与之相关的东西。 2)pthread_join()它有一个副作用分离它。 如果你不这样做,我认为这将是一个资源泄漏。 Yes -- it's safe to let the variable go out of scope. But remember you have to at some point do one of two things: 1) pthread_d ...

相关文章

更多

最新问答

更多
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • linux的常用命令干什么用的
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • Java中的不可变类(Immutable class in Java)
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • 绑定属性设置器未被调用(Bound Property Setter not getting Called)
  • linux ubuntu14.04版没有那个文件或目录
  • 如何使用JSF EL表达式在param中迭代变量(How to iterate over variable in param using JSF EL expression)
  • 是否有可能在WPF中的一个单独的进程中隔离一些控件?(Is it possible to isolate some controls in a separate process in WPF?)
  • 使用Python 2.7的MSI安装的默认安装目录是什么?(What is the default installation directory with an MSI install of Python 2.7?)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • ckeditor config.protectedSource不适用于editor.insertHtml上的html元素属性(ckeditor config.protectedSource dont work for html element attributes on editor.insertHtml)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 将CouchDB与AJAX一起使用是否安全?(Is it safe to use CouchDB with AJAX?)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • 无法在新线程中从FREContext调用getActivity()?(Can't call getActivity() from FREContext in a new thread?)
  • 在Alpine上升级到postgres96(/ usr / bin / pg_dump:没有这样的文件或目录)(Upgrade to postgres96 on Alpine (/usr/bin/pg_dump: No such file or directory))
  • 如何按部门显示报告(How to display a report by Department wise)
  • Facebook墙贴在需要访问令牌密钥后无法正常工作(Facebook wall post not working after access token key required)
  • Javascript - 如何在不擦除输入的情况下更改标签的innerText(Javascript - how to change innerText of label while not wiping out the input)
  • WooCommerce / WordPress - 不显示具有特定标题的产品(WooCommerce/WordPress - Products with specific titles are not displayed)