redis - 查询redis数据

标签 redis

我的 access_log 文件有几行这样的行...... 10.10.11.69 [13/Sep/2011:09:52:48 +0530] “GET/icons/blank.gif HTTP/1.1” 304 - “http://10.10.10.14/production-logs/no2-pg-wallet/""Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.15) Gecko/20110303 Firefox/3.6.15"

我正在尝试将数据保存在 redis 数据库中。我可以创建一个自动递增的 ID 并保存 IP、时间戳、页面响应等,如下所示。

redis-cli incr next.news.id

set news:2:IP "10.10.11.69"

set news:2:timestamp "[13/Sep/2011:09:52:48 +0530]"

set news:2:request "GET /icons/blank.gif HTTP/1.1"

set news:2:response "304"

set news:2:page "http://10.10.10.14/production-logs/" 

set news:2:browser "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.15) Gecko/20110303 Firefox/3.6.15"

我有两个问题:

1) 如何自动化将 access_log 存储到 redis 的过程?

2) 我如何知道页面“production_logs”收到了多少次点击?

最佳答案

How do I automate the process of storing access_log to redis?

您可能需要创建一些脚本/程序来在每次创建新日志条目时执行您的命令集,或者在一段时间后批量执行此操作(例如计划作业)。

How do I know how many hits I have received to page "production_logs"?

您可以创建一个由一些前缀和页面 url(或 url 的散列)组成的键,例如 url:{url or hash here},并使用 INCRBY 这个键上的命令。如果你想散列页面 url,你可以将这些东西存储在 redis 散列数据结构中,其中一个字段将指示 url 的名称,第二个将用于使用 HINCRBY 命令存储命中计数。

关于redis - 查询redis数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7397260/

相关文章:

redis - redis-4.0.11的集群模式是否需要Sentinel?

ruby - 运行时错误 : -ERR Unknown Command running redis gem on Ruby

python - 如何在我们的 django Rest 框架项目中使用基于 Redis 缓存的存储?

c# - ServiceStack.Redis 无法连接sPort

azure - REDIS Slave无法连接Master

caching - CacheManager.Net - Redis 流水线

c# - Redis .StoreAll 类型为 'System.StackOverflowException' 的未处理异常发生在 mscorlib.dll 中

python - 在图中创建节点?

node.js - 同步调用redis方法

python - 我可以将安装在适用于 Linux 的 Windows 子系统上的 Redis 与 Windows 中的 python 应用程序一起使用吗?