Skip to content

Commit

Permalink
add temporary invite use idRedisKey
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaomlove committed Feb 26, 2024
1 parent ba1f6e5 commit 86782e7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
11 changes: 5 additions & 6 deletions app/Console/Commands/InviteAddTemporary.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ class InviteAddTemporary extends Command
*
* @var string
*/
protected $signature = 'invite:tmp {uid} {days} {count}';
protected $signature = 'invite:tmp {idRedisKey} {days} {count}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Add temporary invite to user, argument: uid(Multiple comma separated), days, count';
protected $description = 'Add temporary invite to user, argument: idRedisKey, days, count';

/**
* Execute the console command.
Expand All @@ -28,14 +28,13 @@ class InviteAddTemporary extends Command
*/
public function handle()
{
$uid = $this->argument('uid');
$idRedisKey = $this->argument('idRedisKey');
$days = $this->argument('days');
$count = $this->argument('count');
$log = "uid: $uid, days: $days, count: $count";
$log = "idRedisKey: $idRedisKey, days: $days, count: $count";
$this->info($log);
do_log($log);
$uidArr = preg_split('/[\s,]+/', $uid);
GenerateTemporaryInvite::dispatch($uidArr, $days, $count);
GenerateTemporaryInvite::dispatch($idRedisKey, $days, $count);
return Command::SUCCESS;
}
}
15 changes: 11 additions & 4 deletions app/Jobs/GenerateTemporaryInvite.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Str;
use Nexus\Database\NexusDB;

class GenerateTemporaryInvite implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

private int $count;

private array $uidArr;
private string $idRedisKey;

private int $days;

Expand All @@ -28,9 +29,9 @@ class GenerateTemporaryInvite implements ShouldQueue
*
* @return void
*/
public function __construct(array $uidArr, int $days, int $count)
public function __construct(string $idRedisKey, int $days, int $count)
{
$this->uidArr = $uidArr;
$this->idRedisKey = $idRedisKey;
$this->days = $days;
$this->count = $count;
}
Expand All @@ -57,7 +58,13 @@ public function retryUntil()
public function handle()
{
$toolRep = new ToolRepository();
foreach ($this->uidArr as $uid) {
$idStr = NexusDB::cache_get($this->idRedisKey);
if (empty($idStr)) {
do_log("no idStr of idRedisKey: {$this->idRedisKey}...");
return;
}
$idArr = explode(",", $idStr);
foreach ($idArr as $uid) {
try {
$hashArr = $toolRep->generateUniqueInviteHash([], $this->count, $this->count);
$data = [];
Expand Down
4 changes: 3 additions & 1 deletion public/take-increment-bulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@
break;
}
$idStr = implode(',', $idArr);
$idRedisKey = sprintf("temporary_invite:%d", microtime(true));
\Nexus\Database\NexusDB::cache_put($idRedisKey, $idStr);
if ($isTypeTmpInvite) {
$command = sprintf(
'invite:tmp %s %s %s',
$idStr, $duration, $amount
$idRedisKey, $duration, $amount
);
$output = executeCommand($command, 'string', true);
do_log(sprintf('command: %s, output: %s', $command, $output));
Expand Down

0 comments on commit 86782e7

Please sign in to comment.