【问题标题】:Configuration for grails-redis plugingrails-redis 插件的配置
【发布时间】:2015-02-05 06:36:44
【问题描述】:

我正在尝试使用 grails-redis 插件,以便实现分布式对象缓存。我的 BuildConfig 中有缓存和缓存 redis:

compile ':cache:1.1.8'
compile ":cache-redis:1.1.0"

我在本地运行 redis。我知道它正在工作,因为如果我杀死 redis,grails 应用程序将无法连接到它。我没有找到的是当我不在本地运行时如何修改redis的配置。

docs here 中没有任何内容。我还查看了source here,没有发现任何值得注意的地方。

如何配置 redis 设置(主机、端口、超时等)?

【问题讨论】:

    标签: grails caching configuration redis


    【解决方案1】:

    仔细查看插件本身的CacheRedisGrailsPlugin.groovy。你会看到 redis 本身在插件设置的doWithSpring 阶段进行了配置,并从redisCacheConfig 配置文件中读取主机、端口等内容。

    因此,在 Config.groovy 中添加类似以下内容是完全可以接受的:

    grails {
      cache {
        redis {
          hostName = 'localhost'
          port = 6379
          timeout = 2000
        }
      }
    }
    

    【讨论】:

    • 感谢您的建议,但是,我将它添加到我的 Config.groovy 并提供了一个虚假的主机名,它仍然可以正常连接,所以我不认为这是准确的。此外,使用 : 代替 = 似乎很奇怪(顺便说一句,我都试过了)。
    • 好的,知道了 grails { cache { redis { timeout = 2000 //默认以毫秒为单位 port = 6379 hostName = "localhost" } } }
    • 更新了答案以反映这一点。
    猜你喜欢
    • 2010-10-25
    • 2012-01-27
    • 1970-01-01
    • 2018-02-16
    • 1970-01-01
    • 2013-03-11
    • 1970-01-01
    • 2012-10-19
    • 2015-07-14
    相关资源
    最近更新 更多