Fix Redis instance

This commit is contained in:
Ben van Hartingsveldt 2025-05-25 19:51:23 +02:00
parent 64534e5b99
commit 3a6e10b467
No known key found for this signature in database
GPG key ID: 261AA214130CE7AB

View file

@ -32,8 +32,8 @@ class BlockCommand extends Command{
const scriptAddress = [5, 122]; const scriptAddress = [5, 122];
//public static string $redisurl; protected static $redis;
public static string $rpcurl; public static $rpcurl;
/** /**
* The console command description. * The console command description.
@ -49,7 +49,7 @@ class BlockCommand extends Command{
public function __construct(){ public function __construct(){
parent::__construct(); parent::__construct();
//self::$redisurl = config('database.redis.default.url'); self::$redis = Redis::connection()->client();
self::$rpcurl = config('lbry.rpc_url'); self::$rpcurl = config('lbry.rpc_url');
} }
@ -155,10 +155,9 @@ class BlockCommand extends Command{
// start with all txs // start with all txs
$decoder_url = 'http://127.0.0.1:5000'; $decoder_url = 'http://127.0.0.1:5000';
$redis = Redis::connection()->client();
$conn = DB::connection(); $conn = DB::connection();
$redis_key = 'claim.oid'; $redis_key = 'claim.oid';
$last_claim_oid = $redis->exists($redis_key) ? $redis->get($redis_key) : 0; $last_claim_oid = self::$redis->exists($redis_key) ? self::$redis->get($redis_key) : 0;
try { try {
$stmt = $conn->getPdo()->query('SELECT COUNT(Id) AS RecordCount FROM Outputs WHERE Id > ?', [$last_claim_oid]); $stmt = $conn->getPdo()->query('SELECT COUNT(Id) AS RecordCount FROM Outputs WHERE Id > ?', [$last_claim_oid]);
$count = min(500000, $stmt->fetch(PDO::FETCH_OBJ)->RecordCount); $count = min(500000, $stmt->fetch(PDO::FETCH_OBJ)->RecordCount);
@ -303,7 +302,7 @@ class BlockCommand extends Command{
echo "[$idx_str/$count] no claim found for [$out->Hash:$vout]. Skipping.\n"; echo "[$idx_str/$count] no claim found for [$out->Hash:$vout]. Skipping.\n";
} }
$redis->set($redis_key, $out->Id); self::$redis->set($redis_key, $out->Id);
} }
} catch (Exception $e) { } catch (Exception $e) {
// continue // continue
@ -407,11 +406,10 @@ class BlockCommand extends Command{
public function fixzerooutputs(): void{ public function fixzerooutputs(): void{
self::lock('zerooutputs'); self::lock('zerooutputs');
$redis = Redis::connection()->client();
$conn = DB::connection(); $conn = DB::connection();
/** 2017-06-12 21:38:07 **/ /** 2017-06-12 21:38:07 **/
//$last_fixed_txid = $redis->exists('fix.txid') ? $redis->get('fix.txid') : 0; //$last_fixed_txid = self::$redis->exists('fix.txid') ? self::$redis->get('fix.txid') : 0;
try { try {
$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']); $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']);
$txids = $stmt->fetchAll(PDO::FETCH_OBJ); $txids = $stmt->fetchAll(PDO::FETCH_OBJ);
@ -663,7 +661,7 @@ class BlockCommand extends Command{
} }
} }
//$redis->set('fix.txid', $txid); //self::$redis->set('fix.txid', $txid);
$diff_ms = (round(microtime(true) * 1000)) - $start_ms; $diff_ms = (round(microtime(true) * 1000)) - $start_ms;
$total_diff += $diff_ms; $total_diff += $diff_ms;
echo "update took {$diff_ms}ms. Total {$total_diff} ms.\n"; echo "update took {$diff_ms}ms. Total {$total_diff} ms.\n";
@ -1026,7 +1024,6 @@ class BlockCommand extends Command{
//$conn->execute('SET foreign_key_checks = 0'); //$conn->execute('SET foreign_key_checks = 0');
//$conn->execute('SET unique_checks = 0'); //$conn->execute('SET unique_checks = 0');
$redis = Redis::connection()->client();
try { try {
$unproc_blocks = Block::query()->select(['Id', 'Height', 'Hash', 'TransactionHashes', 'BlockTime'])->where('TransactionsProcessed',0)->orderBy('Height')->get(); $unproc_blocks = Block::query()->select(['Id', 'Height', 'Hash', 'TransactionHashes', 'BlockTime'])->where('TransactionsProcessed',0)->orderBy('Height')->get();
foreach ($unproc_blocks as $min_block) { foreach ($unproc_blocks as $min_block) {
@ -1066,8 +1063,8 @@ class BlockCommand extends Command{
$total_diff += $diff_ms; $total_diff += $diff_ms;
echo "tx took {$diff_ms}ms. Total {$total_diff}ms. "; echo "tx took {$diff_ms}ms. Total {$total_diff}ms. ";
if (!$data_error && $redis && $redis->sismember(self::mempooltxkey, $tx_hash)) { if (!$data_error && self::$redis && self::$redis->sismember(self::mempooltxkey, $tx_hash)) {
$redis->srem(self::mempooltxkey, $tx_hash); self::$redis->srem(self::mempooltxkey, $tx_hash);
echo "Removed $tx_hash from redis mempooltx.\n"; echo "Removed $tx_hash from redis mempooltx.\n";
} }
@ -1107,8 +1104,8 @@ class BlockCommand extends Command{
$upd_entity->save(); $upd_entity->save();
echo "Done.\n"; echo "Done.\n";
if ($redis && $redis->sismember(self::mempooltxkey, $tx_hash)) { if (self::$redis && self::$redis->sismember(self::mempooltxkey, $tx_hash)) {
$redis->srem(self::mempooltxkey, $tx_hash); self::$redis->srem(self::mempooltxkey, $tx_hash);
echo "Removed $tx_hash from redis mempooltx.\n"; echo "Removed $tx_hash from redis mempooltx.\n";
} }
} else { } else {
@ -1134,7 +1131,7 @@ class BlockCommand extends Command{
self::lock('parsenewblocks'); self::lock('parsenewblocks');
echo "Parsing new blocks...\n"; echo "Parsing new blocks...\n";
$redis = Redis::connection()->client(); self::$redis = Redis::connection()->client();
try { try {
// Get the best block hash // Get the best block hash
$req = ['method' => 'getbestblockhash', 'params' => [],'id'=>rand()]; $req = ['method' => 'getbestblockhash', 'params' => [],'id'=>rand()];
@ -1279,8 +1276,8 @@ class BlockCommand extends Command{
} }
// Remove from redis if present // Remove from redis if present
if (!$data_error && $redis && $redis->sismember(self::mempooltxkey, $tx_hash)) { if (!$data_error && self::$redis && self::$redis->sismember(self::mempooltxkey, $tx_hash)) {
$redis->srem(self::mempooltxkey, $tx_hash); self::$redis->srem(self::mempooltxkey, $tx_hash);
echo "Removed $tx_hash from redis mempooltx.\n"; echo "Removed $tx_hash from redis mempooltx.\n";
} }
} }
@ -1305,7 +1302,6 @@ class BlockCommand extends Command{
self::lock('forevermempool'); self::lock('forevermempool');
$conn = DB::connection(); $conn = DB::connection();
$redis = Redis::connection()->client();
while (true) { while (true) {
try { try {
@ -1318,16 +1314,16 @@ class BlockCommand extends Command{
if (count($txs) === 0) { if (count($txs) === 0) {
// If no transactions found, that means there's nothing in the mempool. Clear redis // If no transactions found, that means there's nothing in the mempool. Clear redis
if ($redis) { if (self::$redis) {
$redis->del(self::mempooltxkey); self::$redis->del(self::mempooltxkey);
echo "Empty rawmempool. Cleared mempool txs from redis.\n"; echo "Empty rawmempool. Cleared mempool txs from redis.\n";
} }
} }
foreach ($txs as $tx_hash) { foreach ($txs as $tx_hash) {
// Check redis mempool txs // Check redis mempool txs
if ($redis && $redis->exists(self::mempooltxkey)) { if (self::$redis && self::$redis->exists(self::mempooltxkey)) {
if ($redis->sismember(self::mempooltxkey, $tx_hash)) { if (self::$redis->sismember(self::mempooltxkey, $tx_hash)) {
echo "Found processed tx hash: $tx_hash. Skipping.\n"; echo "Found processed tx hash: $tx_hash. Skipping.\n";
continue; continue;
} }
@ -1354,8 +1350,8 @@ class BlockCommand extends Command{
$conn->commit(); $conn->commit();
// Save to redis to prevent the DB from behing hit again // Save to redis to prevent the DB from behing hit again
if ($redis) { if (self::$redis) {
$redis->sadd(self::mempooltxkey, $tx_hash); self::$redis->sadd(self::mempooltxkey, $tx_hash);
} }
} }
} }