Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7590025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:18:17+00:00 2026-05-30T20:18:17+00:00

I’m making a game that uses redis to store game state. It keeps track

  • 0

I’m making a game that uses redis to store game state. It keeps track of locations and players pretty well, but I don’t have a good way to clean up inactive players.

Every time a player moves (it’s a semi-slow moving game. Think 1-5 frames per second), I update a hash with the new location and remove the old location key.

What would be the best way to keep track of active players? I’ve thought of the following

  1. Set some key on the user to expire. Update every heartbeat or move. Problem is the locations are stored in a hash, so if the user key expires the player will still be in the same spot.
  2. Same, but use pub/sub to listen for the expiration and finish cleaning up (seems overly complicated)
  3. Store heartbeats in a sorted set, have a process run every X seconds to look for old players. Update score every heartbeat.
  4. Completely revamp the way I store locations so I can use expire.. somehow?

Any other ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T20:18:18+00:00Added an answer on May 30, 2026 at 8:18 pm

    Perhaps use separate redis data structures (though same database) to track user activity
    and user location.

    For instance, track users currently online separately using redis sets:

    [my code snippet is in python using the redis-python bindings, and adapted from example app in Flask (python micro-framework); example app and the framework both by Armin Ronacher.]

    from redis import Redis as redis
    from time import time
    
    r1 = redis(db=1)
    

    when the function below is called, it creates a key based on current unix time in minutes
    and then adds a user to a set having that key. I would imagine you would want to
    set the expiry at say 10 minutes, so at any given time, you have 10 keys live
    (one per minute).

    def record_online(player_id):
        current_time = int(time.time())
        expires = now + 600     # 10 minutes TTL
        k1 = "playersOnline:{0}".format(now//60)
        r1.sadd(k1, player_id)
        r1.expire(k1, expires)
    

    So to get all active users just union all of the live keys (in this example, that’s 10
    keys, a purely arbitrary number), like so:

    def active_users(listOfKeys):
        return r1.sunion(listOfKeys)
    

    This solves your “clean-up” issues because of the TTL–the inactive users would not appear in your live keys because they constantly recycle–i.e., in active users are only keyed to old timestamps which don’t persist in this example (but perhaps are written to a permanent store by redis before expiry). In any event, this clears inactive users from your active redis db.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I need to clean up various Word 'smart' characters in user input, including but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.