记录日志的Redis [英] redis for logging

查看:84
本文介绍了记录日志的Redis的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑将Redis用于Web应用程序日志记录.我在Google上搜索到有人使用这种方法,将日志转储到Redis队列/列表中,然后将计划的工作人员转储到磁盘.

I am thinking of using Redis for web application logging purposes. I googled that there are people using this approach by dumping the logs into a Redis queue/list, and then a scheduled worker to write to disk.

http://nosql.mypopescu.com/post/8652869828/another -redis-use-case-centralized-logging

我想寻求一种理解,为什么不直接使用Redis持久化到磁盘?如果我分配了一个Redis将写入的小型服务器,与数据库中的应用服务器分开,那么使用Redis直接保留日志是否可行?

I wish to seek understanding that why not directly use Redis to persist to disk? If I have allocated a small server which Redis will write to, separated from the database, app server, is it feasible to use Redis to persist the logs directly?

在按日期时间,用户等查询Redis时,我还需要帮助.例如,每个日志如下.

I also need help in querying Redis by datetime, user, etc. For example, each log is as follow.

datetime=>2012-03-24 17:45:12
userid=>123
message=>test message
category=>my category

如何查询特定用户在特定类别的日期时间范围内的结果?

How can I query for results within a datetime range, by a specific user, of a particular category?

谢谢!

推荐答案

您需要记住,Redis是内存数据库(即使它可以将数据持久保存到磁盘).您放入Redis的数据必须容纳在内存中.

You need to keep in mind that Redis is an in-memory database (even if it can persist the data to disk). The data you put in Redis have to fit in memory.

您提到的文章中的建议是关于将Redis用作分布式排队系统. Worker进程将项目出队并写入磁盘,因此Redis内存中没有多少项目.这种设计有一个缺陷:如果工作进程无法将数据足够快地写入磁盘,Redis的内存消耗将激增-因此,它必须受到配置(Redis maxmemory参数)或软件(在插入时修剪队列,或清空)的限制.队列已满).

The proposal in the article you mention is about using Redis as a distributed queuing system. Worker processes dequeue the items and write them to disk, so there are not that many items in Redis memory. This design has a flaw: if the worker processes cannot write the data fast enough to disk, Redis memory consumption will explode - so it has to be limited by configuration (Redis maxmemory parameter) or software (trim the queue at insert time, or empty the queue when it is full).

由于您在Redis中写入的所有数据都将保留在内存中(即使这些数据由Redis本身持久保存到磁盘中),因此您的建议实际上并没有奏效.

Now your proposal does not really work since all the data you write in Redis will be kept in memory (even if they are persisted to disk by Redis itself).

另一点是您无法查询Redis. Redis不是关系数据库,它不支持即席查询机制,仅支持涉及先前定义的访问路径的命令.如果要使用不同的参数搜索数据,则必须预见所有可能的搜索并在插入时构建相关的数据结构(集合,排序集合等).

Another point is you cannot query Redis. Redis is not a relational database, it supports no ad-hoc query mechanism, only commands involving previously defined access paths. If you want to search data with different parameters, you have to anticipate all the possible searches and build the relevant data structures (set, sorted sets, etc ...) at insert time.

另一个商店(MongoDB或关系数据库)可能更适合您的用例.

Another store (MongoDB, or a relational database) will probably be a much better fit for your use case.

这篇关于记录日志的Redis的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆