/** * Get market price from Redis with database fallback * @param string $market Market code (e.g., 'OP', 'BUFF', 'DM', 'SP') * @param int $itemID Item ID * @param object $redis Redis connection * @param object $dbh Database connection * @return array|null Market price data or null */ function getMarketPrice($market, $itemID, $redis, $dbh) { // Try Redis first (fast cache) $cache_key = $market . '_' . $itemID; $data = json_decode($redis->get($cache_key), true); // If Redis has the data, return it if ($data && isset($data['amount'])) { return $data; } // Fallback to database // Map market codes to site names in pricelist.list table $site_map = [ 'OP' => 'opskins', 'BUFF' => 'buff', 'DM' => 'dmarket', 'SP' => 'skinport', 'SBAY' => 'shadowpay', 'WM' => 'whitemarket', 'CSM' => 'csmoney' ]; $site = isset($site_map[$market]) ? $site_map[$market] : strtolower($market); try { $stmt = $dbh->prepare(" SELECT price, market_name FROM pricelist.list WHERE site = ? AND item_id = ? ORDER BY last_updated DESC LIMIT 1 "); $stmt->execute([$site, $itemID]); $row = $stmt->fetch(PDO::FETCH_ASSOC); if ($row && $row['price']) { $data = [ 'amount' => $row['price'], 'market_name' => $row['market_name'] ]; // Cache it in Redis for next time (1 hour expiry) $redis->setex($cache_key, 3600, json_encode($data)); return $data; } } catch (Exception $e) { // If DB query fails, return null error_log("getMarketPrice DB fallback failed: " . $e->getMessage()); } return null; } Compare CS2 Skin Prices Side-by-Side | SteamAnalyst
SteamAnalyst.com
Market Name Avg. 7 days SM Listing Price Volume Trend 7 days
AUG | Akihabara Accept (Factory New) $3,916.23 N/A N/A
AUG | Akihabara Accept (Minimal Wear) $1,474.42 N/A N/A
AUG | Akihabara Accept (Field-Tested) $644.34 N/A N/A
AUG | Akihabara Accept (Well-Worn) $460.23 N/A N/A
AUG | Akihabara Accept (Battle-Scarred) $319.25 N/A N/A