
SwooleRedisServer::format 메소드는 Redis 메시지를 포맷하는 데 사용됩니다. 포맷 문자열에 변수를 넣을 때, 변수가 문자열이 아닌 경우에는 변수를 문자열로 변환해야 합니다.
변수를 문자열로 변환하는 방법은 다음과 같습니다.
#hostingforum.kr
php
$message = (string) $data;
포맷 문자열에 변수가 여러 개 있을 때, 변수를 순서대로 넣을 수 있습니다. 변수를 순서대로 넣기 위해서는, 포맷 문자열에서 변수를 대괄호 {} 안에 넣어야 합니다.
예를 들어, 포맷 문자열이 "Hello, {name}!" 인 경우, 변수 $name을 넣기 위해서는 다음과 같이 코드를 작성해야 합니다.
#hostingforum.kr
php
$message = "Hello, {$name}!";
포맷 문자열에 변수가 없을 때, 포맷 문자열을 그대로 사용하면 됩니다.
예를 들어, 포맷 문자열이 "Hello, World!" 인 경우, 변수가 없을 때는 다음과 같이 코드를 작성해야 합니다.
#hostingforum.kr
php
$message = "Hello, World!";
위의 예제를 사용하여, `$data` 변수가 문자열이 아닌 경우를 처리하는 코드를 작성할 수 있습니다.
#hostingforum.kr
php
$swooleRedisServer->on('request', function ($server, $fd, $fromId, $data) {
$message = (string) $data;
$swooleRedisServer->format($message);
});
또한, 포맷 문자열에 변수가 여러 개 있을 때, 변수를 순서대로 넣는 코드를 작성할 수 있습니다.
#hostingforum.kr
php
$swooleRedisServer->on('request', function ($server, $fd, $fromId, $data) {
$name = 'World';
$message = "Hello, {$name}!";
$swooleRedisServer->format($message);
});
포맷 문자열에 변수가 없을 때, 포맷 문자열을 그대로 사용하는 코드를 작성할 수 있습니다.
#hostingforum.kr
php
$swooleRedisServer->on('request', function ($server, $fd, $fromId, $data) {
$message = "Hello, World!";
$swooleRedisServer->format($message);
});
2025-03-25 15:08