Skip to content

Commit 3a6e10b

Browse files
committed
Fix Redis instance
1 parent 64534e5 commit 3a6e10b

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

app/Console/Commands/BlockCommand.php

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ class BlockCommand extends Command{
3232

3333
const scriptAddress = [5, 122];
3434

35-
//public static string $redisurl;
36-
public static string $rpcurl;
35+
protected static $redis;
36+
public static $rpcurl;
3737

3838
/**
3939
* The console command description.
@@ -49,7 +49,7 @@ class BlockCommand extends Command{
4949

5050
public function __construct(){
5151
parent::__construct();
52-
//self::$redisurl = config('database.redis.default.url');
52+
self::$redis = Redis::connection()->client();
5353
self::$rpcurl = config('lbry.rpc_url');
5454
}
5555

@@ -155,10 +155,9 @@ public function buildclaimindex(): void{
155155

156156
// start with all txs
157157
$decoder_url = 'http://127.0.0.1:5000';
158-
$redis = Redis::connection()->client();
159158
$conn = DB::connection();
160159
$redis_key = 'claim.oid';
161-
$last_claim_oid = $redis->exists($redis_key) ? $redis->get($redis_key) : 0;
160+
$last_claim_oid = self::$redis->exists($redis_key) ? self::$redis->get($redis_key) : 0;
162161
try {
163162
$stmt = $conn->getPdo()->query('SELECT COUNT(Id) AS RecordCount FROM Outputs WHERE Id > ?', [$last_claim_oid]);
164163
$count = min(500000, $stmt->fetch(PDO::FETCH_OBJ)->RecordCount);
@@ -303,7 +302,7 @@ public function buildclaimindex(): void{
303302
echo "[$idx_str/$count] no claim found for [$out->Hash:$vout]. Skipping.\n";
304303
}
305304

306-
$redis->set($redis_key, $out->Id);
305+
self::$redis->set($redis_key, $out->Id);
307306
}
308307
} catch (Exception $e) {
309308
// continue
@@ -407,11 +406,10 @@ protected function _getclaimfortxout($pubkeyasm, $tx_hash, $vout, $tx_time = nul
407406
public function fixzerooutputs(): void{
408407
self::lock('zerooutputs');
409408

410-
$redis = Redis::connection()->client();
411409
$conn = DB::connection();
412410

413411
/** 2017-06-12 21:38:07 **/
414-
//$last_fixed_txid = $redis->exists('fix.txid') ? $redis->get('fix.txid') : 0;
412+
//$last_fixed_txid = self::$redis->exists('fix.txid') ? self::$redis->get('fix.txid') : 0;
415413
try {
416414
$stmt = $conn->getPdo()->query('SELECT Id FROM Transactions WHERE Created >= ? AND Created <= ? LIMIT 1000000', ['2017-06-15 20:44:50', '2017-06-16 08:02:09']);
417415
$txids = $stmt->fetchAll(PDO::FETCH_OBJ);
@@ -663,7 +661,7 @@ public function fixzerooutputs(): void{
663661
}
664662
}
665663

666-
//$redis->set('fix.txid', $txid);
664+
//self::$redis->set('fix.txid', $txid);
667665
$diff_ms = (round(microtime(true) * 1000)) - $start_ms;
668666
$total_diff += $diff_ms;
669667
echo "update took {$diff_ms}ms. Total {$total_diff} ms.\n";
@@ -1026,7 +1024,6 @@ public function parsetxs(): void{
10261024
//$conn->execute('SET foreign_key_checks = 0');
10271025
//$conn->execute('SET unique_checks = 0');
10281026

1029-
$redis = Redis::connection()->client();
10301027
try {
10311028
$unproc_blocks = Block::query()->select(['Id', 'Height', 'Hash', 'TransactionHashes', 'BlockTime'])->where('TransactionsProcessed',0)->orderBy('Height')->get();
10321029
foreach ($unproc_blocks as $min_block) {
@@ -1066,8 +1063,8 @@ public function parsetxs(): void{
10661063
$total_diff += $diff_ms;
10671064
echo "tx took {$diff_ms}ms. Total {$total_diff}ms. ";
10681065

1069-
if (!$data_error && $redis && $redis->sismember(self::mempooltxkey, $tx_hash)) {
1070-
$redis->srem(self::mempooltxkey, $tx_hash);
1066+
if (!$data_error && self::$redis && self::$redis->sismember(self::mempooltxkey, $tx_hash)) {
1067+
self::$redis->srem(self::mempooltxkey, $tx_hash);
10711068
echo "Removed $tx_hash from redis mempooltx.\n";
10721069
}
10731070

@@ -1107,8 +1104,8 @@ public function parsetxs(): void{
11071104
$upd_entity->save();
11081105
echo "Done.\n";
11091106

1110-
if ($redis && $redis->sismember(self::mempooltxkey, $tx_hash)) {
1111-
$redis->srem(self::mempooltxkey, $tx_hash);
1107+
if (self::$redis && self::$redis->sismember(self::mempooltxkey, $tx_hash)) {
1108+
self::$redis->srem(self::mempooltxkey, $tx_hash);
11121109
echo "Removed $tx_hash from redis mempooltx.\n";
11131110
}
11141111
} else {
@@ -1134,7 +1131,7 @@ public function parsenewblocks(): void{
11341131
self::lock('parsenewblocks');
11351132

11361133
echo "Parsing new blocks...\n";
1137-
$redis = Redis::connection()->client();
1134+
self::$redis = Redis::connection()->client();
11381135
try {
11391136
// Get the best block hash
11401137
$req = ['method' => 'getbestblockhash', 'params' => [],'id'=>rand()];
@@ -1279,8 +1276,8 @@ public function parsenewblocks(): void{
12791276
}
12801277

12811278
// Remove from redis if present
1282-
if (!$data_error && $redis && $redis->sismember(self::mempooltxkey, $tx_hash)) {
1283-
$redis->srem(self::mempooltxkey, $tx_hash);
1279+
if (!$data_error && self::$redis && self::$redis->sismember(self::mempooltxkey, $tx_hash)) {
1280+
self::$redis->srem(self::mempooltxkey, $tx_hash);
12841281
echo "Removed $tx_hash from redis mempooltx.\n";
12851282
}
12861283
}
@@ -1305,7 +1302,6 @@ public function forevermempool(): void{
13051302
self::lock('forevermempool');
13061303

13071304
$conn = DB::connection();
1308-
$redis = Redis::connection()->client();
13091305

13101306
while (true) {
13111307
try {
@@ -1318,16 +1314,16 @@ public function forevermempool(): void{
13181314

13191315
if (count($txs) === 0) {
13201316
// If no transactions found, that means there's nothing in the mempool. Clear redis
1321-
if ($redis) {
1322-
$redis->del(self::mempooltxkey);
1317+
if (self::$redis) {
1318+
self::$redis->del(self::mempooltxkey);
13231319
echo "Empty rawmempool. Cleared mempool txs from redis.\n";
13241320
}
13251321
}
13261322

13271323
foreach ($txs as $tx_hash) {
13281324
// Check redis mempool txs
1329-
if ($redis && $redis->exists(self::mempooltxkey)) {
1330-
if ($redis->sismember(self::mempooltxkey, $tx_hash)) {
1325+
if (self::$redis && self::$redis->exists(self::mempooltxkey)) {
1326+
if (self::$redis->sismember(self::mempooltxkey, $tx_hash)) {
13311327
echo "Found processed tx hash: $tx_hash. Skipping.\n";
13321328
continue;
13331329
}
@@ -1354,8 +1350,8 @@ public function forevermempool(): void{
13541350
$conn->commit();
13551351

13561352
// Save to redis to prevent the DB from behing hit again
1357-
if ($redis) {
1358-
$redis->sadd(self::mempooltxkey, $tx_hash);
1353+
if (self::$redis) {
1354+
self::$redis->sadd(self::mempooltxkey, $tx_hash);
13591355
}
13601356
}
13611357
}

0 commit comments

Comments
 (0)