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_t获取线程ID?(How do I get a thread ID from an arbitrary pthread_t?)

由于pthread不需要用Linux线程(或者根本就不用内核线程)来实现,并且某些实现完全是用户级别的或混合的,所以pthread s接口不提供访问这些实现细节的函数,如那些将不可移植(甚至跨Linux上的pthread的实现)。 使用这些库的线程库可以将此作为扩展,但似乎并没有这样做。 除了访问线程库的内部数据结构(你可以理解,不需要,尽管你的假设是关于处理器亲和性和Linux线程ID,但是你的代码无论如何都不能移植),你可以在创建时玩弄技巧,如果您控制创建线程的代码: 给pthread_cre...

对当前正在运行的线程重用pthread_t变量(reusing pthread_t variable for currently running threads)

pthread_t只是一个标识符。 你可以复制它或随意摧毁它。 当然,如你所说,如果你销毁它(因为它是本地的),那么你不能用它来调用pthread_join 。 如果您为多个线程重复使用相同的pthread_t变量,那么除非一次只有一个线程处于活动状态,否则您将用新值覆盖旧值,并且只能在最近启动的线程上调用pthread_join 。 另外,如果你从多个线程内部启动你的线程,那么你将需要用一个互斥体来保护pthread_t变量。 如果您需要等待线程完成,请给它自己的pthread_t变量,并在需要...

如何打印pthread_t(How to print 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<sizeof(pt); i++) { fprintf(f, "%02x", (unsigned)(ptc[i])); } } 为了打印每个pthread_t...

删除pthread_t *(deleting pthread_t*)

你需要方括号来创建数组: 不是这个: pthread_t* threadNumber = new pthread_t (4); // ^ ^ 但这是正确的: pthread_t* threadNumber = new pthread_t [4]; // ^ ^ 你的版本是一个初始化为4 pthread_t变量 - 无论这个4在这个上下文中意味着什么...

管道无法通过pthread_t工作(pipe not working through pthread_t)

我认为在涉及线程时文件描述符是重复的,但似乎并非如此。 不,那不是真的。 进程中的所有线程共享这些文件描述符(以及其他资源)。 因为,关闭管道的写入端, write() (在线程中完成)失败。 相同进程的线程可以在共享地址空间时直接与每个进程通信。 例如,您可以使用全局变量进行线程之间的通信(具有适当的同步),或者您可以malloc()一些内存并将其传递给线程以发送数据。 您似乎期望的那种“共享”在由共同祖先通过fork()创建的进程之间使用。 分叉时 ,文件描述符(以及其他文件描述符)是重复的,...

从线程ID获取pthread_t(get pthread_t from thread id)

我不认为这样的功能存在,但我很乐意纠正。 作为一种解决方法,我可以创建一个表映射&pthread_t到pid_t并确保我总是通过向该表添加条目的包装器调用pthread_create() 。 这非常有效,并允许我将OS线程id转换为pthread_t ,然后我可以使用pthread_cancel()终止它。 以下是该机制的片段: typedef void* (*threadFunc)(void*); static void* start_thread(void* arg) { threadF...

如果我在未使用的pthread_t上调用pthread_join()会发生什么?(What will happen if I call pthread_join() on an unused pthread_t?)

根据ISO C, newThread变量是一个“不确定值的对象”,其使用会触发未定义的行为。 它可能有一个“陷阱表示”,它会触发CPU异常。 或者它可能只被解释为该类型的随机值,API可以通过以下两种方式之一处理:要么没有这样的线程,要么返回ESRCH ,要么侥幸有这样的线程。 然后会出现各种情况:是否可以加入,等等。 According to ISO C, the newThread variable is an "indeterminately valued object", the use ...

为什么和pthread_t是不透明类型?(Why and in what sense is pthread_t an opaque type?)

是否真的有意支持线程没有数字标识的系统? 有不同的类型可以作为数字线程标识符。 例如,在资源有限的系统上,可以使用8位线程标识符来代替unsigned long 。 属性类型的结构不是故意暴露的。 该注释不是针对pthread_t定义的,而是针对pthread_attr_t定义下面的一行: typedef union { char __size[__SIZEOF_PTHREAD_ATTR_T]; long int __align; } pthread_attr_t; 该注释指出char ...

`pthread_create`的`pthread_t *`参数需要多长时间才能存活?(How long does the `pthread_t*` argument to `pthread_create` need to survive?)

返回线程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 ...

我可以让pthread_t实例超出范围吗?(Can I let pthread_t instance go out of scope?)

是的 - 让变量超出范围是安全的。 但请记住,您必须在某些时候执行以下两项操作之一: 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) pthr...

相关文章

更多

Redis Cookbook

Two years since its initial release, Redis already ...

Redis概述

什么是Redis Redis是Remote Dictionary Server的缩写, Redis是一 ...

redis安装-redis集群管理

安装redis [root@master opt]# mkdir /opt/redis [root ...

基于linux下redis安装与配置

编译源程序:make install,复制可执行文件,Redis的启动,Redis随机启动

基于window安装redis

1、下载redis的window版本 下载地址: https://github.com/Service ...

redis整合spring示例一

这里使用java操作redis的示例,也是领悟书生网站项目中使用的代码.当然本示例也是参考网上的相关文 ...

redis主从从架构搭建-redis集群管理

主从从架构 [root@master redis-master-slave]# vim 6382/re ...

redis 使用笔记01

今天和张哥商量 准备将微信服务端 移植到4joy服务器上。首先一个问题就是解决人员列表缓存同步问题。 ...

Redis 哈希(Hash)详解

Redis hash 是一个string类型的field和value的映射表,hash特别适合用于存储 ...

redis新增集群节点-redis集群管理

新增一个节点6383,并启动 执行redis-trib.rb add-node命令添加节点 redi ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本