Created
July 11, 2010 09:42
-
-
Save nrk/471425 to your computer and use it in GitHub Desktop.
Parse the string returned by INFO (warning: code written by a newbie to Scala :-))
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| redis_version:1.3.15 | |
| redis_git_sha1:00000000 | |
| redis_git_dirty:0 | |
| arch_bits:32 | |
| multiplexing_api:select | |
| process_id:3160 | |
| uptime_in_seconds:48 | |
| uptime_in_days:0 | |
| connected_clients:1 | |
| connected_slaves:0 | |
| blocked_clients:0 | |
| used_memory:451264 | |
| used_memory_human:440.69K | |
| changes_since_last_save:0 | |
| bgsave_in_progress:0 | |
| last_save_time:1278840545 | |
| bgrewriteaof_in_progress:0 | |
| total_connections_received:1 | |
| total_commands_processed:1 | |
| expired_keys:0 | |
| hash_max_zipmap_entries:64 | |
| hash_max_zipmap_value:512 | |
| pubsub_channels:0 | |
| pubsub_patterns:0 | |
| vm_enabled:0 | |
| role:master | |
| db0:keys=1,expires=0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // parse the string returned by INFO | |
| import com.redis._ | |
| val redis = new RedisClient() | |
| val rawInfo = redis.info.get | |
| val GenericEntry = """(\w+):(.+)\r\n""".r | |
| val NumericEntry = """(\w+):(\d+)\r\n""".r | |
| val DatabaseEntry = """(db\d+):(.+)\r\n""".r | |
| val DatabaseKV = """(\w+)=(\d+)""".r | |
| val info = Map.empty ++ (for (kv <- GenericEntry findAllIn rawInfo) | |
| yield kv match { | |
| case DatabaseEntry(k, v) => (k, Map.empty ++ (for (dbkv <- DatabaseKV findAllIn v) | |
| yield dbkv match { | |
| case DatabaseKV(dbk, dbv) => (dbk, dbv.toInt) | |
| } | |
| )) | |
| case NumericEntry(k, v) => k -> v.toInt | |
| case GenericEntry(k, v) => k -> v | |
| } | |
| ) | |
| val arch_bits = info("arch_bits").asInstanceOf[Int] // arch_bits: Int = 32 | |
| val role = info("role").asInstanceOf[String] // role: String = master | |
| val db0_keys = info("db0").asInstanceOf[Map[String,Int]]("keys") // db0_keys: Int = 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment