Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vipin93's avatar
Level 13

Have anyone using redis as database for particular table?

I try to implement attendance system in my app so attendance will taken by teacher daily so its lots of data so think redis is better choice but how to use redish for this operation I don't know any one have idea please share here in my controller which I want to use redis here is my controller

public function student_take_attendence_post(Request $r)
    {
          $this->validate($r,[

            'date'   =>      'required|date_format:d/m/Y',
            'marked' =>      'required',
        ]);

           $user = Auth::user();

            $students = Student::whereHas('studentacadmic.courses.teacheracadmic',
                             function($q) use($user){
                               
                               $q->where('teacher_id', $user->id);
                               
                             })->whereHas('studentacadmic', function($q) use($user){
                                $q->where('section_id',$user->teacheracadmic->section_id);
                             })->latest()->get();

               $d = $r->date; 

        $dates = str_replace('/', '-', $d);

        $date = date('Y-m-d', strtotime($dates));
                   
            foreach ($students as $key => $value) {
                $ids = $value->id;
                //dd($ids);
             $todayattendence = StudentAttendence::
                           where('student_id', $ids)
                           ->whereDate('date' , $date)->first();
            }
                     //dd($todayattendence);                            

        if ($todayattendence) {

            flash('You already marked attendence for date of '. $d ); 
                        
           return back();          

        } else{
            
             foreach ($students as $key => $value)
           { 
             $data = [

              'date'       => $r->date,
              'marked'     => $r->marked [$key],
              'taker_id'   => $user->id
             ];

             $value->studentattendence()->create($data);

           }  

           $studentss = Student::whereHas('studentattendence',function($q) use($date){
                                   $q->whereDate('date',$date)
                                     ->where('marked',0);
                                 })->select('emer_no','name')->get()->toArray();

          $numbers = array_pluck($studentss, 'emer_no');

         if ($studentss) {
            event(new StudentAbsent($numbers,$d));
         }

           flash()->success('Successfully attendence marked'); 
          return back(); 
         
        } 
                   
    }  

my students_attendences table

 Schema::create('student_attendences', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('student_id')->unsigned()->index();
            $table->integer('taker_id')->unsigned()->index();
            $table->date('date');
            $table->boolean('marked');
            $table->timestamps();
        })
0 likes
8 replies
ohffs's avatar

Why are you wanting to use redis? Redis is really useful for a lot of things, but I'm not seeing why you would use it in this case rather than just an sql table?

vipin93's avatar
Level 13

@ohffs actually i going to use attendance system and they have every day attendance so it's take space and my lots of query suppose I have 100k user and if I take attendance of every user per day then I think redis or another database is useful so I think redis is bettor option

ohffs's avatar

Do you actually have 100k users? And do you have servers with enough RAM to hold it all in Redis? How are you going to structure the data in Redis?

vipin93's avatar
Level 13

not now but in future we have more than 100k users just here I want to test and learn

apsdsm's avatar

If you're dead set on doing this with Redis (at least as a learning exercise) then you should investigate the \Cache facade, and how to set that in the Laravel config file. read this: https://laravel.com/docs/5.4/cache

You'll also want to read into snapshotting Redis states: https://redis.io/topics/persistence

Redis is just a KVP store, however, so you cannot use the same queries that you're using in your current code. You'll have to do all that manually.

That said, Redis is not designed for what you want to do. I applaud that you want to learn how to use Redis, but honestly you're trying to tighten a screw with a hammer.

Even if you were to store that data in Redis, Redis only maintains data for as long as the server isn't reset. You will eventually have to write that data to a database or file at some point, and that will add another layer of complexity to your application.

You also have a problem where for each new student attendance that is taken, you need to have more available memory to store the overall state of attendance. So if you DO indeed have 100k users, be prepared to upgrade your AWS memory every few days.

In my humble opinion a Redis persistent store is better for data that does not change or grow regularly.

Good luck though!

dipankarb's avatar

First of all redis is not persistence and its in-memory database. Hope you know that. For this if Server goes off all data gone.

Overall its not good idea I think. Use PostgreSQL it will work without no issue I guess.

vipin93's avatar
Level 13

as I have to noticed that redis is memory base driver, and it's not for big data as database so , it's good idea to use mysql for my this operation or I have to use noSQL like mongoDB?

Please or to participate in this conversation.