Redis启动脚本应该在启动时创建一个pid文件,但我已经确认了我能找到的所有设置,并且没有创建任何pid文件.
我安装了redis:
$ yum install redis
$ chkconfig redis on
$ service redis start
Run Code Online (Sandbox Code Playgroud)
在我的配置文件(/etc/redis.conf)中,我检查了以确保这些已启用:
daemonize yes
pidfile /var/run/redis/redis.pid
Run Code Online (Sandbox Code Playgroud)
在启动脚本(/etc/init.d/redis)中有:
exec="/usr/sbin/$name"
pidfile="/var/run/redis/redis.pid"
REDIS_CONFIG="/etc/redis.conf"
[ -e /etc/sysconfig/redis ] && . /etc/sysconfig/redis
lockfile=/var/lock/subsys/redis
start() {
[ -f $REDIS_CONFIG ] || exit 6
[ -x $exec ] || exit 5
echo -n $"Starting $name: "
daemon --user ${REDIS_USER-redis} "$exec $REDIS_CONFIG"
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $name: "
killproc -p $pidfile …Run Code Online (Sandbox Code Playgroud) 我知道要在我自己的控制器中设置 Cache-Control 标头,我可以调用#expires_now,但我的 Rails 应用程序使用引擎(apitome),并且在这些请求中, Cache-Control 标头设置为max-age=0, private, must-revalidate. 我看到这可能是 Rack::ETag here的默认值,但我不知道如何覆盖它。
例如,当我设置时Rails.configuration.public_file_server.headers = { 'Cache-Control' => 'no-cache' },会更改我的 javascript 资产的标头,但不会更改引擎。
有没有办法覆盖默认值或在引擎中设置此设置的好方法?也许只是猴子修补控制器并添加一个 before_action 来设置标题?
我正在运行 Rails 5.1.4,我有一个看起来像这样的模型:
class Quota < ActiveRecord::Base
belongs_to :domain, optional: true
belongs_to :project, optional: true
end
Run Code Online (Sandbox Code Playgroud)
配额应属于域或项目,但不能同时属于两者(因此设置optional: true)。
但是,如果提供了无效的项目或域 ID,我似乎无法弄清楚如何使 rails 抛出错误。
这是发生的事情:
q = Quota.create!(domain_id: nil, project_id: 'invalid_id')
q.project_id # -> nil
Run Code Online (Sandbox Code Playgroud)
即使我明确传递了 project_id,如果它与有效项目不匹配,它也会神奇地将其清除。我尝试添加自定义验证方法,但是在调用验证方法时,它已经设置为 nil。它甚至不使用该project_id=方法;我检查了。
如果 ID 无效而不是将其设置为 nil,有没有办法让 Rails 引发错误?(同时仍然允许一个 nil 值)
我正在使用 Ruby 2.3.1,这是我想要做的:
1.33333333.ceil(2) -> 1.34
1.33333333.floor(3) -> 1.333
Run Code Online (Sandbox Code Playgroud)
该Float#round方法允许我舍入,但我需要能够指定是向上还是向下舍入,类似于#ceil和#floor方法,但带有一个参数来指定要保留的小数位数。
我有一个通过自动化运行的 PowerShell 脚本,所以我需要将脚本的输出捕获到一个文件中,但我还想捕获运行的命令,为输出提供一些上下文(我会set -x在Linux shell 脚本)。我不知道如何将这些命令捕获到 Windows 中的输出文件中;任何帮助深表感谢!
# script.ps1
Set-PSDebug -Trace 1
Write-Host "Hello, World!"
Run Code Online (Sandbox Code Playgroud)
我如何调用脚本(从 cmd):
$ powershell -command "./script.ps1 *>&1 | Tee-Object -FilePath ./output.txt"
Run Code Online (Sandbox Code Playgroud)
终端输出:
DEBUG: 2+ >>>> Write-Host "Hello, World!"
Hello, World!
Run Code Online (Sandbox Code Playgroud)
output.txt 文件内容:
Hello, World!
Run Code Online (Sandbox Code Playgroud)
您可以看到输出文件缺少终端中显示的调试行。理想情况下,我希望调试行只在输出文件中(不是终端输出),但在两个地方都有调试行也可以。
请注意,PowerShell 5.1 是我安装的版本。
activerecord ×1
caching ×1
ceil ×1
floor ×1
powershell ×1
rack ×1
rails-models ×1
redis ×1
rhel6 ×1
rounding ×1
ruby ×1
trace ×1