php - 如何使用 Predis 和 redis-cli 连接到同一个 redis 数据库?

标签 php redis predis

在使用 redis 时,我注意到,连接 Predis 和 redis-cli 会导致不同的键空间,它们都具有名称 db0。两个连接都连接到运行在 tcp://localhost:6379 上的 redis 服务器。 我可以看到转储也在不同的位置。

这是来自两个实例的信息:

来自 redis-cli:信息服务器

# Server
redis_version:2.8.19
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:70633d1af7244f5e
redis_mode:standalone
os:Darwin 14.3.0 x86_64
arch_bits:64
multiplexing_api:kqueue
gcc_version:4.2.1
process_id:517
run_id:900bab4b7a89ed6616bababd8c7d443b7d53f6a8
tcp_port:6379
uptime_in_seconds:136898
uptime_in_days:1
hz:10
lru_clock:5781598
config_file:/usr/local/etc/redis.conf

来自 predis,信息

  'Server' => 
    array (size=17)
      'redis_version' => string '2.8.19' (length=6)
      'redis_git_sha1' => string '00000000' (length=8)
      'redis_git_dirty' => string '0' (length=1)
      'redis_build_id' => string '70633d1af7244f5e' (length=16)
      'redis_mode' => string 'standalone' (length=10)
      'os' => string 'Darwin 14.3.0 x86_64' (length=20)
      'arch_bits' => string '64' (length=2)
      'multiplexing_api' => string 'kqueue' (length=6)
      'gcc_version' => string '4.2.1' (length=5)
      'process_id' => string '8894' (length=4)
      'run_id' => string 'fff57e23438c261c83dc0e91ca4829a743d5919a' (length=40)
      'tcp_port' => string '6379' (length=4)
      'uptime_in_seconds' => string '5621' (length=4)
      'uptime_in_days' => string '0' (length=1)
      'hz' => string '10' (length=2)
      'lru_clock' => string '5781216' (length=7)
      'config_file' => string '' (length=0)

最佳答案

run_id:900bab4b7a89ed6616bababd8c7d443b7d53f6a8
'run_id' => string 'fff57e23438c261c83dc0e91ca4829a743d5919a' (length=40)

以上是你连接两个不同的Redis服务器的证明,所以答案很简单,就是有不同的问题要解决,也就是理解为什么会这样。在检查了明显的原因之后,如果您没有找到任何线索,请检查您是否正在与一台监听 IPv6 地址的服务器和一台监听 IPv4 地址的同一端口进行对话。

关于php - 如何使用 Predis 和 redis-cli 连接到同一个 redis 数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30287878/

相关文章:

javascript - onclick 也重定向到 "form action"

php - uploadify firefox崩溃成功响应警报

performance - JedisPool 持有的默认连接

mysql - 将 MySQL 中的主键映射到 Redis

php - Redis 中的 CRUD 和关系 : How to

带有 mysql 和长时间运行备份的 PHP 应用程序

php - csv 到 excel 转换

python - Flask Heroku 应用程序无法连接到 Redis 队列

java - 服务器架构 - Redis 与 Socket 服务器

redis - Predis集群槽手册集