So I have the following code:
use Predis\Collection\Iterator;
static function GetRecords($email) {
//this gets the redis client in read/write mode
$redis = GetRedisClient(true);
$glob = "users:{$email}*";
$i = 0;
foreach(new Iterator\Keyspace($redis, $glob) as $key) {
echo "$key<br>";
}
}
but for some reason it's not working. The script just hangs forever as if it's in an infinite loop and nothing happens. When I do a:
print_r(new Iterator\Keyspace($redis, $glob));
it prints out an object instead of an array of keys. I'm not sure what to do to iterate through the keys. I have tried the glob from the command line and it works just fine, it's PHP that's giving me trouble.
edit: here is the output for the print_r:
Predis\Collection\Iterator\Keyspace Object
(
[client:protected] => Predis\Client Object
(
[connection:protected] => Predis\Connection\StreamConnection Object
(
[resource:Predis\Connection\AbstractConnection:private] => Resource id #34
[cachedId:Predis\Connection\AbstractConnection:private] =>
[parameters:protected] => Predis\Connection\Parameters Object
(
[parameters:Predis\Connection\Parameters:private] => Array
(
[host] => 127.0.0.1
[port] => 6383
[scheme] => tcp
[timeout] => 5
)
)
[initCommands:protected] => Array
(
)
)
[options:protected] => Predis\Configuration\Options Object
(
[input:protected] => Array
(
)
[options:protected] => Array
(
[connections] => Predis\Connection\Factory Object
(
[schemes:protected] => Array
(
[tcp] => Predis\Connection\StreamConnection
[unix] => Predis\Connection\StreamConnection
[redis] => Predis\Connection\StreamConnection
[http] => Predis\Connection\WebdisConnection
)
)
[profile] => Predis\Profile\RedisVersion300 Object
(
[commands:Predis\Profile\RedisProfile:private] => Array
(
[EXISTS] => Predis\Command\KeyExists
[DEL] => Predis\Command\KeyDelete
[TYPE] => Predis\Command\KeyType
[KEYS] => Predis\Command\KeyKeys
[RANDOMKEY] => Predis\Command\KeyRandom
[RENAME] => Predis\Command\KeyRename
[RENAMENX] => Predis\Command\KeyRenamePreserve
[EXPIRE] => Predis\Command\KeyExpire
[EXPIREAT] => Predis\Command\KeyExpireAt
[TTL] => Predis\Command\KeyTimeToLive
[MOVE] => Predis\Command\KeyMove
[SORT] => Predis\Command\KeySort
[DUMP] => Predis\Command\KeyDump
[RESTORE] => Predis\Command\KeyRestore
[SET] => Predis\Command\StringSet
[SETNX] => Predis\Command\StringSetPreserve
[MSET] => Predis\Command\StringSetMultiple
[MSETNX] => Predis\Command\StringSetMultiplePreserve
[GET] => Predis\Command\StringGet
[MGET] => Predis\Command\StringGetMultiple
[GETSET] => Predis\Command\StringGetSet
[INCR] => Predis\Command\StringIncrement
[INCRBY] => Predis\Command\StringIncrementBy
[DECR] => Predis\Command\StringDecrement
[DECRBY] => Predis\Command\StringDecrementBy
[RPUSH] => Predis\Command\ListPushTail
[LPUSH] => Predis\Command\ListPushHead
[LLEN] => Predis\Command\ListLength
[LRANGE] => Predis\Command\ListRange
[LTRIM] => Predis\Command\ListTrim
[LINDEX] => Predis\Command\ListIndex
[LSET] => Predis\Command\ListSet
[LREM] => Predis\Command\ListRemove
[LPOP] => Predis\Command\ListPopFirst
[RPOP] => Predis\Command\ListPopLast
[RPOPLPUSH] => Predis\Command\ListPopLastPushHead
[SADD] => Predis\Command\SetAdd
[SREM] => Predis\Command\SetRemove
[SPOP] => Predis\Command\SetPop
[SMOVE] => Predis\Command\SetMove
[SCARD] => Predis\Command\SetCardinality
[SISMEMBER] => Predis\Command\SetIsMember
[SINTER] => Predis\Command\SetIntersection
[SINTERSTORE] => Predis\Command\SetIntersectionStore
[SUNION] => Predis\Command\SetUnion
[SUNIONSTORE] => Predis\Command\SetUnionStore
[SDIFF] => Predis\Command\SetDifference
[SDIFFSTORE] => Predis\Command\SetDifferenceStore
[SMEMBERS] => Predis\Command\SetMembers
[SRANDMEMBER] => Predis\Command\SetRandomMember
[ZADD] => Predis\Command\ZSetAdd
[ZINCRBY] => Predis\Command\ZSetIncrementBy
[ZREM] => Predis\Command\ZSetRemove
[ZRANGE] => Predis\Command\ZSetRange
[ZREVRANGE] => Predis\Command\ZSetReverseRange
[ZRANGEBYSCORE] => Predis\Command\ZSetRangeByScore
[ZCARD] => Predis\Command\ZSetCardinality
[ZSCORE] => Predis\Command\ZSetScore
[ZREMRANGEBYSCORE] => Predis\Command\ZSetRemoveRangeByScore
[PING] => Predis\Command\ConnectionPing
[AUTH] => Predis\Command\ConnectionAuth
[SELECT] => Predis\Command\ConnectionSelect
[ECHO] => Predis\Command\ConnectionEcho
[QUIT] => Predis\Command\ConnectionQuit
[INFO] => Predis\Command\ServerInfoV26x
[SLAVEOF] => Predis\Command\ServerSlaveOf
[MONITOR] => Predis\Command\ServerMonitor
[DBSIZE] => Predis\Command\ServerDatabaseSize
[FLUSHDB] => Predis\Command\ServerFlushDatabase
[FLUSHALL] => Predis\Command\ServerFlushAll
[SAVE] => Predis\Command\ServerSave
[BGSAVE] => Predis\Command\ServerBackgroundSave
[LASTSAVE] => Predis\Command\ServerLastSave
[SHUTDOWN] => Predis\Command\ServerShutdown
[BGREWRITEAOF] => Predis\Command\ServerBackgroundRewriteAOF
[SETEX] => Predis\Command\StringSetExpire
[APPEND] => Predis\Command\StringAppend
[SUBSTR] => Predis\Command\StringSubstr
[BLPOP] => Predis\Command\ListPopFirstBlocking
[BRPOP] => Predis\Command\ListPopLastBlocking
[ZUNIONSTORE] => Predis\Command\ZSetUnionStore
[ZINTERSTORE] => Predis\Command\ZSetIntersectionStore
[ZCOUNT] => Predis\Command\ZSetCount
[ZRANK] => Predis\Command\ZSetRank
[ZREVRANK] => Predis\Command\ZSetReverseRank
[ZREMRANGEBYRANK] => Predis\Command\ZSetRemoveRangeByRank
[HSET] => Predis\Command\HashSet
[HSETNX] => Predis\Command\HashSetPreserve
[HMSET] => Predis\Command\HashSetMultiple
[HINCRBY] => Predis\Command\HashIncrementBy
[HGET] => Predis\Command\HashGet
[HMGET] => Predis\Command\HashGetMultiple
[HDEL] => Predis\Command\HashDelete
[HEXISTS] => Predis\Command\HashExists
[HLEN] => Predis\Command\HashLength
[HKEYS] => Predis\Command\HashKeys
[HVALS] => Predis\Command\HashValues
[HGETALL] => Predis\Command\HashGetAll
[MULTI] => Predis\Command\TransactionMulti
[EXEC] => Predis\Command\TransactionExec
[DISCARD] => Predis\Command\TransactionDiscard
[SUBSCRIBE] => Predis\Command\PubSubSubscribe
[UNSUBSCRIBE] => Predis\Command\PubSubUnsubscribe
[PSUBSCRIBE] => Predis\Command\PubSubSubscribeByPattern
[PUNSUBSCRIBE] => Predis\Command\PubSubUnsubscribeByPattern
[PUBLISH] => Predis\Command\PubSubPublish
[CONFIG] => Predis\Command\ServerConfig
[PERSIST] => Predis\Command\KeyPersist
[STRLEN] => Predis\Command\StringStrlen
[SETRANGE] => Predis\Command\StringSetRange
[GETRANGE] => Predis\Command\StringGetRange
[SETBIT] => Predis\Command\StringSetBit
[GETBIT] => Predis\Command\StringGetBit
[RPUSHX] => Predis\Command\ListPushTailX
[LPUSHX] => Predis\Command\ListPushHeadX
[LINSERT] => Predis\Command\ListInsert
[BRPOPLPUSH] => Predis\Command\ListPopLastPushHeadBlocking
[ZREVRANGEBYSCORE] => Predis\Command\ZSetReverseRangeByScore
[WATCH] => Predis\Command\TransactionWatch
[UNWATCH] => Predis\Command\TransactionUnwatch
[OBJECT] => Predis\Command\ServerObject
[SLOWLOG] => Predis\Command\ServerSlowlog
[CLIENT] => Predis\Command\ServerClient
[PTTL] => Predis\Command\KeyPreciseTimeToLive
[PEXPIRE] => Predis\Command\KeyPreciseExpire
[PEXPIREAT] => Predis\Command\KeyPreciseExpireAt
[MIGRATE] => Predis\Command\KeyMigrate
[PSETEX] => Predis\Command\StringPreciseSetExpire
[INCRBYFLOAT] => Predis\Command\StringIncrementByFloat
[BITOP] => Predis\Command\StringBitOp
[BITCOUNT] => Predis\Command\StringBitCount
[HINCRBYFLOAT] => Predis\Command\HashIncrementByFloat
[EVAL] => Predis\Command\ServerEval
[EVALSHA] => Predis\Command\ServerEvalSHA
[SCRIPT] => Predis\Command\ServerScript
[TIME] => Predis\Command\ServerTime
[SENTINEL] => Predis\Command\ServerSentinel
[SCAN] => Predis\Command\KeyScan
[BITPOS] => Predis\Command\StringBitPos
[SSCAN] => Predis\Command\SetScan
[ZSCAN] => Predis\Command\ZSetScan
[ZLEXCOUNT] => Predis\Command\ZSetLexCount
[ZRANGEBYLEX] => Predis\Command\ZSetRangeByLex
[ZREMRANGEBYLEX] => Predis\Command\ZSetRemoveRangeByLex
[ZREVRANGEBYLEX] => Predis\Command\ZSetReverseRangeByLex
[HSCAN] => Predis\Command\HashScan
[PUBSUB] => Predis\Command\PubSubPubsub
[PFADD] => Predis\Command\HyperLogLogAdd
[PFCOUNT] => Predis\Command\HyperLogLogCount
[PFMERGE] => Predis\Command\HyperLogLogMerge
[COMMAND] => Predis\Command\ServerCommand
)
[processor:Predis\Profile\RedisProfile:private] =>
)
)
[handlers:protected] => Array
(
[cluster] => Predis\Configuration\ClusterOption
[connections] => Predis\Configuration\ConnectionFactoryOption
[exceptions] => Predis\Configuration\ExceptionsOption
[prefix] => Predis\Configuration\PrefixOption
[profile] => Predis\Configuration\ProfileOption
[replication] => Predis\Configuration\ReplicationOption
)
)
[profile:Predis\Client:private] => Predis\Profile\RedisVersion300 Object
(
[commands:Predis\Profile\RedisProfile:private] => Array
(
[EXISTS] => Predis\Command\KeyExists
[DEL] => Predis\Command\KeyDelete
[TYPE] => Predis\Command\KeyType
[KEYS] => Predis\Command\KeyKeys
[RANDOMKEY] => Predis\Command\KeyRandom
[RENAME] => Predis\Command\KeyRename
[RENAMENX] => Predis\Command\KeyRenamePreserve
[EXPIRE] => Predis\Command\KeyExpire
[EXPIREAT] => Predis\Command\KeyExpireAt
[TTL] => Predis\Command\KeyTimeToLive
[MOVE] => Predis\Command\KeyMove
[SORT] => Predis\Command\KeySort
[DUMP] => Predis\Command\KeyDump
[RESTORE] => Predis\Command\KeyRestore
[SET] => Predis\Command\StringSet
[SETNX] => Predis\Command\StringSetPreserve
[MSET] => Predis\Command\StringSetMultiple
[MSETNX] => Predis\Command\StringSetMultiplePreserve
[GET] => Predis\Command\StringGet
[MGET] => Predis\Command\StringGetMultiple
[GETSET] => Predis\Command\StringGetSet
[INCR] => Predis\Command\StringIncrement
[INCRBY] => Predis\Command\StringIncrementBy
[DECR] => Predis\Command\StringDecrement
[DECRBY] => Predis\Command\StringDecrementBy
[RPUSH] => Predis\Command\ListPushTail
[LPUSH] => Predis\Command\ListPushHead
[LLEN] => Predis\Command\ListLength
[LRANGE] => Predis\Command\ListRange
[LTRIM] => Predis\Command\ListTrim
[LINDEX] => Predis\Command\ListIndex
[LSET] => Predis\Command\ListSet
[LREM] => Predis\Command\ListRemove
[LPOP] => Predis\Command\ListPopFirst
[RPOP] => Predis\Command\ListPopLast
[RPOPLPUSH] => Predis\Command\ListPopLastPushHead
[SADD] => Predis\Command\SetAdd
[SREM] => Predis\Command\SetRemove
[SPOP] => Predis\Command\SetPop
[SMOVE] => Predis\Command\SetMove
[SCARD] => Predis\Command\SetCardinality
[SISMEMBER] => Predis\Command\SetIsMember
[SINTER] => Predis\Command\SetIntersection
[SINTERSTORE] => Predis\Command\SetIntersectionStore
[SUNION] => Predis\Command\SetUnion
[SUNIONSTORE] => Predis\Command\SetUnionStore
[SDIFF] => Predis\Command\SetDifference
[SDIFFSTORE] => Predis\Command\SetDifferenceStore
[SMEMBERS] => Predis\Command\SetMembers
[SRANDMEMBER] => Predis\Command\SetRandomMember
[ZADD] => Predis\Command\ZSetAdd
[ZINCRBY] => Predis\Command\ZSetIncrementBy
[ZREM] => Predis\Command\ZSetRemove
[ZRANGE] => Predis\Command\ZSetRange
[ZREVRANGE] => Predis\Command\ZSetReverseRange
[ZRANGEBYSCORE] => Predis\Command\ZSetRangeByScore
[ZCARD] => Predis\Command\ZSetCardinality
[ZSCORE] => Predis\Command\ZSetScore
[ZREMRANGEBYSCORE] => Predis\Command\ZSetRemoveRangeByScore
[PING] => Predis\Command\ConnectionPing
[AUTH] => Predis\Command\ConnectionAuth
[SELECT] => Predis\Command\ConnectionSelect
[ECHO] => Predis\Command\ConnectionEcho
[QUIT] => Predis\Command\ConnectionQuit
[INFO] => Predis\Command\ServerInfoV26x
[SLAVEOF] => Predis\Command\ServerSlaveOf
[MONITOR] => Predis\Command\ServerMonitor
[DBSIZE] => Predis\Command\ServerDatabaseSize
[FLUSHDB] => Predis\Command\ServerFlushDatabase
[FLUSHALL] => Predis\Command\ServerFlushAll
[SAVE] => Predis\Command\ServerSave
[BGSAVE] => Predis\Command\ServerBackgroundSave
[LASTSAVE] => Predis\Command\ServerLastSave
[SHUTDOWN] => Predis\Command\ServerShutdown
[BGREWRITEAOF] => Predis\Command\ServerBackgroundRewriteAOF
[SETEX] => Predis\Command\StringSetExpire
[APPEND] => Predis\Command\StringAppend
[SUBSTR] => Predis\Command\StringSubstr
[BLPOP] => Predis\Command\ListPopFirstBlocking
[BRPOP] => Predis\Command\ListPopLastBlocking
[ZUNIONSTORE] => Predis\Command\ZSetUnionStore
[ZINTERSTORE] => Predis\Command\ZSetIntersectionStore
[ZCOUNT] => Predis\Command\ZSetCount
[ZRANK] => Predis\Command\ZSetRank
[ZREVRANK] => Predis\Command\ZSetReverseRank
[ZREMRANGEBYRANK] => Predis\Command\ZSetRemoveRangeByRank
[HSET] => Predis\Command\HashSet
[HSETNX] => Predis\Command\HashSetPreserve
[HMSET] => Predis\Command\HashSetMultiple
[HINCRBY] => Predis\Command\HashIncrementBy
[HGET] => Predis\Command\HashGet
[HMGET] => Predis\Command\HashGetMultiple
[HDEL] => Predis\Command\HashDelete
[HEXISTS] => Predis\Command\HashExists
[HLEN] => Predis\Command\HashLength
[HKEYS] => Predis\Command\HashKeys
[HVALS] => Predis\Command\HashValues
[HGETALL] => Predis\Command\HashGetAll
[MULTI] => Predis\Command\TransactionMulti
[EXEC] => Predis\Command\TransactionExec
[DISCARD] => Predis\Command\TransactionDiscard
[SUBSCRIBE] => Predis\Command\PubSubSubscribe
[UNSUBSCRIBE] => Predis\Command\PubSubUnsubscribe
[PSUBSCRIBE] => Predis\Command\PubSubSubscribeByPattern
[PUNSUBSCRIBE] => Predis\Command\PubSubUnsubscribeByPattern
[PUBLISH] => Predis\Command\PubSubPublish
[CONFIG] => Predis\Command\ServerConfig
[PERSIST] => Predis\Command\KeyPersist
[STRLEN] => Predis\Command\StringStrlen
[SETRANGE] => Predis\Command\StringSetRange
[GETRANGE] => Predis\Command\StringGetRange
[SETBIT] => Predis\Command\StringSetBit
[GETBIT] => Predis\Command\StringGetBit
[RPUSHX] => Predis\Command\ListPushTailX
[LPUSHX] => Predis\Command\ListPushHeadX
[LINSERT] => Predis\Command\ListInsert
[BRPOPLPUSH] => Predis\Command\ListPopLastPushHeadBlocking
[ZREVRANGEBYSCORE] => Predis\Command\ZSetReverseRangeByScore
[WATCH] => Predis\Command\TransactionWatch
[UNWATCH] => Predis\Command\TransactionUnwatch
[OBJECT] => Predis\Command\ServerObject
[SLOWLOG] => Predis\Command\ServerSlowlog
[CLIENT] => Predis\Command\ServerClient
[PTTL] => Predis\Command\KeyPreciseTimeToLive
[PEXPIRE] => Predis\Command\KeyPreciseExpire
[PEXPIREAT] => Predis\Command\KeyPreciseExpireAt
[MIGRATE] => Predis\Command\KeyMigrate
[PSETEX] => Predis\Command\StringPreciseSetExpire
[INCRBYFLOAT] => Predis\Command\StringIncrementByFloat
[BITOP] => Predis\Command\StringBitOp
[BITCOUNT] => Predis\Command\StringBitCount
[HINCRBYFLOAT] => Predis\Command\HashIncrementByFloat
[EVAL] => Predis\Command\ServerEval
[EVALSHA] => Predis\Command\ServerEvalSHA
[SCRIPT] => Predis\Command\ServerScript
[TIME] => Predis\Command\ServerTime
[SENTINEL] => Predis\Command\ServerSentinel
[SCAN] => Predis\Command\KeyScan
[BITPOS] => Predis\Command\StringBitPos
[SSCAN] => Predis\Command\SetScan
[ZSCAN] => Predis\Command\ZSetScan
[ZLEXCOUNT] => Predis\Command\ZSetLexCount
[ZRANGEBYLEX] => Predis\Command\ZSetRangeByLex
[ZREMRANGEBYLEX] => Predis\Command\ZSetRemoveRangeByLex
[ZREVRANGEBYLEX] => Predis\Command\ZSetReverseRangeByLex
[HSCAN] => Predis\Command\HashScan
[PUBSUB] => Predis\Command\PubSubPubsub
[PFADD] => Predis\Command\HyperLogLogAdd
[PFCOUNT] => Predis\Command\HyperLogLogCount
[PFMERGE] => Predis\Command\HyperLogLogMerge
[COMMAND] => Predis\Command\ServerCommand
)
[processor:Predis\Profile\RedisProfile:private] =>
)
)
[match:protected] => users:anne.castrillon@gmail.com*
[count:protected] =>
[valid:protected] => 1
[fetchmore:protected] => 1
[elements:protected] => Array
(
)
[cursor:protected] => 0
[position:protected] => -1
[current:protected] =>
)