Skip to content

Commit

Permalink
Use redis ConnectionManager
Browse files Browse the repository at this point in the history
  • Loading branch information
Sliman4 committed May 3, 2024
1 parent 3347eda commit db8ee74
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async-trait = "0.1.80"
tokio = { version = "1.37.0", features = ["macros", "rt-multi-thread"] }
log = "0.4.21"
simple_logger = "5.0.0"
redis = { version = "0.25.3", features = [ "tokio-rustls-comp" ] }
redis = { version = "0.25.3", features = [ "tokio-rustls-comp", "connection-manager" ] }
serde = { version = "1.0.199", features = [ "derive" ] }
serde_json = "1.0.116"
dotenv = "0.15.0"
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use inindexer::{
run_indexer, AutoContinue, BlockIterator, CompleteTransaction, Indexer, IndexerOptions,
PreprocessTransactionsSettings, TransactionReceipt,
};
use redis::aio::ConnectionManager;
use redis_handler::PushToRedisStream;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -191,7 +192,7 @@ async fn main() {
std::env::var("REDIS_URL").expect("No $REDIS_URL environment variable set"),
)
.unwrap();
let connection = client.get_multiplexed_tokio_connection().await.unwrap();
let connection = ConnectionManager::new(client).await.unwrap();

let mut indexer = NftIndexer(PushToRedisStream::new(connection, 10_000));

Expand Down
12 changes: 6 additions & 6 deletions src/redis_handler.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use async_trait::async_trait;
use inindexer::near_utils::{NftBurnEvent, NftMintEvent};
use redis::{aio::MultiplexedConnection, streams::StreamMaxlen, AsyncCommands};
use redis::{streams::StreamMaxlen, AsyncCommands};

use crate::{EventContext, ExtendedNftTransferEvent, NftEventHandler};

pub struct PushToRedisStream {
connection: MultiplexedConnection,
pub struct PushToRedisStream<C: AsyncCommands + Sync> {
connection: C,
max_stream_size: usize,
}

impl PushToRedisStream {
pub fn new(connection: MultiplexedConnection, max_stream_size: usize) -> Self {
impl<C: AsyncCommands + Sync> PushToRedisStream<C> {
pub fn new(connection: C, max_stream_size: usize) -> Self {
Self {
connection,
max_stream_size,
Expand All @@ -19,7 +19,7 @@ impl PushToRedisStream {
}

#[async_trait]
impl NftEventHandler for PushToRedisStream {
impl<C: AsyncCommands + Sync> NftEventHandler for PushToRedisStream<C> {
async fn handle_mint(&mut self, mint: NftMintEvent, context: EventContext) {
let response: String = self
.connection
Expand Down

0 comments on commit db8ee74

Please sign in to comment.