【问题标题】:How to find azure redis cache total memory using redis commond如何使用 redis 命令查找 azure redis 缓存总内存
【发布时间】:2021-05-09 13:14:38
【问题描述】:

我已经开始学习 Redis 缓存,我曾计划通过我搜索过的节点 js API 调用来获得总的 Azure Redis 缓存内存,但我没有得到清晰的愿景,你能帮助我如何做到这一点。

【问题讨论】:

    标签: azure-redis-cache redis-cache


    【解决方案1】:

    1.在门户上创建Azure Redis Cache

    2。点击Console

    3.输入info memory 命令,查看输出信息。我相信maxmemory是你想要的。

    4.测试代码。

        'use strict'
    
        var redis = require("redis");
        var bluebird = require("bluebird");
    
        const PORT=6380;
        const REDISCACHEHOSTNAME="jas***.windows.net";
        const REDISCACHEKEY="+tDRMmw********56ooVF7c=";
    
        // Convert Redis client API to use promises, to make it usable with async/await syntax
        bluebird.promisifyAll(redis.RedisClient.prototype);
        bluebird.promisifyAll(redis.Multi.prototype);
    
        async function testCache() {
            var cacheConnection = redis.createClient(PORT, REDISCACHEHOSTNAME, 
                {auth_pass: REDISCACHEKEY, tls: {servername: REDISCACHEHOSTNAME}});
    
            // Simple PING command
            console.log("\nCache command: info memory");
            let response=await cacheConnection.sendCommandAsync("info",["memory"]);
            let obj=parseInfo(response);
            console.log("Cache response : maxmemory = " + obj.maxmemory);
        }
    
        function parseInfo( info ) {
            var lines = info.split( "\r\n" );
            var obj = { };
            for ( var i = 0, l = info.length; i < l; i++ ) {
                var line = lines[ i ];
                if ( line && line.split ) {
                    line = line.split( ":" );
                    if ( line.length > 1 ) {
                        var key = line.shift( );
                        obj[ key ] = line.join( ":" );
                    }
                }
            }
            return obj;
        }
    
        testCache();
    

    5.测试结果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-16
      • 1970-01-01
      • 2016-06-04
      • 1970-01-01
      • 2015-12-08
      • 2016-09-10
      • 2019-05-17
      • 1970-01-01
      相关资源
      最近更新 更多