Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
150 views
in Technique[技术] by (71.8m points)

How to find azure redis cache total memory using redis commond

I have started to learn Redis cache I had the plan to get total azure Redis cache memory through node js API call I have searched but I am not getting clear vision could you assist me how I can do this.

question from:https://stackoverflow.com/questions/66059151/how-to-find-azure-redis-cache-total-memory-using-redis-commond

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

1. Create Azure Redis Cache on portal.

2. Click Console.

enter image description here

3. Input info memory command, and check the output info. I believe maxmemory is you want.

enter image description here

4. Test Code.

    '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("
Cache 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( "
" );
        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. Test Result.

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...